Multicall is a smart contract pattern and protocol that enables developers to bundle multiple separate blockchain function calls—such as reading token balances, querying prices, or executing state changes—into a single, aggregated transaction. This batching mechanism is a fundamental optimization tool for reducing network load, minimizing latency, and lowering gas costs for users interacting with decentralized applications (dApps). By consolidating operations, it addresses the inherent inefficiency of making numerous sequential requests to a blockchain node.
Multicall
What is Multicall?
A protocol for batching multiple read or write calls into a single transaction to optimize blockchain interactions.
The protocol operates through a dedicated Multicall contract deployed on-chain. Instead of sending individual transactions, a client constructs an array of call data, specifying the target contract addresses, the function selectors, and the encoded arguments for each desired operation. This array is sent to the Multicall contract's aggregate or tryAggregate function, which executes each call in sequence within the confines of a single transaction block. The contract then returns an array of the results and success statuses for each sub-call, allowing the client to process them efficiently.
For read-only operations (calls), Multicall is primarily a performance and reliability enhancement. It drastically reduces the number of remote procedure calls (RPC) a frontend must make, speeding up data fetching for complex dashboards or portfolios. For state-changing operations (transactions), it can significantly reduce total gas fees by paying the base transaction cost only once and can enable atomic execution, where a set of actions either all succeed or all fail. Prominent implementations include the canonical Multicall3 contract by Michael Elliot, which is deployed on dozens of networks.
Common use cases include fetching portfolio data (e.g., multiple token balances and staking positions in one query), performing complex on-chain calculations that require data from several sources, and executing multi-step DeFi strategies atomically. Developers integrate it using libraries like ethers.js or viem, which provide helper functions to encode calls and decode the aggregated results. Its adoption is now considered a best practice for efficient dApp development, forming a critical piece of infrastructure in the Web3 stack.
How Multicall Works
A technical breakdown of the Multicall pattern, a smart contract technique for bundling multiple on-chain calls into a single transaction to improve efficiency and user experience.
Multicall is a smart contract design pattern that aggregates multiple read or write function calls into a single, batched transaction. Instead of sending individual transactions for each operation—like checking multiple token balances or approving and swapping in a single action—a user or dApp submits one transaction containing an array of encoded calls. The Multicall contract acts as a router, executes each call in sequence, and returns all results in a single response. This fundamental mechanism is the cornerstone for reducing network congestion, lowering gas costs, and creating seamless user interactions in decentralized applications.
The technical execution involves encoding the target address, function selector, and calldata for each desired operation. This encoded data is passed to the Multicall contract's aggregate or multicall function. The contract uses a low-level delegatecall or call to execute each item in the array against their respective target contracts. For read calls (eth_call), this happens off-chain via an RPC provider, returning all results instantly without gas. For write calls, the entire batch is confirmed in one on-chain transaction, with the gas cost often being less than the sum of its individual parts due to fixed overhead costs per transaction.
Prominent implementations include MakerDAO's Multicall and OpenZeppelin's library, which have become standard infrastructure. Key use cases are manifold: - Data Fetching: Querying multiple wallet balances, prices, or states in one RPC request for dashboards. - Atomic Operations: Ensuring a series of actions—like approve, swap, and deposit into a vault—succeed or fail together, preventing partial execution. - Gas Optimization: Significantly reducing costs for complex DeFi interactions by minimizing redundant transaction overhead. This pattern is essential for the composability and efficiency of modern Ethereum and EVM-compatible blockchains.
Key Features & Benefits
Multicall is a smart contract pattern that aggregates multiple read or write calls into a single transaction, optimizing for efficiency and user experience.
Batch Read Operations
Aggregates multiple view function calls (e.g., fetching token balances, price data) into a single RPC request. This drastically reduces latency and network overhead for applications like dashboards and portfolio trackers.
- Key Benefit: Enables fetching complex, multi-contract state in one network round trip.
- Example: A DEX frontend can query 10 different liquidity pool reserves simultaneously.
Atomic Write Bundling
Bundles multiple state-changing transactions (e.g., token approvals and swaps) into one atomic transaction. If any call in the bundle fails, the entire transaction reverts, protecting users from partial execution.
- Key Benefit: Improves user experience by reducing wallet pop-ups and gas costs for multi-step operations.
- Use Case: A single transaction to approve a token and execute a complex DeFi strategy.
Gas Optimization
Reduces the total gas cost for users by consolidating transaction overhead. Instead of paying base gas for each individual transaction, users pay it once for the bundled multicall.
- Mechanism: Saves on intrinsic gas costs (21,000 gas per tx) and can optimize calldata.
- Impact: Essential for complex DeFi interactions where executing steps separately would be prohibitively expensive.
Error Handling & Reverts
Provides structured error propagation. Advanced implementations allow calls to continue on failure or return detailed revert data for each sub-call, enabling robust fallback logic.
- Try-Aggregate: A pattern that attempts all calls and returns results for successful ones, ignoring failures.
- Benefit: Builds more resilient applications that can handle partial data retrieval or conditional execution paths.
MEV & Front-Running Mitigation
Helps mitigate Maximal Extractable Value (MEV) and front-running for complex trades. By batching sensitive operations (like a DEX swap followed by a deposit) into one atomic transaction, it reduces the window for predatory bots to intercept profitable opportunities between steps.
- Limitation: Does not protect against within-block MEV, but eliminates between-transaction arbitrage.
Code Example
A practical demonstration of how to implement the Multicall pattern in a smart contract to batch multiple read or write operations into a single transaction.
The following Solidity code example demonstrates a basic implementation of a Multicall contract, a pattern popularized by Uniswap V3. This contract exposes a single function, multicall, which accepts an array of bytes data representing encoded function calls. The contract iterates through this array, making low-level delegatecalls to itself for each item, which allows it to execute multiple functions in sequence within a single transaction. This is a foundational pattern for reducing network overhead and improving user experience in decentralized applications (dApps).
The key technical mechanism is the use of delegatecall within the loop. When delegatecall is invoked, the code at the target address (in this case, the contract itself) is executed in the context of the caller's storage, msg.sender, and msg.value. This allows the multicall function to act as a router, dispatching each encoded call to the correct internal function. The function includes a check for failed calls using a require statement, ensuring the entire batch reverts if any individual call fails, maintaining atomicity. This fail-fast behavior is critical for state consistency.
Developers typically use this pattern to batch read-only queries to a smart contract, significantly reducing the number of RPC calls a frontend needs to make. However, it can also batch state-changing write operations, though this requires careful handling of msg.value across calls. The example shows a simple return data aggregation, but more advanced implementations, like OpenZeppelin's Multicall.sol, handle return data more robustly and manage msg.value for payable functions. This pattern is a cornerstone of efficient blockchain interaction, directly combating the "over-fetching" problem common in dApp development.
Primary Use Cases
The Multicall pattern is a foundational smart contract technique for batching multiple on-chain read or write operations into a single transaction, addressing core blockchain inefficiencies.
Aggregating On-Chain Data
DApps and analytics dashboards use Multicall to fetch multiple pieces of state in a single RPC call. This is critical for efficiently populating user interfaces with data like token balances, pool reserves, and protocol metrics without hitting rate limits or causing excessive latency. For example, a DeFi front-end can batch queries for a user's positions across 20 different liquidity pools.
Optimizing Transaction Execution
For write operations, Multicall bundles multiple function calls (e.g., approve and swap, or deposit into multiple vaults) into one transaction. This reduces the gas cost overhead per action, minimizes wallet pop-ups for users, and ensures atomic execution—all actions succeed or fail together. It's a standard pattern in complex DeFi interactions.
Mitigating Front-Running
In decentralized exchanges, Multicall can be used to submit a sequence of actions—such as a price check followed immediately by a trade—within the same transaction. This creates a more atomic execution environment, reducing the window for MEV (Maximal Extractable Value) bots to front-run profitable trades by sandwiching them.
Simulating Complex States
Developers and integrators use Multicall for off-chain simulation. By batching multiple eth_call queries, they can simulate the outcome of a hypothetical series of transactions (e.g., a multi-step arbitrage path) without spending gas. This is essential for building robust bots, risk engines, and transaction builders.
Reducing RPC Load & Cost
By consolidating dozens of individual JSON-RPC requests into one, Multicall significantly reduces the load on node providers and can lower costs for services using paid RPC endpoints. This scalability benefit is crucial for applications serving high volumes of read queries, such as blockchain explorers or portfolio trackers.
Ecosystem Usage
Multicall is a smart contract utility that aggregates multiple read or write calls into a single transaction, reducing network overhead and improving the user experience for decentralized applications (dApps).
Atomic Write Transactions
Multicall contracts also enable batching state-changing transactions, allowing users to execute multiple actions atomically. This is critical for complex DeFi strategies where operations must succeed or fail together to avoid partial execution. Common patterns include:
- Approving and swapping tokens in one transaction.
- Adding liquidity across multiple pools.
- Claiming rewards from several staking contracts simultaneously.
Gas Optimization
By bundling calls, Multicall reduces the total gas overhead associated with transaction initiation and calldata. While each individual operation still consumes gas, the savings from combining multiple transactions into one can be significant, especially for simple calls. This makes complex interactions more affordable and is a standard optimization in wallet interfaces and automated trading systems.
MEV & Slippage Protection
For write transactions, atomic execution via Multicall provides protection against Maximal Extractable Value (MEV) and slippage risks. By ensuring a sequence of trades or liquidity actions either all succeed or all revert, it prevents malicious bots from sandwiching individual transactions within the batch, securing user funds and intended execution prices.
Cross-Chain Implementations
While pioneered on Ethereum, the Multicall pattern is now a cross-chain standard. Most EVM-compatible chains (Polygon, Arbitrum, BSC) and even some non-EVM networks have deployed their own versions. This consistency allows developers to use the same batching logic across different blockchain environments, simplifying multi-chain dApp architecture.
Security Considerations
While the Multicall pattern is a powerful tool for batching transactions, it introduces unique security considerations for both users and developers. Understanding these risks is crucial for safe interaction with smart contracts.
Atomicity & Partial Failure
A key security feature of Multicall is atomic execution: all calls in the batch either succeed or fail together. This prevents partial state corruption where some operations complete while others revert. However, developers must be aware that a single failing sub-call (e.g., due to insufficient allowance, slippage, or a custom revert) will cause the entire batch to revert, which can be a usability consideration.
DelegateCall Risks
Some Multicall implementations support delegatecall, which executes code in the context of the calling contract. This is extremely dangerous if users can supply arbitrary target addresses. A malicious contract could perform a storage collision attack, overwriting the caller's critical state variables. Secure implementations strictly whitelist allowed targets or disable delegatecall functionality for user-supplied calls.
Frontrunning & MEV
Batched transactions are visible in the mempool and can be vulnerable to Maximal Extractable Value (MEV) exploitation. A searcher might frontrun a profitable arbitrage opportunity contained within a user's batch. Using private transaction relays or Flashbots Protect can mitigate this. The atomic nature of Multicall also prevents sandwich attacks on individual swaps within the batch, as the entire sequence is executed in a single block.
Gas Limit & Reentrancy
Batching multiple calls can consume significant gas, risking an out-of-gas revert for the entire transaction. Contracts must also guard against reentrancy within the batch. While a Multicall function itself may not be reentrant, a sub-call could re-enter the parent contract through another function if proper checks (like the Checks-Effects-Interactions pattern) are not in place across the entire contract system.
Signature Replay & Phishing
When signing a permit for a token approval within a Multicall, ensure the signature is bound to the specific batch. A malicious dApp could trick a user into signing a generic approval, then replay that signature in a different, harmful Multicall transaction. Always verify that signed data includes a nonce and is specific to the intended contract call sequence.
Multicall vs. Standard Calls
A technical comparison of batch and individual on-chain read operations.
| Feature / Metric | Standard RPC Call | Multicall (Aggregated) |
|---|---|---|
Call Mechanism | Single, sequential contract call | Batched, single transaction with multiple calls |
Network Round Trips (RTT) | 1 per call | 1 for the entire batch |
Latency Overhead | High (serialized waits) | Low (parallel execution in EVM) |
Gas Cost for Reads | 21,000 gas base per call | ~21,000 gas base + ~(100-500 gas per internal call) |
Developer Experience | Multiple async/await calls, complex error handling | Single function call, consolidated results |
Error Handling | Fails individually; other calls proceed | Fails atomically; entire batch reverts (default behavior) |
Typical Use Case | Fetching a single user balance or NFT owner | Populating a dashboard with multiple data points |
Blockchain Load | Higher (more transactions) | Lower (fewer transactions) |
Common Misconceptions
Multicall is a fundamental tool for blockchain efficiency, but its capabilities and limitations are often misunderstood. This section clarifies key points about batching transactions, gas optimization, and state management.
No, a Multicall is a single on-chain transaction that contains multiple, distinct function calls bundled together. The key distinction is that while the user signs and pays for one transaction, the Ethereum Virtual Machine (EVM) executes the bundled calls sequentially within that single transaction's context. This atomic execution means all calls succeed or fail together, but they are not merged into one operation; each call's logic, state changes, and gas consumption are separate and occur in the specified order.
Technical Breakdown:
- Transaction Hash: One hash is generated for the entire bundle.
- Execution: Calls run one after another, with the output of one call not directly accessible to the next unless the contract is designed for it (see DELEGATECALL).
- Atomicity: A revert in any call causes the entire Multicall transaction to revert, preventing partial state updates.
Frequently Asked Questions
Multicall is a core smart contract pattern for batching multiple on-chain operations. These questions address its core mechanics, benefits, and implementation.
Multicall is a smart contract pattern that allows multiple read or write function calls to be aggregated into a single transaction. It works by deploying a helper contract with an aggregate or multicall function that takes an array of call data (target address, encoded function data) as input, executes each call in sequence, and returns an array of the results. This batching mechanism is fundamental for improving efficiency and user experience in decentralized applications (dApps).
For read calls, it reduces the number of separate RPC requests a frontend must make. For write calls, it allows users to approve a token and execute a swap, or perform multiple protocol interactions, in one atomic transaction, saving significant gas and reducing the risk of partial execution.
Further Reading
Explore the technical architecture, practical implementations, and ecosystem impact of the Multicall pattern.
Technical Architecture
A Multicall contract is a deployed smart contract that aggregates multiple function calls. It typically exposes a single aggregate or tryAggregate function that takes an array of call data. Key architectural features include:
- Static vs. Delegate Calls: Standard
callfor simple reads,delegatecallfor composing logic from other contracts. - Error Handling: Robust implementations use
try/catchpatterns to allow partial batch success. - Gas Optimization: Reduces overhead by batching transactions, saving on base gas (21k) and repeated opcode costs.
Use Cases & Examples
Multicall is foundational for efficient blockchain interaction. Common use cases are:
- Dashboard Data Fetching: Aggregating wallet balances, staking positions, and pool APYs from multiple protocols in one query.
- Atomic Transactions: Submitting multiple approvals and swaps in a single transaction to avoid front-running and reduce cost.
- Smart Contract Automation: Executing a series of governance votes or liquidity management actions atomically.
- Example: A DeFi frontend uses Multicall to get a user's USDC balance, Uniswap V3 positions, and Aave debt ceiling in one RPC call.
MakerDAO's Multicall
MakerDAO's Multicall implementation is one of the earliest and most influential, designed for the Maker Protocol. It enables atomic execution of multiple governance and vault management actions. Key characteristics:
- Delegatecall Focus: Primarily used to batch calls to the
DssProxyActionscontract for CDP management. - Gas Savings for Complex Operations: Essential for actions like opening a vault, drawing DAI, and swapping in one transaction.
- Ecosystem Standard: Its design heavily influenced later generalized implementations like Uniswap's and BentoBox's.
EIP-5792: Wallet Call Bundling
EIP-5792 proposes a standard for wallet-native call bundling, moving batch execution logic from standalone contracts into the wallet itself. This enables:
- Sponsored Transactions: A third party can pay for a bundle of calls executed from a user's wallet.
- Improved UX: Native wallet support for complex, atomic multi-step interactions.
- Reduced Latency: Eliminates the need to deploy and interact with a separate Multicall contract for simple bundles. It represents the next evolution, making batched calls a first-class primitive.
Aggregators & SDKs
Major infrastructure providers offer Multicall utilities to simplify developer integration:
- ethers.js & viem: Both libraries have built-in
MulticallProvideror batch call utilities to abstract RPC aggregation. - The Graph: While not a Multicall replacement, it serves a similar data-fetching purpose by indexing and aggregating on-chain data into single queries.
- DefiLlama / Yearn's Multicall: A widely adopted, gas-optimized contract used by many analytics dashboards for efficient data fetching across chains. Using these tools is considered a best practice for any application reading significant on-chain state.
Get In Touch
today.
Our experts will offer a free quote and a 30min call to discuss your project.