Skip to content

Documentation / js-sdk-core / calculateTotalGasEstimate

Function: calculateTotalGasEstimate()

calculateTotalGasEstimate(txRequest, provider): Promise<Object>

Calculate the total estimated gas cost from the transaction request. This method assumes the transaction has already been processed by Privy's populateTransactionRequest and that both a gasLimit and one of the gasPrice or maxFeePerGas have been set.

If the transaction is on an OP Stack chain, this method will include the L1 execution fee in the returned totalGasEstimate and will also return the execution fee as a separate l1ExecutionFeeEstimate. For non-OP Stack chains, the l1ExecutionFeeEstimate will be 0.

Parameters

txRequest: UnsignedTransactionRequestWithChainId

{UnsignedTransactionRequest} the transaction request for which to total estimated gas for

provider: StaticJsonRpcProvider

{StaticJsonRpcProvider} ethers provider

Returns

Promise<Object>

the totalGasEstimate and l1ExecutionFeeEstimate

l1ExecutionFeeEstimate

l1ExecutionFeeEstimate: BigNumber

totalGasEstimate

totalGasEstimate: BigNumber