Skip to content

Paying for Gas Across Chains

AbstractJS enables developers to use native and ERC20 tokens on any supported chain to pay for gas on any other supported chain.

This means that as long as your user has either native tokens or ERC20 tokens on any chain, they can execute transactions on all of them

Guide

This guide will demonstrate how to use USDC on Optimsim to pay for transaction execution on Arbitrum

Install AbstractJS and viem

Install AbstractJS
npm install @biconomy/abstractjs viem

Initialize the infrastructure

In order to use cross-chain gas features, users need to intialize the MultichainSmartAccount and connect to the Biconomy Superbundler.

To learn more about the setup, read our Building a Chain Abstracted App guide.

Connect the infrastructure
// Initialize the MultichainSmartAccount
const mcNexus = await toMultichainNexusAccount({
  chains: [optimism, base, polygon],
  signer: eoaAccount
})
 
// Connect to the Superbundler
const meeClient = createMeeClient({
  account: mcNexus
})

Encode a Supertransaction

Cross-chain gas functionalities in AbstractJS are achieved by encoding and executing Supertransactions.

Encode a Supertransaction
// Placeholder call - sends 0 ETH to 0x0000000
const emptyCall: AbstractCall = {
  to: zeroAddress,
  value: 0n,
  gasLimit: 50_000n
}
 
const crossChainGasSupertx: Supertransaction = {
  instructions: [
    // Transaction on Arbitrum
    { calls: [emptyCall], chainId: arbitrum.id }
  ],
  // Pay for gas with USDC on Optimsim
  feeToken: toFeeToken({
    chainId: optimism.id,
    token: mcUSDC
  })
}

Get the Execution Quote

Send the Supertransaction to the Superbundler to get the quote for the execution of your cross-chain gas Supertransaction.

The quote contains the price for which the Superbundler will execute the Supertransaction.

Get Quote
const quote = await getQuote(meeClient, crossChainGasSupertx)
 
console.log(
  // Human readable token amount, e.g. 1.3 
  quote.paymentInfo.tokenAmount
)

Execute the Supertransaction

If you're happy with the offered price, sign and execute the Supertransaction

Execute Supertransaction
const { hash } = await executeQuote(meeClient, { quote })

Wait for the Execution to Complete

Track the execution status of the Supertranaction

Wait for Receipt
const receipt = 
  await waitForSupertransactionReceipt(meeClient, { hash })
 
// Get the link to MEEScan
console.log(getMeeScanLink(hash))

To track the transaction go to MEEScan and paste the hash.