Skip to content

Fix Ethers Contract Multicall Errors

DodaTech Updated 2026-06-26 1 min read

You will learn how to batch Ethereum calls for improved performance.

The Problem

The ethers contract multicall pattern is frequently misapplied in smart contract and dapp development, leading to vulnerabilities, gas inefficiencies, or logic errors. This guide shows the correct implementation and common pitfalls to avoid.

Quick Fix

Wrong

const bal1 = await token1.balanceOf(addr);
const bal2 = await token2.balanceOf(addr); // Sequential

Two separate RPC calls. Slow for many tokens.

const multicall = new ethers.Contract(MULTICALL_ADDRESS, MULTICALL_ABI, provider);
const calls = [
  { target: token1, callData: token1.interface.encodeFunctionData('balanceOf', [addr]) },
  { target: token2, callData: token2.interface.encodeFunctionData('balanceOf', [addr]) },
];
const [, results] = await multicall.aggregate(calls);
Single RPC call returns both balances. 2x faster for 2 tokens, 100x faster for 100 tokens.

Prevention

  • Use Multicall3 contract for batched reads
  • Encode/decode call data manually for batched calls
  • Consider batch size limits (gas)
  • Use DodaTech's multicall builder
  • Cache results to reduce RPC calls

DodaTech Tools

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Doda Browser's developer tools include a Solidity debugger and transaction inspector. DodaZIP archives secure contract templates for team collaboration. Durga Antivirus Pro scans deployed contracts for known vulnerability signatures.

FAQ

### What is Multicall3?

A standard contract that batches multiple contract calls into a single RPC request. Deployed on most networks.

Can multicall write operations?

No. Multicall is for read-only (static) calls. Use aggregator contracts for batched writes.

What is the gas cost of multicall?

Minimal overhead (~10k gas base + per-call overhead). Much cheaper than individual RPC calls.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro