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 Optimism to pay for transaction execution on Arbitrum
Install AbstractJS and viem
npm install @biconomy/abstractjs viem @rhinestone/module-sdk@0.2.3
Initialize the infrastructure
In order to use cross-chain gas features, users need to initialize the MultichainSmartAccount
and connect to the Biconomy MEE Node.
To learn more about the setup, read our Building a Chain Abstracted App guide.
// Initialize the MultichainSmartAccount
const mcNexus = await toMultichainNexusAccount({
chains: [optimism, base, polygon],
transports: [http(), http(), http()],
signer: eoaAccount
})
// Connect to the MEE Node
const meeClient = await createMeeClient({
account: mcNexus
})
Encode a Supertransaction
Cross-chain gas functionalities in AbstractJS
are achieved by encoding and executing
Supertransactions
// Placeholder call - sends 0 ETH to 0x0000000
const emptyCall: AbstractCall = {
to: zeroAddress,
value: 0n
}
const crossChainGasSupertx: Supertransaction = {
instructions: [
mcNexus.build({ type: "default", data: { chainId: arbitrum.id, calls: [emptyCall] } }),
],
// Pay for gas with USDC on Optimism
feeToken: {
address: mcUSDC.addressOn(optimism.id),
chainId: optimism.id
}
}
Get the Execution Quote
Send the Supertransaction to the MEE Node to get the quote for the execution of your cross-chain gas Supertransaction.
The quote contains the price for which the MEE Node will execute the Supertransaction.
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
const { hash } = await executeQuote(meeClient, { quote })
Wait for the Execution to Complete
Track the execution status of the Supertransaction
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
.