thirdweb
  • Homepage ↗
  • Guides
  • Case Studies
  • Changelog
  • Docs ↗
  • YouTube ↗
Smart Wallets

Batch Transactions with the Smart Wallet

  • Ciara Nightingale

Ciara Nightingale

14 Aug 2023 • 4 min read
Batch Transactions with the Smart Wallet

In this guide we will go through how to batch multiple transactions into a single transaction with smart wallet in a backend script.

💡
To learn more about smart wallet, visit the portal documentation. Reminder: smart wallet is an account abstraction component that you can use in scripts and applications. If you would like to use the thirdweb infrastructure, such as bundler and paymaster services that power smart wallet, make sure to obtain an API key from the thirdweb dashboard.

The full source-code for this guide is available on GitHub:

GitHub - thirdweb-example/smart-wallet-batch-tx-script
Contribute to thirdweb-example/smart-wallet-batch-tx-script development by creating an account on GitHub.
GitHubthirdweb-example

Batching Transactions

One of the main benefits of a smart wallet is that code determines how it functions because it is a smart contract wallet. We have added a function to the smart wallet to enable batching transactions - executeBatch(). This means that only one signature is required from the personal wallet in order to execute multiple transactions. This streamlines the user experience significantly as user flows which would previously have been tedious, now become simplified. For example, you could deploy an NFT contract, mint an NFT and transfer the NFT all in a single user click and single transaction.

Creating a Smart Wallet Script

To demonstrate batching transactions, we are going to perform two transactions in a single batch:

  1. Claim a token from a TokenDrop contract.
  2. Claim an edition NFT from an EditionDrop contract.

To get started, we first need to setup a script which initializes a personal wallet, creates a smart wallet and then gets instances of each drop contract:

import { config } from "dotenv";
import { ThirdwebSDK } from "@thirdweb-dev/sdk";
import { readFileSync } from "fs";
import { Goerli } from "@thirdweb-dev/chains";
import {
  SmartWallet,
  SmartWalletConfig,
} from "@thirdweb-dev/wallets";
import { LocalWalletNode } from "@thirdweb-dev/wallets/evm/wallets/local-wallet-node";

config();

const chain = Goerli;
const factoryAddress = "0x3c115305ecC8119D9517BB67a5B3D4073Bc9CffF";
const secretKey = process.env.THIRDWEB_SECRET_KEY as string;

const main = async () => {
  if (!secretKey) {
    throw new Error(
      "No API Key found, get one from https://thirdweb.com/dashboard"
    );
  }
  console.log("Running on", chain.slug, "with factory", factoryAddress);

  // Load or create personal wallet
  // here we generate LocalWallet that will be stored in wallet.json
  const personalWallet = new LocalWalletNode();
  await personalWallet.loadOrCreate({
    strategy: "encryptedJson",
    password: "password",
  });

  const personalWalletAddress = await personalWallet.getAddress();
  console.log("Personal wallet address:", personalWalletAddress);

  // Configure the smart wallet
  const config: SmartWalletConfig = {
    chain,
    factoryAddress,
    secretKey,
    gasless: true,
  };

  // Connect the smart wallet
  const smartWallet = new SmartWallet(config);
  await smartWallet.connect({
    personalWallet,
  });

  // now use the SDK normally to perform transactions with the smart wallet
  const sdk = await ThirdwebSDK.fromWallet(smartWallet, chain, {
    secretKey: secretKey,
  });

  console.log("Smart Account addr:", await sdk.wallet.getAddress());
  console.log("balance:", (await sdk.wallet.balance()).displayValue);

  // Claim a ERC20 token
  const contract = await sdk.getContract(
    "0xc54414e0E2DBE7E9565B75EFdC495c7eD12D3823" // TokenDrop on goerli
  );
  const editionContract = await sdk.getContract(
    "0x8096C71f400984C3C1B7F3a79Ab0C0EaC417b91c"
  ); // EditionDrop on goerli
  const tokenBalance = await contract.erc20.balance();
  const editionBalance = await editionContract.erc1155.balance(0);
  console.log("ERC20 token balance:", tokenBalance.displayValue);
  console.log("Edition NFT balance:", editionBalance.toNumber());
};

main();

Here, we have used LocalWalletNode as the personal wallet or key. This is to keep things simple however, you could use any other EOA wallet from the wallet SDK including MetaMask EmailWallet or CoinbaseWallet.

If this seems complicated or you are confused at this point, check out this guide which explains how to use smart wallet in a backend:

How to Deploy a Smart Wallet (ERC-4337)
Learn what a smart wallet is, what its use cases are, and how you can use them to create powerful wallet experiences for users.
thirdwebAtharva Deosthale

Batching Transactions

To batch our transactions, we first need to prepare an array of transactions to execute using the Transaction Builder from the thirdweb SDK. To do this, we will use the function prepare()

// Execute multiple transactions at once
  const tx1 = await contract.erc20.claim.prepare(1);
  const tx2 = await editionContract.erc1155.claim.prepare(0, 1);
  const transactions = [tx1, tx2];

Now, we need to use the method executeBatch on the SmartWallet instance we created earlier and pass the transactions to be executed:

const batchTx = await smartWallet.executeBatch(transactions);
  console.log(
    "Claimed 1 ERC20 token & 1 Edition NFT, tx hash:",
    batchTx.receipt.transactionHash
  );
  const tokenBalanceAfter = await contract.erc20.balance();
  const editionBalanceAfter = await editionContract.erc1155.balance(0);
  console.log("ERC20 token balance:", tokenBalanceAfter.displayValue);
  console.log("Edition NFT balance:", editionBalanceAfter.toNumber());

This will return a TransactionResult containing the transaction receipt.

Running the script in your terminal using the command yarn start will yield the following output:

As you can see from the token and edition NFT balances, we have successfully executed both transactions in a  single transaction!

For the full source code, check out this GitHub repository.

Wrapping Up

Smart wallet is a smart contract wallet meaning that code defines the functionality. This means we can create a streamlined user experience by creating functions to, for example, execute multiple transactions while only requiring one signature from the personal wallet.

This guide has demonstrated how using thirdweb's smart wallet, the batching transaction is super easy!

If you have any questions or would like to share anything, please reach out on Discord where you can speak directly to the thirdweb team.

Server wallet token swapping in dashboard

Server wallet token swapping in dashboard

You can now swap tokens held by your server wallets directly from the dashboard. Useful to convert the fees and payments you receive to the token / chain of your choice. Simply head to your project dashboard, you'll find a new "Swap" button in your project wallet
05 Dec 2025 1 min read
Bridge improvements

Bridge improvements

We recently shipped 3 important improvements to the Bridge API and widgets. 1 - Batched transactions with ERC-5792 We reduced the number of confirmations required by half for erc20 token swaps in the Bridge widgets. Under the hood we leverage ERC-5792 enabled wallets to atomically perform approvals and swaps in
04 Dec 2025 1 min read
Bridge and swap over 14,000+ tokens on over 95+ EVM chains

Bridge and swap over 14,000+ tokens on over 95+ EVM chains

The Fastest and Easiest Way To Move Tokens Across Any EVM Chain If you’ve ever tried to move tokens between blockchains, you know the drill: tabs on tabs on tabs… swapping here, bridging there, and then you finally get to play with the app you logged onto 15 minutes
03 Dec 2025 3 min read
thirdweb © 2025
Powered by Ghost