ethereum-toolkit
v1.0.8
Published
A TypeScript project to calculate the next block base fee, typically used in blockchain or EVM-based systems.
Readme
calcNextBlockBaseFee
A TypeScript project to calculate the next block base fee, typically used in blockchain or EVM-based systems.
Features
- ✅ TypeScript Support: Written in TypeScript
- ✅ Base Fee Calculation: Implements logic to calculate the next block base fee
- ✅ Configurable: Easily adaptable for different fee calculation rules
- ✅ Error Handling: Validates input and handles edge cases
Installation
npm installCalculates the next block base fee based on the current base fee, gas used, and gas target.
Parameters:
currentBaseFee: The base fee of the current blockgasUsed: The amount of gas used in the current blockgasTarget: The target gas for the block
Returns: The calculated base fee for the next block
Prerequisites
- Node.js (v14 or higher)
- npm
Setup
# Clone the repository
git clone <repository-url>
cd calcNextBlockBaseFee
# Install dependencies
npm install
# Build the project
npm run build
# Run tests
npm test
# Development mode (watch for changes)
npm run devScripts
npm run build: Compile TypeScript to JavaScriptnpm run test: Run testsnpm run dev: Watch mode for development
Algorithm
The base fee calculation typically follows the EIP-1559 specification:
- If
gasUsedequalsgasTarget, the base fee remains unchanged. - If
gasUsedis higher thangasTarget, the base fee increases. - If
gasUsedis lower thangasTarget, the base fee decreases.
Refer to EIP-1559 for the exact formula and logic.
Error Handling
The project validates input values and handles edge cases such as negative numbers and overflow.
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Changelog
v1.0.9
- Initial release: base fee calculation logic implemented in TypeScript
