Skip to main content

Gas estimation

In this brief guide we will use the Checkout SDK to fetch the estimated gas amount required for performing key Checkout operations on zkEVM and L1 (e.g. Ethereum).


Get estimated gas amount

The estimated gas amount per transaction type can be programmatically fetched using the gasEstimate() function.

The gasEstimate() function allows to specify the type of transaction using GasEstimateType and returns respective result.

The GasEstimateSwapResult for SWAP type of transaction.

The GasEstimateBridgeToL2Result for BRIDGE_TO_L2 type of transaction.

info

The estimated gas amount covers any ERC20 approval cost as well as the cost of performing the operation (e.g. Swap ERC20).

// Import the checkout module from the Immutable SDK package
import {checkout} from '@imtbl/sdk';

// Instantiate the Checkout SDKs with the default configurations
const checkoutSDK = new checkout.Checkout();

// Fetch gas-estimate for Swap type of transaction
checkoutSDK
.gasEstimate({ gasEstimateType: checkout.GasEstimateType.SWAP })
.then((resp) => console.log(resp));