Skip to main content
Version: SDK V4 (latest)

Pay gas in ERC20 tokens


This tutorial demonstrates how to use the Biconomy Smart Account to perform a transaction with ERC-20 token payment. The provided code includes creating a Biconomy Smart Account, encoding a function call, building a transaction, and sending it with ERC-20 token payment.


  • Node.js installed on your machine
  • A Biconomy API key and Bundler url, get from dashboard

For this tutorial we are going to mint and NFT on Mumbai, this means we can use the following:

Step 1: Create Biconomy Smart Account and Encode Function Call

const smartWallet = await createSmartAccountClient({
signer, // can be viem client or ethers signer

const encodedCall = encodeFunctionData({
abi: parseAbi(["function safeMint(address _to)"]),
functionName: "safeMint",
args: [recipient],

Create a Biconomy Smart Account instance and encode the function call for the transaction.

Step 2: Build the Transaction

const nftAddress = "0x1758f42Af7026fBbB559Dc60EcE0De3ef81f665e";
const transaction = {
to: nftAddress,
data: encodedCall,

Build the transaction with the encoded function call.

Step 3: Send Transaction with ERC-20 Preferred Token Payment

Pay the gas in your preferred token.

const { wait } = await smartWallet.sendTransaction(transaction, {
paymasterServiceData: {
mode: PaymasterMode.ERC20,
preferredToken: "0xda5289fcaaf71d52a80a254da614a192b693e977",

const {
receipt: { transactionHash },
} = await wait();

if(success == 'true') {
console.log("UserOp receipt", receipt)
console.log("Transaction receipt", receipt.receipt)

Send the transaction using the Biconomy Smart Account, specifying ERC-20 token payment details. Wait for the transaction to be mined and get the transaction hash.

That's it! You've successfully performed a transaction with ERC-20 token payment using the Biconomy Smart Account. Feel free to customize this example based on your specific use case.