Skip to main content

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 Object
PropertyTypeDescription
blockNumberbigintThe number of the block being analyzed.
gasUsedbigintThe total amount of gas used in the block.
targetGasLimitbigintThe target gas limit for the block.
emabigintThe Exponential Moving Average of gas prices.
baseGasbigintThe base gas price for the block.
gasPerSatbigintThe 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 and gasPerSat 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: