Posted in

How to batch multiple transactions using Ethers?

If you’ve ever tried processing more than a handful of Ethereum transactions, you know how quickly the small work of sending funds, updating balances, or interacting with smart contracts adds up. Each transaction requires a separate call to a node, signs individually, and waits for its own confirmation—eating time, burning extra gas, and multiplying the chances of something going wrong. As someone who’s spent years working behind the scenes as an Ethers provider, I’ve heard countless developers and project managers complain about these headaches. That’s why I’ve learned to rely on batching transactions with Ethers.js, a tool that turns a stack of isolated operations into one smooth, efficient pipeline. In this post, I’ll walk through exactly how to batch multiple transactions using Ethers, share the lessons I’ve picked up from working with dozens of teams, and explain why this method can save you time, money, and frustration. Ethers


First, let’s break down what transaction batching actually means for Ethereum. Normally, every transaction you send—whether it’s transferring ETH, minting an NFT, or interacting with a DeFi protocol—lives on the blockchain as a separate entry. Each one needs its own nonce (a number that ensures transactions are processed in order), its own gas limit and gas price, and its own signature. When you batch, you wrap all those individual operations into a single call, and send them all at once. This cuts down on node requests, reduces total gas costs, and simplifies the process for both you and your users. For teams like mine that support developers building on Ethereum, batching isn’t just a nice-to-have—it’s a core part of keeping operations scalable, whether you’re processing hundreds of transactions a day for a Web3 app or a handful for a small business.

Ethers.js is the perfect tool for this. It’s lightweight, well-documented, and built to work seamlessly with Ethereum’s core functionality. Before we dive into the steps, a quick note: batching works best for transactions that all interact with the same smart contract or target the same sender address. If you’re sending funds to dozens of different recipients across different contracts, you’ll want to adjust your approach slightly—we’ll cover that later. For now, let’s focus on the most common use case: batching transactions from a single wallet to multiple recipients on a single contract.


Step 1: Set Up Your Ethers Environment

Before you can batch transactions, you need a basic Ethers setup. If you’re new to this, start by installing Ethers via npm or yarn. Open your terminal and run:
npm install ethers

Once installed, import Ethers into your project. For most node.js or backend projects, you’ll use something like:
const { ethers } = require("ethers");

For frontend projects, you can pull Ethers from a CDN or use the same import syntax. Next, you’ll need a provider (a connection to the Ethereum network) and a signer (the wallet that will sign and send the transactions). For this example, I’ll use a testnet provider (like Sepolia) and a wallet private key—note that in production, never hardcode your private key; use a secure vault or environment variable.

// Replace with your testnet RPC URL and private key (securely stored in production)
const provider = new ethers.providers.JsonRpcProvider("https://sepolia.infura.io/v3/YOUR_INFURA_PROJECT_ID");
const signer = new ethers.Wallet("YOUR_WALLET_PRIVATE_KEY", provider);

This is your foundation. Without a properly connected provider and signer, you can’t send any transactions, let alone batch them.


Step 2: Prepare Your Transaction Data

The key to batching multiple transactions with Ethers is collecting all the individual transaction data first. Each transaction needs two things: the target address (the contract or recipient you’re interacting with) and the encoded function data (the action you want to take on the contract). For example, if you’re batching ERC-20 token transfers, you’ll encode the transfer function for each recipient.

Let’s say we have an ERC-20 token contract deployed at 0x1234567890abcdef1234567890abcdef12345678 on Sepolia. We want to send 100 tokens each to three different addresses: 0xabcdefabcdefabcdefabcdefabcdefabcdefabcd, 0xdefdefdefdefdefdefdefdefdefdefdefdefdef, and 0x1234123412341234123412341234123412341234.

First, define the contract’s ABI (Application Binary Interface) for the transfer function. The ABI tells Ethers how to encode the function call:
const tokenAbi = [
"function transfer(address to, uint256 amount) public returns (bool)"
];

Next, create a contract instance for the token:
const tokenContract = new ethers.Contract("0x1234567890abcdef1234567890abcdef12345678", tokenAbi, signer);

Now, loop through each recipient to create the encoded transaction data. For this example, let’s use 100 tokens (adjust decimals as needed—ERC-20s often use 18 decimals, so 100 tokens would be 100 * 10^18):
const recipients = [
"0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",
"0xdefdefdefdefdefdefdefdefdefdefdefdefdef",
"0x1234123412341234123412341234123412341234"
];
const amount = ethers.utils.parseUnits("100", 18); // 100 tokens, 18 decimals

// Collect all individual transaction requests
const txRequests = [];
for (const to of recipients) {
const tx = tokenContract.transfer.populateTransaction(to, amount);
txRequests.push(tx);
}

Here’s where the magic happens: populateTransaction takes the function call and returns an object with all the necessary data for a transaction—to (the contract address), data (the encoded function), and other defaults like gas limit. If you were sending ETH instead of a token, you’d skip the contract and create a transaction object with to (recipient address), value (the ETH amount), and data (empty for simple ETH sends).


Step 3: Batch the Transactions with Ethers Multicall

Now that we have all the individual transaction requests, we need to batch them. The easiest way to do this is with the Multicall contract, a standard Ethereum contract that lets you execute multiple function calls in a single transaction. Ethers has built-in support for Multicall, but you can also use a pre-deployed Multicall contract (on most testnets and mainnets, it’s deployed at 0xcA11bde05977b3631167028862bE2a173976CA11).

First, set up the Multicall contract. We’ll use the ABI for Multicall’s aggregate function, which takes an array of call data and returns the results:
const multicallAbi = [
"function aggregate(tuple(address target, bytes callData)[] calls) public payable returns (uint256 blockNumber, bytes[] returnData)"
];
const multicallAddress = "0xcA11bde05977b3631167028862bE2a173976CA11";

const multicallContract = new ethers.Contract(multicallAddress, multicallAbi, signer);

Next, we’ll format our txRequests into the structure Multicall expects: an array of tuples with target (the contract address we’re calling) and callData (the encoded function from each transaction). We can map over our txRequests array to create this:
const multicallCalls = txRequests.map(tx => ({
target: tokenContract.address,
callData: tx.data
}));

Now, send the batched transaction using the Multicall contract’s aggregate function. This single transaction will execute all three transfers in one:
try {
const txResponse = await multicallContract.aggregate(multicallCalls);
console.log("Batched transaction submitted, hash:", txResponse.hash);

// Wait for the transaction to be mined
const receipt = await txResponse.wait();
console.log("Batched transaction confirmed in block:", receipt.blockNumber);
} catch (error) {
console.error("Error batching transactions:", error);
}

Wait a second—this works, but let’s add a few refinements I’ve learned from experience. First, when creating transactions manually (instead of using populateTransaction), you should always set a nonce manually to avoid nonce collisions. If you’re batching transactions quickly, Ethers might reuse the same nonce for multiple transactions, which will cause failures. You can fetch the current nonce from the signer:
const nonce = await provider.getTransactionCount(signer.address, "pending");

Then, add it to each transaction request before batching:
for (let i = 0; i < txRequests.length; i++) {
txRequests[i].nonce = nonce + i;
}

This small step has saved countless teams from nonce-related errors, especially when batching more than 10 transactions at once.

Another refinement: gas estimation. When you batch transactions, the total gas cost is lower than sending them individually, but you’ll want to estimate the gas for the batched transaction to avoid running out of gas. You can do this with Ethers’ estimateGas method on the Multicall contract:
const gasEstimate = await multicallContract.estimateGas.aggregate(multicallCalls);
// Add a 20% buffer to the gas estimate to account for network fluctuations
const gasLimit = gasEstimate.mul(120).div(100);

Then pass gasLimit to the aggregate call:
const txResponse = await multicallContract.aggregate(multicallCalls, { gasLimit });


Step 4: Handle Simple ETH Transfers (No Smart Contracts)

What if you’re batching simple ETH sends, not contract interactions? The process is almost the same—you just don’t need the Multicall contract for function calls. Instead, you can create an array of transaction objects for each recipient, then use Ethers’ sendTransaction in a batch, but even better, use a custom batching approach for ETH. Wait—actually, for ETH, Multicall still works, but you’ll set the value in each transaction to the ETH amount, and the target will be the recipient’s address instead of a contract. Let’s adjust the example:

// For sending 0.01 ETH to 3 recipients
const ethRecipients = [
"0xabcdefabcdefabcdefabcdefabcdefabcdefabcd",
"0xdefdefdefdefdefdefdefdefdefdefdefdefdef",
"0x1234123412341234123412341234123412341234"
];
const ethAmount = ethers.utils.parseEther("0.01"); // 0.01 ETH per recipient

// Create transaction objects for each ETH send
const ethTxRequests = ethRecipients.map(to => ({
to: to,
value: ethAmount,
nonce: await provider.getTransactionCount(signer.address, "pending") // Add manual nonce
}));

// For Multicall, format each call with target = recipient, callData = empty (no function)
const ethMulticallCalls = ethTxRequests.map(tx => ({
target: tx.to,
callData: "0x", // Empty data for simple ETH sends
value: tx.value
}));

// Send with Multicall
const txResponse = await multicallContract.aggregate(ethMulticallCalls, { gasLimit: … });

This works because Multicall accepts any call to an address, even if it’s just sending ETH (no function call needed).


Common Pitfalls to Avoid (Lessons From Ethers Provider Experience)

After working with hundreds of clients, I’ve seen the same mistakes trip developers up when batching transactions. Let’s go over them so you don’t have to:

  1. Ignoring Decimals for Tokens: This is the number one error. ERC-20 tokens use different decimal places (18 is standard, but some use 6 or 8). If you use parseUnits with the wrong decimal, you’ll either send too little or too many tokens. Always confirm the token’s decimals before creating your amount.
  2. Nonce Collisions: As I mentioned earlier, when batching multiple transactions in quick succession, Ethers might auto-assign the same nonce. Always manually set the nonce for each transaction (starting from the current nonce and incrementing by 1 for each batch item) to avoid “nonce too low” or “nonce too high” errors.
  3. Gas Underestimation: Network congestion can cause gas prices to spike, and batching means a single failed transaction (out of the batch) can waste all the gas for that batch. Always add a buffer to your gas estimate—20-30% is standard.
  4. Using the Wrong Multicall Contract Address: Multicall is deployed on every EVM chain, but the address changes. For mainnet it’s 0xcA11bde05977b3631167028862bE2a173976CA11, but for testnets or lesser-known chains, double-check the address (Chainlist has a full list).
  5. Over-Batching: Batching 100 transactions is more efficient, but if you batch 1,000 at once, you might hit gas limits for the block. Aim for batches of 10-50 transactions, depending on the network (Ethereum blocks have a gas limit around 30 million, so 10 transactions at 2 million gas each is safe).

When Batching Makes (And Doesn’t Make) Sense

Batching is great for:

  • Sending tokens or ETH to multiple users (like airdrops, payroll, or refunds)
  • Updating multiple balances in a single smart contract
  • Processing repeated interactions with the same protocol (like staking multiple times)

It’s less useful for:

  • Transactions that require unique signatures or individual logic (each transaction has a different function call that can’t be grouped)
  • High-priority transactions where you can’t risk waiting for a single batch to confirm (batches add one confirmation instead of multiple, so if one fails, all in the batch do)

For teams looking to scale, batching is a foundational step—but it’s not the only one. At our Ethers provider, we help teams optimize their batching strategies, from selecting the right Multicall deployment to adjusting gas limits for different network conditions, so you can balance speed and cost.


If you’re ready to implement transaction batching for your project, or if you have questions about adjusting this approach for your specific use case, our team is here to help. Whether you’re building a small Web3 app, a DeFi protocol, or a business that needs to process frequent on-chain transactions, we can walk through setup, troubleshoot common issues, and tailor a strategy that fits your needs. Get in touch with our procurement team to discuss your requirements and request a custom demo of batching with Ethers.


Esters References
Ethers.js Documentation: https://docs.ethers.org/v5/
Multicall Contract Standard: https://github.com/mds1/multicall
ERC-20 Token Standard: https://eips.ethereum.org/EIPS/eip-20


Qingdao Jinforest Chem Tech Co., Ltd.
Qingdao Jinforest Chem Tech Co., Ltd. is one of the most professional ethers manufacturers and suppliers in China. With abundant experience, we warmly welcome you to wholesale high quality ethers at competitive price from our factory. If you have any enquiry about quotation, please feel free to email us.
Address: Huangdao District, Qingdao City, Shandong Province (3002, Unit 1, Block B, No.226 Changjiang Middle Road, Former Development Zone)
E-mail: cecilia@kozorigin.com
WebSite: https://www.jinforestchem.com/