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).

Fetch gas estimatesView on GitHub
// Get gas estimate for Swap type of transaction
const swapEstimate = await checkoutSDK.gasEstimate({ gasEstimateType: checkout.GasEstimateType.SWAP });
// Get gas estimate for Bridge type of transaction
const bridgeEstimate = await checkoutSDK.gasEstimate({ gasEstimateType: checkout.GasEstimateType.BRIDGE_TO_L2 });