GasEstimate
GasEstimate represents the estimated gas required for a transaction, typically returned by eth_estimateGas RPC method. Always add buffer (20-30%) before using as gasLimit.
Type Definition
Gas Estimation Flow
API
Constructors
from(value)
Create GasEstimate from number, bigint, or string.
InvalidFormatError if value is negative.
Conversions
toNumber(estimate)
Convert to number.
toBigInt(estimate)
Convert to bigint (identity operation).
toHex(estimate)
Convert to hex string.
Comparisons
equals(est1, est2)
Check equality.
compare(est1, est2)
Compare values (-1, 0, 1).
Utilities
withBuffer(estimate, percentage)
Add percentage buffer to estimate.
- Standard: 20-25%
- Conservative: 30-40%
- Network congestion: 50%+
toGasLimit(estimate)
Convert to gas limit (typically after adding buffer).
Usage Examples
Basic Estimation
Add Buffer and Send Transaction
Compare Estimation Strategies
Handle Network Congestion
Why Add Buffer?
eth_estimateGas returns the minimum gas needed under ideal conditions:
- State changes: Between estimation and execution, blockchain state may change
- Gas costs: Hard forks can change opcode gas costs
- Execution paths: Conditional logic may take different paths
- Rounding: EVM operations round up, estimation may round down
Estimation Strategies
Standard (20-25%)
Good for:- Simple transfers
- Known contract calls
- Stable network conditions
Conservative (30-40%)
Good for:- Complex contract interactions
- First-time contract calls
- Unknown execution paths
Very Safe (50%+)
Good for:- Network congestion
- Critical transactions
- Maximum safety needed
Common Estimates
| Operation | Typical Estimate |
|---|---|
| ETH transfer | 21,000 |
| ERC20 transfer | 50,000-65,000 |
| Uniswap swap | 120,000-180,000 |
| NFT mint | 80,000-150,000 |
| Contract deploy | Varies widely |
EIPs
- EIP-150: Gas cost changes (1/64th rule)
- EIP-2929: Cold/warm storage access costs
- EIP-3529: Refund reduction (doesn’t affect estimation)
See Also
- GasUsed - Actual gas consumed
- GasRefund - Gas refunds after execution
- GasCosts - Gas cost constants
- eth_estimateGas - RPC specification

