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
| Field | Type | Description |
|---|---|---|
gasLimit | bigint | Estimated gas units |
gasPrice | bigint | Current gas price |
maxFeePerGas | bigint | EIP-1559 max fee |
maxPriorityFeePerGas | bigint | EIP-1559 priority fee |
estimatedCostEth | string | Human-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