Filecoin Docs
BasicsStorage providersNodesNetworksSmart contractsReference
  • Welcome to Filecoin Docs
  • Basics
    • What is Filecoin
      • Crypto-economics
      • Blockchain
      • Storage model
      • Storage market
      • Retrieval market
      • Programming on Filecoin
      • Networks
    • The blockchain
      • Actors
      • Addresses
      • Blocks and tipsets
      • Consensus
      • Drand
      • Proofs
    • Assets
      • The FIL token
      • Wallets
      • Metamask setup
      • Get FIL
      • Transfer FIL
    • Interplanetary consensus
    • How storage works
      • Filecoin plus
      • Storage onramps
      • Filecoin and IPFS
    • How retrieval works
      • Basic retrieval
      • Serving retrievals
      • Saturn
    • Project and community
      • Forums and FIPs
      • Filecoin compared to
      • Filecoin FAQs
      • Related projects
      • Social media
      • The Filecoin project
      • Ways to contribute
  • Storage providers
    • Basics
      • Quickstart guide
    • Filecoin economics
      • Storage proving
      • FIL collateral
      • Block rewards
      • Slashing
      • Committed capacity
    • Filecoin deals
      • Storage deals
      • Verified deals
      • Filecoin programs and tools
      • Snap deals
      • Charging for data
      • Auxiliary services
      • Return-on-investment
    • Architecture
      • Software components
      • Storage provider automation
      • Sealing pipeline
      • Sealing rate
      • Sealing-as-a-service
      • Network indexer
    • Infrastructure
      • Storage
      • Network
      • Backup and disaster recovery
      • Reference architectures
    • Skills
      • Linux
      • Network
      • Security
      • Storage
      • Sales
      • Industry
    • PDP
      • Prerequisites
      • Install & Run Lotus
      • Install & Run YugabyteDB
      • Install & Run Curio
      • Enable PDP
      • Use PDP
  • Nodes
    • Implementations
      • Lotus
      • Venus
    • Full-nodes
      • Pre-requisites
      • Basic setup
      • Node providers
    • Lite-nodes
      • Spin up a lite-node
  • Smart contracts
    • Fundamentals
      • The Filecoin Virtual Machine
      • Filecoin EVM runtime
      • ERC-20 quickstart
      • Roadmap
      • Support
      • FAQs
    • Filecoin EVM-runtime
      • Actor types
      • Address types
      • FILForwarder
      • Difference with Ethereum
      • How gas works
      • Precompiles
    • Programmatic storage
      • Aggregated deal-making
      • Direct deal-making
      • Cross-Chain Data Bridge(CCDB)
      • Data replication, renewal and repair (RaaS)
      • RaaS interfaces
    • Developing contracts
      • Get test tokens
      • Remix
      • Hardhat
      • Foundry
      • Solidity libraries
      • Call built-in actors
      • Filecoin.sol
      • Direct deal-making with Client contract
      • Using RaaS
      • Verify a contract
      • Best practices
    • Advanced
      • Wrapped FIL
      • Oracles
      • Multicall
      • Multisig
      • FEVM Indexers
      • Cross-chain bridges
      • Aggregated deal-making
      • Contract automation
      • Relay
  • Networks
    • Mainnet
      • Explorers
      • RPCs
      • Network performance
    • Calibration
      • Explorers
      • RPCs
    • Local testnet
      • Get test tokens
    • Deprecated networks
  • Reference
    • General
      • Glossary
      • Specifications
      • Tools
    • Exchanges
      • Exchange integration
    • Built-in actors
      • Protocol API
      • Filecoin.sol
    • JSON-RPC
      • Auth
      • Chain
      • Client
      • Create
      • Eth
      • Gas
      • I
      • Log
      • Market
      • Miner
      • Mpool
      • Msig
      • Net
      • Node
      • Paych
      • Raft
      • Start
      • State
      • Sync
      • Wallet
      • Web3
  • Builder Cookbook
    • Overview
    • Table of Contents
    • Data Storage
      • Store Data
      • Retrieve Data
      • Privacy & Access Control
    • dApps
      • Chain-Data Query
      • Oracles
      • Cross-Chain Bridges
      • Decentralized Database
Powered by GitBook
LogoLogo

Basics

  • Overview
  • Crypto-economics
  • Storage model
  • Reference

Developers

  • The FVM
  • EVM-runtime
  • Quickstart
  • Transfer FIL

Contact

  • GitHub
  • Slack
  • Twitter
On this page
  • Multicall3
  • Contract address
  • Usage
  • Hints

Was this helpful?

Edit on GitHub
Export as PDF
  1. Smart contracts
  2. Advanced

Multicall

Multicall allows you to aggregate multiple contract reads into a single JSON-RPC request, and execute multiple state-changing calls in a single transaction on the FVM.

PreviousOraclesNextMultisig

Last updated 6 months ago

Was this helpful?

Multicall3

is a powerful tool that offers batch contract calls to smart contracts on the Filecoin Virtual Machine (FVM).

Multicall3 is deployed on over 100 chains at 0xcA11bde05977b3631167028862bE2a173976CA11. A sortable, searchable list of all chains it's deployed on can be found .

The can be downloaded or copied to the clipboard in various formats, including:

  • Solidity interface.

  • JSON ABI, prettified.

  • JSON ABI, minified.

  • human readable ABI.

  • human readable ABI.

Alternatively, you can:

  • Download the ABI from the page.

  • Copy the ABI from .

  • Install and run cast interface 0xcA11bde05977b3631167028862bE2a173976CA11.

Contract address

Multicall has the same, precomputed address for all of the networks it is deployed on.

Name
Address
Mainnet
Calibration

0xcA11bde05977b3631167028862bE2a173976CA11

✔️

❌

0xcA11bde05977b3631167028862bE2a173976CA11

❌

✔️

Usage

To use Multicall3 to send batch contract read/write to your smart contract, you will need to:

  1. Obtain the Multicall3 contract address for the network you're using (Filecoin mainnet or Calibration testnet).

  2. Get the Multicall3 ABI, which can be downloaded or copied from various sources mentioned above.

  3. Create an instance of the Multicall3 contract using a web3 library like ethers.js or viem.

  4. Prepare your batch calls, including the target contract addresses, function selectors, and input data.

  5. Use the appropriate Multicall3 method (e.g., aggregate3 for multiple calls) to execute your batch operations.

  6. Process the returned data from the Multicall3 contract.

The steps above differ slightly for integrations using smart contracts, where steps 2 and 3 are replaced with:

  1. Import the Multicall3 interface in your smart contract.

  2. Create a function that interacts with the Multicall3 contract using the imported interface.

Batching Contract Reads

Batching contract reads, one of the most common use cases, allows a single eth_call JSON RPC request to return the results of multiple contract function calls. It has many benefits:

  1. Reduced JSON RPC Requests: Multicall reduces the number of separate JSON RPC requests that need to be sent. This is particularly useful when using remote nodes, such as GLIF. By aggregating multiple contract reads into a single JSON-RPC request, Multicall (1) reduces RPC usage and therefore costs, and (2) reduces the number of round trips between the client and the node, which can significantly improve performance

  2. Consistent Data from the Same Block: Multicall guarantees that all values returned are from the same block. This ensures data consistency and reliability, as all the read operations are performed on the same state of the blockchain.

  3. Detection of Stale Data: Multicall enables the block number or timestamp to be returned with the read data. This feature helps in detecting stale data, as developers can compare the block number or timestamp with the current state of the blockchain to ensure the data is up-to-date.

When directly interacting with the Multicall3 contract to batch calls, you'll typically use the aggregate3 method. This method allows you to execute multiple contract calls in a single transaction. Here's an explanation of how it works, along with examples:

  1. Solidity Implementation: The aggregate3 method is implemented in the Multicall3 contract like this:

    function aggregate3(Call3[] calldata calls) public payable returns (Result[] memory returnData) {
        uint256 length = calls.length;
        returnData = new Result[](length);
        for (uint256 i = 0; i < length;) {
            (bool success, bytes memory ret) = calls[i].target.call(calls[i].callData);
            if (calls[i].allowFailure) {
                returnData[i] = Result(success, ret);
            } else {
                require(success, "Multicall3: call failed");
                returnData[i] = Result(true, ret);
            }
            unchecked { ++i; }
        }
    }
  2. Example of sending multicalls to this smart contract: Here's an example using ethers.js to interact with the Multicall3 contract:

    const { ethers } = require("ethers");
    
    const provider = new ethers.providers.JsonRpcProvider("https://api.node.glif.io/rpc/v1");
    const multicallAddress = "0xcA11bde05977b3631167028862bE2a173976CA11";
    const multicallAbi = [/* Multicall3 ABI */];
    const multicall = new ethers.Contract(multicallAddress, multicallAbi, provider);
    
    // Example: Batch balance checks for multiple addresses
    async function batchBalanceChecks(addresses) {
      const calls = addresses.map(address => ({
        target: "0x...", // ERC20 token address
        allowFailure: false,
        callData: ethers.utils.id("balanceOf(address)").slice(0, 10) + 
                  ethers.utils.defaultAbiCoder.encode(["address"], [address]).slice(2)
      }));
    
      const results = await multicall.aggregate3(calls);
      return results.map(result => ethers.utils.defaultAbiCoder.decode(["uint256"], result.returnData)[0]);
    }
    
    batchBalanceChecks(["0x123...", "0x456...", "0x789..."]).then(console.log);

This example demonstrates how to use Multicall3 to batch multiple balanceOf calls for an ERC20 token in a single transaction, significantly reducing the number of separate RPC calls needed.

Batch Contract Writes

When using Multicall3, it's crucial to understand two key aspects: the behavior of msg.sender in calls versus delegatecalls, and the risks associated with msg.value in multicalls.

In FVM, there are two types of accounts: Externally Owned Accounts (EOAs) controlled by private keys, and Contract Accounts controlled by code. The msg.sender value during contract execution depends on whether a CALL or DELEGATECALL opcode is used. CALL changes the execution context, while DELEGATECALL preserves it.

For EOAs, which can only use CALL, Multicall3's address becomes the msg.sender for subsequent calls. This limits its usefulness from EOAs to scenarios where msg.sender is irrelevant. However, contract wallets or other contracts can use either CALL or DELEGATECALL, with the latter preserving the original msg.sender.

Hints

Many libraries and tools such as , , and have native Multicall3 integration which can be used in your projects directly. To learn how to use Multicall3 with these tools, check out

Multicall3, while unaudited, can be safely used for batching on-chain writes when used correctly. As a stateless contract, it should never hold funds after a transaction ends, and users should never approve it to spend tokens.

The handling of msg.value in multicalls requires caution. Since msg.value doesn't change with delegatecalls, relying on it within a multicall can lead to security vulnerabilities. To learn more about this, see and .

Lotus FEVM RPC supports Ethereum batch transactions. The key difference between multicall and batch transactions is that multicall aggregates multiple RPC requests into a single call, while batch transactions are simply an array of transactions executed sequentially but sent in one request. For more details, please refer to the .

⚠️
Multicall3
here
multicall3 ABI
ethers.js
viem
releases
Etherscan
Foundry
ethers-rs
viem
ape
Multicall3 examples folder
here
here
Ethereum documentation
Was this page helpful?
Multicall - Mainnet
Multicall - Calibration