eth_estimateGas
Returns an estimate of the gas that would be used in a transaction with the given parameters.
Params
Transaction
:Object
. A standard Ethereum transaction object containing the following fields:to
:string
. The destination address of the message.data
:string
(optional). Either a byte string containing the associated data of the message, or in the case of a contract-creation transaction, the initialisation code.value
:string
(optional). The value transferred for the transaction in wei, encoded as a hex string.
BlockNumber
:string
(optional). The block number to get the gas estimate at. If omitted, the latest block is used.
Result
Returns a Promise that resolves with a hex string containing the estimated gas.
Example
const gas = await provider.request({
method: 'eth_estimateGas',
params: [
{
to: '0x...',
data: '0x...'
},
'latest'
]
});
console.log(gas); // ['0x...']