Skip to main content

Gas Estimation

Estimate gas costs before executing transactions.

Single Operation

const estimate = await client.estimateExecute({
target: contractAddress,
value: 0n,
data: calldata,
});

console.log('Gas limit:', estimate.gasLimit);
console.log('Gas price:', ethers.formatGwei(estimate.gasPrice), 'gwei');
console.log('Estimated cost:', estimate.estimatedCostEth, 'ETH');

Batch Operations

const estimate = await client.estimateBatch({
targets: [addr1, addr2],
values: [0n, 0n],
calldatas: [data1, data2],
});

console.log('Total gas:', estimate.gasLimit);
console.log('Max fee:', ethers.formatGwei(estimate.maxFeePerGas), 'gwei');

Estimate Response

FieldTypeDescription
gasLimitbigintEstimated gas units
gasPricebigintCurrent gas price
maxFeePerGasbigintEIP-1559 max fee
maxPriorityFeePerGasbigintEIP-1559 priority fee
estimatedCostEthstringHuman-readable cost

Best Practices

  • Always estimate before large transactions
  • Add 10-20% buffer to gas limit for complex operations
  • Monitor gas prices during high network activity