Skip to content

Sending Batch Transactions with SDK ⚡️

Account abstraction enables the bundling of multiple transactions into a single transaction. This can be useful in various scenarios, such as executing multiple trades at once on a decentralized exchange or making batch payments. For instance, you can deploy an NFT contract, mint an NFT, and transfer it, all with a single user action and transaction.

We have created a quick start template repository that you can use to get started. It comes set up with TypeScript, viem, and @biconomy/sdk.

Set up an owner account

First, we need to set up an Owner for the Smart Account which will be used to sign User Operations (transactions) for the Smart Account.

import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
 
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(`${privateKey}`);

Set up Nexus client

A Smart Account needs access to the Network to query for information about its state (e.g., nonce, address, etc.). Let's configure a client for the Smart Account. A bundlerUrl is required to submit User Operations to the Network, which will initialize the Smart Account.

import { createSmartAccountClient, createBicoPaymasterClient } from "@biconomy/sdk";
import { baseSepolia } from "viem/chains"; 
import { http } from "viem"; 
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
 
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(`${privateKey}`);
 
const bundlerUrl = "https://bundler.biconomy.io/api/v3/84532/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44"; 
const paymasterUrl = "https://paymaster.biconomy.io/api/v2/84532/F7wyL1clz.75a64804-3e97-41fa-ba1e-33e98c2cc703";
 
const nexusClient = await createSmartAccountClient({ 
    signer: account, 
    chain: baseSepolia, 
    transport: http(), 
    bundlerTransport: http(bundlerUrl), 
    paymaster: createBicoPaymasterClient({paymasterUrl})
});

Send batch transactions

Next, define the transactions you want to send in a batch. Each transaction should specify the necessary parameters. Use the sendTransaction method to send the batch of transactions.

import { createSmartAccountClient, createBicoPaymasterClient } from "@biconomy/sdk";
import { baseSepolia } from "viem/chains"; 
import { http, parseEther } from "viem"; 
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
 
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(`${privateKey}`);
 
const bundlerUrl = "https://bundler.biconomy.io/api/v3/84532/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44"; 
const paymasterUrl = "https://paymaster.biconomy.io/api/v2/84532/F7wyL1clz.75a64804-3e97-41fa-ba1e-33e98c2cc703"; 
 
const nexusClient = await createSmartAccountClient({ 
    signer: account, 
    chain: baseSepolia, 
    transport: http(), 
    bundlerTransport: http(bundlerUrl), 
    paymaster: createBicoPaymasterClient({paymasterUrl})
});
 
const hash = await nexusClient.sendTransaction({ 
    calls: [ 
        {
            to: '0xf5715961C550FC497832063a98eA34673ad7C816', 
            value: parseEther('0'), 
        },
        {
            to: '0x0000000000000000000000000000000000000000',
            data: "0x", 
        },
    ], 
}); 
const receipt = await nexusClient.waitForTransactionReceipt({ hash }); 

You have successfully sent batch transactions using the SDK. For more advanced features and options, refer to the official documentation.

See sendTransaction Docs