Links

eth_estimateGas

Generates and returns an estimate of the gas required for a transaction to complete. The transaction will not be added to the blockchain.

Parameters

See eth_call parameters, expect that all properties are optional. If no gas limit is specified geth uses the block gas limit from the pending block as an upper bound. As a result the returned estimate might not be enough to executed the call/transaction when the amount of gas is higher than the pending block gas limit.

Returns

QUANTITY(hex string) - the amount of gas used.

Example

Request

curl
TypeScript
curl https://api.blockvision.org/v1/<api key> \
-X POST \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_estimateGas",
"params": [
{
"from": "0x3d597789ea16054a084ac84ce87f50df9198f415",
"to": "0x3d597789ea16054a084ac84ce87f50df9198f415",
"value": "0x1"
}
],
"id": 1
}'
import { BlockVisionProvider, BvNetwork } from 'blockvision.js'
// Optional parameters, but default to eth-mainnet and default api-key.
const bv = new BlockVisionProvider(BvNetwork.POL_MAINNET)
// Access standard Ethers.js JSON-RPC node request
bv.estimateGas({
to: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
data: '0xd0e30db0',
value: parseEther('1.0')
}).then(console.log)

Result

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5208"
}