Skip to main content

estimateGas

Callable


  • Simulates the transaction within the EVM to estimate the amount of gas to be used by the transaction. The transaction will not be added to the blockchain, and actual gas usage can vary when interacting with a contract as a result of updating the contract’s state.


    Type parameters

    Parameters

    Returns Promise<NumberTypes[ReturnFormat[number]]>

    The used gas for the simulated transaction execution.

    const transaction = {
    from: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
    to: '0xe899f0130FD099c0b896B2cE4E5E15A25b23139a',
    value: '0x1',
    nonce: '0x1',
    type: '0x0'
    }

    web3.eth.estimateGas(transaction).then(console.log);
    > 21000n

    web3.eth.estimateGas(transaction, { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log);
    > 21000