POST
/
6df1a1b3061097e66349993a96b8e535
curl --request POST \
  --url https://aurora-mainnet.core.chainstack.com/6df1a1b3061097e66349993a96b8e535 \
  --header 'Content-Type: application/json' \
  --data '{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_estimateGas",
  "params": [
    {
      "from": "0xE9217BC70B7ED1f598ddD3199e80b093fA71124F",
      "to": "0x2A39319dB98A3982F7C363380b72C66Ab1FFe228"
    },
    "latest"
  ]
}'
{
  "jsonrpc": "<string>",
  "id": 123,
  "result": "aSDinaTvuI8gbWludGxpZnk="
}

Aurora API method that returns an estimate of gas units needed for a given transaction.

It estimates the maximum amount of gas units required to complete the transaction based on the network’s current state and the transaction’s parameters. A client or wallet can use this estimate to determine the appropriate amount of gas to include in a transaction to ensure the network processes it.

Get you own node endpoint today

Start 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

  • object — the transaction call object, same as in eth_call; the from field is optional, and the nonce field is omitted:

    • from — (optional) the address string used to send the transaction.
    • to — the string of the address to which the transaction is directed, a wallet, or a smart contract.
    • gas — (optional) the maximum amount of gas that can be used by the transaction.
    • gasprice — (optional) the amount of gas price the sender is willing to pay for each gas unit in Wei.
    • value — (optional) the value sent with this transaction, encoded as hexadecimal.
    • data — (optional) additional data to be sent with the call, usually used to invoke functions from smart contracts as a string of the hash of the method signature and encoded parameters; see the Ethereum Contract ABI.
  • quantity or tag — the integer of a block encoded as hexadecimal or the string with:

    • latest — the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.
    • safe — the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or an instance of severe propagation latency.
    • finalized — the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, and it would require at least 1/3 of the staked amount to be burned.
    • earliest — the earliest available or genesis block.
    • pending — the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.

Response

  • quantity — the estimated amount of gas units needed, represented as a hexadecimal string.

eth_estimateGas code examples

const { Web3 } = require("web3");

const NODE_URL = "CHAINSTACK_NODE_URL";

const web3 = new Web3(NODE_URL);



async function estimateGas() {

	// The transaction to estimate is a simple transfer in this example.

  const transactionObj = {

    from: "0x8B0003B2AA1699Ca0Dd269ceda5bC26757a86FbC",

    to: "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",

  }



  const gasUnits = await web3.eth.estimateGas(transactionObj);

  console.log(`Estimated gas units required: ${gasUnits}`);

}



estimateGas()

Use case

A practical use case for eth_estimateGas is to calculate the gas cost required for a transaction that transfers a value from one Ethereum address (fromAddress) to another (toAddress). The gas cost is an important factor in transactions, as it determines the amount of fees that need to be paid by the sender to the network for processing the transaction.

Body

application/json
id
integer
default:1
jsonrpc
string
default:2.0
method
string
default:eth_estimateGas
params
object[]

Response

200 - application/json
The estimated gas amount
jsonrpc
string
id
integer
result
string