Fetching Block Gas Parameters
The gasParameters
method allows you to retrieve gas metrics for the current block on the OP_NET network. These parameters include the total gas used, target gas limit, base gas price, and Exponential Moving Average (EMA) of gas prices.
Method
gasParameters(): Promise<BlockGasParameters>;
- Returns:
Promise<BlockGasParameters>
: An object containing gas metrics for the current block.
Object Definitions
BlockGasParameters
ObjectProperty | Type | Description |
---|---|---|
blockNumber | bigint | The number of the block being analyzed. |
gasUsed | bigint | The total amount of gas used in the block. |
targetGasLimit | bigint | The target gas limit for the block. |
ema | bigint | The Exponential Moving Average of gas prices. |
baseGas | bigint | The base gas price for the block. |
gasPerSat | bigint | The amount of gas equivalent to one satoshi. |
Example Usage
const gasParameters = await provider.gasParameters();
console.log("Block Gas Parameters:", gasParameters);
console.log("Block Number:", gasParameters.blockNumber);
console.log("Gas Used:", gasParameters.gasUsed);
console.log("Base Gas Price:", gasParameters.baseGas);
Best Practices
- Ensure your application dynamically adapts to changes in
baseGas
andgasPerSat
for accurate transaction fee estimations. - The gas parameters provide insights into the network's gas usage and pricing model, which is crucial for optimizing transaction costs.
What’s Next?
After fetching block gas parameters, you can: