Estimate Gas
Calculates the estimated gas units required for a transaction to execute successfully on the blockchain.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Client ID - The client ID from the Create Client node.
- Transaction ID - The transaction ID from ABI Method or Transfer node.
- Wallet Address - The sender's wallet address.
- Contract/To Address - The destination contract or wallet address.
- Value - The amount of native currency to send with the transaction in hex format (optional).
Output
- Gas - The estimated gas limit required for the transaction (as a number).
How It Works
The Estimate Gas node simulates transaction execution to determine gas requirements. When executed, the node:
- Validates all inputs and retrieves transaction data
- Constructs a call message with all transaction parameters
- Simulates the transaction execution on the current blockchain state
- Calculates the gas units that would be consumed
- Returns the estimated gas limit
Requirements
- Valid Client ID and transaction data
- Sufficient balance in the wallet for the transaction
- Valid contract address (if calling a contract)
- Correct transaction parameters
Error Handling
The node will return errors for:
- Invalid or missing Client ID
- Transaction data not found
- Invalid addresses
- Transaction simulation failures (would revert)
- Insufficient balance for transaction value
- Invalid value format
Gas Estimation Guidelines
The returned gas estimate represents the actual consumption. For safety:
Add a buffer for Send Transaction:
- Simple operations: Add 10-20% (multiply by 1.1 to 1.2)
- Complex operations: Add 20-50% (multiply by 1.2 to 1.5)
- Uncertain operations: Add 50-100% (multiply by 1.5 to 2.0)
Why add a buffer?
- Blockchain state may change between estimate and execution
- Gas costs can increase if storage is allocated
- Prevents out-of-gas failures
Usage Notes
- Always estimate before sending transactions
- The estimate assumes current blockchain state
- State changes between estimate and execution can affect actual usage
- The estimate doesn't include the 21,000 gas base transaction fee for value transfers
- Failed simulations indicate the transaction would fail
- Use the output directly or with a safety buffer
Example
Estimating gas for ERC20 transfer:
Inputs:
- Client ID:
7e8f9a0b-1c2d-3e4f-5a6b-7c8d9e0f1a2b - Transaction ID:
tx-abc123(from ABI Method with transfer function) - Wallet Address:
0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb - Contract/To Address:
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48(USDC) - Value: `` (empty for token transfer)
Output:
- Gas:
65000
Using with safety buffer:
estimatedGas = 65000
gasLimit = Math.ceil(estimatedGas * 1.2) // 78000
Estimating simple ETH transfer:
Inputs:
- Client ID:
7e8f9a0b-1c2d-3e4f-5a6b-7c8d9e0f1a2b - Transaction ID: (from Transfer node)
- Wallet Address:
0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb - Contract/To Address:
0x1234567890123456789012345678901234567890 - Value:
0x016345785d8a0000
Output:
- Gas:
21000
Common Use Cases
Pre-Transaction Validation: Verify a transaction will succeed before sending.
Gas Cost Calculation: Calculate total cost (gas × gasPrice) before execution.
Dynamic Gas Limits: Set appropriate gas limits for varying operations.
Transaction Optimization: Compare gas costs of different approaches.
User Notifications: Inform users of estimated transaction costs.
Budget Enforcement: Reject transactions exceeding gas budgets.
Typical Gas Ranges
Simple Operations:
- ETH transfer: 21,000 gas
- ERC20 transfer: 45,000-65,000 gas
- ERC20 approve: 45,000-50,000 gas
Complex Operations:
- NFT mint: 80,000-150,000 gas
- Uniswap swap: 100,000-200,000 gas
- Multi-step DeFi: 200,000-500,000 gas
- Contract deployment: 500,000+ gas
Integration Example
Complete transaction flow with estimation:
- ABI Method - Encode the transaction
- Estimate Gas - Get gas requirement
- Calculate Buffer - Add 20% safety margin
- Estimate Gas Price - Get current gas price
- Calculate Cost - Multiply gas × gasPrice
- Validate Balance - Ensure sufficient funds
- Send Transaction - Execute with calculated gas limit
Cost Calculation
Formula:
Total Cost (ETH) = (Gas Limit × Gas Price) / 10^18
Example:
- Estimated Gas: 65,000
- Gas Limit (with 20% buffer): 78,000
- Gas Price: 30 GWEI
- Cost: (78,000 × 30,000,000,000) / 10^18 = 0.00234 ETH
Error Scenarios
Estimation fails when:
- Transaction would revert (insufficient balance, failed require statements)
- Contract doesn't exist at the address
- Invalid function parameters
- Insufficient allowance for token transfers
Handle estimation failures:
if (estimationError) {
// Transaction will fail
// Check balance, allowances, parameters
// Don't send transaction
}
Always estimate gas before sending transactions. It's free, instant, and helps prevent failed transactions that waste gas fees.
If Estimate Gas fails, the actual transaction will also fail. Don't proceed with Send Transaction if estimation fails - investigate and fix the issue first.
Gas Limit vs Gas Used
Gas Limit:
- Maximum gas the transaction can consume
- What you set in Send Transaction
- If exceeded, transaction fails
Gas Used:
- Actual gas consumed
- Usually less than the limit
- Only charged for gas used
Best Practice: Set gas limit slightly higher than estimate, but not excessively high to avoid potential issues with some contracts.