POST
/
evm
eth_estimateGas
curl --request POST \
  --url https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm \
  --header 'Content-Type: application/json' \
  --data '{
  "jsonrpc": "2.0",
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0xFC1286EeddF81d6955eDAd5C8D99B8Aa32F3D2AA",
      "to": "0x5555555555555555555555555555555555555555",
      "data": "0xa9059cbb000000000000000000000000fefefefefefefefefefefefefefefefefefefefe0000000000000000000000000000000000000000000000000de0b6b3a7640000"
    }
  ],
  "id": 1
}'
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x5208"
}
The eth_estimateGas JSON-RPC method estimates the amount of gas required to execute a transaction without actually executing it on the blockchain. This method is essential for determining gas costs before sending transactions, helping users avoid failed transactions due to insufficient gas. On Hyperliquid, gas estimation is performed against the latest block state only.
Get your own node endpoint todayStart for free and get your app to production levels immediately. No credit card required.You can sign up with your GitHub, X, Google, or Microsoft account.

Parameters

The method takes one parameter: a transaction object containing the transaction details.

Transaction object

  • from (string, optional) — The address the transaction is sent from
  • to (string, optional) — The address the transaction is directed to
  • gas (string, optional) — Integer of the gas provided for the transaction execution
  • gasPrice (string, optional) — Integer of the gasPrice used for each paid gas
  • value (string, optional) — Integer of the value sent with this transaction
  • data (string, optional) — The compiled code of a contract OR the hash of the invoked method signature and encoded parameters

Response

The method returns the estimated gas amount as a hexadecimal string.

Response structure

Gas estimate:
  • result — The estimated gas amount as a hexadecimal string

Gas estimation accuracy

Estimation considerations:
  • Estimates are based on the latest block state only (Hyperliquid limitation)
  • Actual gas usage may vary if state changes before execution
  • Complex transactions may have less accurate estimates
  • Include a buffer (10-20%) when using estimates for actual transactions
Factors affecting accuracy:
  • Contract complexity and execution paths
  • State changes between estimation and execution
  • Gas price fluctuations and network congestion
  • Dynamic contract behavior based on inputs

Usage example

Basic implementation

// Estimate gas for a transaction on Hyperliquid
const estimateGas = async (transactionObject) => {
  const response = await fetch('https://hyperliquid-mainnet.core.chainstack.com/YOUR_ENDPOINT/evm', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      jsonrpc: '2.0',
      method: 'eth_estimateGas',
      params: [transactionObject],
      id: 1
    })
  });
  
  const data = await response.json();
  const gasEstimate = parseInt(data.result, 16);
  
  return {
    hex: data.result,
    decimal: gasEstimate,
    withBuffer: Math.ceil(gasEstimate * 1.2) // Add 20% buffer
  };
};

// Example: Estimate gas for an ERC-20 transfer
const estimateTokenTransfer = async () => {
  const transaction = {
    from: "0xFC1286EeddF81d6955eDAd5C8D99B8Aa32F3D2AA",
    to: "0x5555555555555555555555555555555555555555", // Token contract
    data: "0xa9059cbb000000000000000000000000fefefefefefefefefefefefefefefefefefefefe0000000000000000000000000000000000000000000000000de0b6b3a7640000"
  };
  
  try {
    const estimate = await estimateGas(transaction);
    console.log(`Estimated gas: ${estimate.decimal}`);
    console.log(`Recommended gas limit: ${estimate.withBuffer}`);
    return estimate;
  } catch (error) {
    console.error('Gas estimation failed:', error);
    throw error;
  }
};

// Usage
estimateTokenTransfer()
  .then(estimate => console.log('Gas estimation successful:', estimate))
  .catch(error => console.error('Error:', error));

Best practices

Transaction preparation

Gas estimation workflow:
  • Always estimate gas before sending transactions
  • Add a reasonable buffer (10-20%) to prevent out-of-gas errors
  • Use estimates for transaction cost calculations
  • Test estimates with various input parameters
Hyperliquid considerations:
  • Estimates are based on latest block state only
  • Monitor actual vs estimated gas usage for optimization
  • Implement fallback gas limits for critical transactions

Example request

Shell
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"from":"0xFC1286EeddF81d6955eDAd5C8D99B8Aa32F3D2AA","to":"0x5555555555555555555555555555555555555555","data":"0xa9059cbb000000000000000000000000fefefefefefefefefefefefefefefefefefefefe0000000000000000000000000000000000000000000000000de0b6b3a7640000"}],"id":1}' \
  https://hyperliquid-mainnet.core.chainstack.com/4f8d8f4040bdacd1577bff8058438274/evm

Use cases

The eth_estimateGas method is essential for applications that need to:
  • Transaction cost calculation: Estimate gas costs before sending transactions
  • Wallet applications: Display transaction fees to users before confirmation
  • DeFi protocols: Calculate gas costs for complex multi-step transactions
  • Smart contract deployment: Estimate deployment costs for contracts
  • Batch operations: Plan gas usage for batch transactions and operations
  • Trading platforms: Estimate gas costs for trading operations and swaps
  • NFT marketplaces: Calculate minting and trading gas costs
  • Gaming applications: Estimate gas for in-game transactions and operations
  • Automated systems: Set appropriate gas limits for automated transactions
  • Cost optimization: Compare gas costs across different transaction methods
  • User experience: Prevent transaction failures due to insufficient gas
  • Analytics platforms: Analyze gas usage patterns and optimization opportunities
  • Development tools: Test and optimize smart contract gas efficiency
  • Portfolio management: Calculate total transaction costs for portfolio operations
  • Cross-chain bridges: Estimate gas costs for bridge operations
  • Governance systems: Calculate voting and proposal submission costs
  • Staking platforms: Estimate gas costs for staking and delegation operations
  • Lending protocols: Calculate gas costs for lending and borrowing operations
  • Insurance platforms: Estimate gas costs for claim processing and payouts
  • Supply chain: Calculate gas costs for supply chain tracking operations
  • Identity systems: Estimate gas costs for identity verification transactions
  • Subscription services: Calculate gas costs for recurring payment operations
  • Audit tools: Analyze gas usage for security and efficiency audits
  • Educational platforms: Demonstrate gas concepts and optimization techniques
  • Research tools: Study gas usage patterns and blockchain economics
This method provides essential gas estimation capabilities, enabling cost-effective and reliable transaction execution on the Hyperliquid EVM platform.
On Hyperliquid, eth_estimateGas only supports the latest block state. Gas estimates may not be accurate for complex transactions or when the blockchain state changes between the estimate and actual execution. Always include a reasonable buffer when using estimates for actual transactions.

Body

application/json

Response

200 - application/json

Successful response with the estimated gas amount

The response is of type object.