# Ethereum eth_estimateGas RPC method
Ethereum API method that returns an estimation of gas units needed for a given transaction.
Parameters:
object
— the transaction call object (opens new window), where thefrom
field is optional, and thenonce
field is omitted.quantity or tag
— the integer block number, or the string:latest
— the latest block that is to be validated. The Beacon Chain may reorg and the latest block can become orphaned.safe
— the block that is equal to the tip of the chain and is very unlikely to be orphaned.finalized
— the block that is accepted by the two thirds of the Ethereum validators.earliest
— the genesis block.pending
— the pending state and transactions block.
Returns:
quantity
— the estimated amount of gas units used.
Example:
- web3.js
- web3.py
- eth.rb
- cURL
const Web3 = require("web3");
const node_url = "CHAINSTACK_NODE_URL";
const web3 = new Web3(node_url);
web3.eth.estimateGas({
from: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
to: "0xbe0eb53f46cd790cd13851d5eff43d12404d33e8",
// web3.js only uses the latest block.
})
.then(gas => {
console.log(gas);
});