LogoLogo
  • What is QPQ?
  • Quickstart
    • Creating your network and node
    • Setup Metamask and get Tokens
    • Create a Metamask account
    • Send tokens between accounts
  • Smart Contracts
    • Ethereum API
      • eth_blockNumber
      • eth_getBlockByHash
      • eth_getBlockByNumber
      • eth_getTransactionByHash
      • eth_getTransactionCount
      • eth_getTransactionReceipt
      • eth_sendRawTransaction
      • eth_getBalance
      • eth_getCode
      • eth_call
      • eth_getLogs
      • eth_estimateGas
      • eth_chainId
      • net_version
    • Deploy and interact with a smart contract
      • Hardhat
        • Interaction - Greeter
      • Remix IDE
  • Tutorials
    • NFT deploy
  • Bridge
    • Setup the bridge
  • Resources
    • 1DLT Frequently asked Questions (FAQ)
    • Support
Powered by GitBook
On this page
  • Parameters
  • Returns
  • Request
  • Result
  1. Smart Contracts
  2. Ethereum API

eth_estimateGas

Generates and returns an estimate of how much gas is necessary to allow the transaction to complete. The transaction will not be added to the blockchain.

Previouseth_getLogsNexteth_chainId

Last updated 2 years ago

Note: The estimate may be significantly more than the amount of gas actually used by the transaction, for a variety of reasons including EVM mechanics and node performance. Estimates are served directly from nodes, we're not doing anything special to the value so the rest of the network is likely seeing the same.

Parameters

  • Object - The transaction call object

    • from: DATA, 20 Bytes - (optional) The address the transaction is sent from.

    • to: DATA, 20 Bytes - The address the transaction is directed to.

    • gas: QUANTITY - (optional) Integer of the gas provided for the transaction execution. eth_estimateGas consumes zero gas, but this parameter may be needed by some executions.

    • gasPrice: QUANTITY - (optional) Integer of the gasPrice used for each paid gas.

    • value: QUANTITY - (optional) Integer of the value sent with this transaction

    • data: DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI

  • QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the .

Returns

QUANTITY - the amount of gas used.

Request

const Web3 = require("web3");

async function main() {

	const Web3 = require('web3')
        const rpcURL = '1DLT-IP-ADDRESS' // Your RPC URL goes here
        const web3 = new Web3(rpcURL)
	
	// Query the blockchain (replace example parameters)
    	const estGas = await web3.eth.estimateGas({
	    from: "0xge61df",
	    to: "0x087a5c",
	    data: "0xa9059c",
	    gasPrice: "0xa994f8",
	  }) 

	// Print the output to console
  	console.log(estGas);
   }

main();
const { ethers } = require("ethers");
async function main() {
 
    // Initialize an ethers instance
    const provider = new ethers.providers.JsonRpcProvider("1DLT-IP-ADDRESS");

	// Query the blockchain (replace example parameters)
    	const estGas = await provider.estimateGas({
	    from: "0xge61df",
	    to: "0x087a5c",
	    data: "0xa9059c",
	    gasPrice: "0xa994f8",
	  }) 

	// Print the output to console
  	console.log(estGas);

   }

main()
curl 1DLT-IP-ADDRESS \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_estimateGas","params":[{"from": "0x8D97689C9818892B700e27F316cc3E41e17fBeb9","to": "0xd3CdA913deB6f67967B99D67aCDFa1712C293601","value": "0x186a0"}],"id":1}'

Result

{
  "id":1,
  "jsonrpc": "2.0",
  "result": "0x5208" // 21000
}
default block parameter