> For the complete documentation index, see [llms.txt](https://docs.pepeunchained.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.pepeunchained.com/recipes/batch-reads-with-multicall3.md).

# Batch Reads with Multicall3

Read many values in one request. PEPU has Multicall3, but not at the canonical address, so this recipe uses the SDK to pin the right one.

PEPU's Multicall3 is `0x9CE19273Ae9c24437DFF512E8DFCAed4E4B001bd`. The canonical `0xcA11bde05977b3631167028862bE2a173976CA11` has no code on PEPU.

Read [The Multicall3 Trap](/contracts-and-addresses/multicall3.md) first if you have not.

## Prerequisites

`@pepu-chain/sdk` and `viem`.

## Steps

`pepuMulticall(client, calls, { allowFailure?, blockNumber? })` is viem's `multicall` pinned to PEPU's address. It goes through `getMulticall3`, which throws `MULTICALL3_CANONICAL_ADDRESS` rather than ever use the canonical one.

```ts
// Batch reads through PEPU's own Multicall3. See docs/recipes/batch-reads-with-multicall3.md
import { erc20Abi, getAddress } from "viem";
import { getPublicClient, pepuMainnet, pepuMulticall, pepuTokenList } from "@pepu-chain/sdk";

const client = getPublicClient(pepuMainnet);

export async function readTokens(holder: `0x${string}`) {
  const tokens = pepuTokenList.tokens.map((t) => getAddress(t.address));

  // pepuMulticall pins the Multicall3 address; the canonical one has no code on PEPU.
  const results = await pepuMulticall(
    client,
    tokens.flatMap(
      (address) =>
        [
          { address, abi: erc20Abi, functionName: "symbol" },
          { address, abi: erc20Abi, functionName: "balanceOf", args: [holder] },
        ] as const,
    ),
    { allowFailure: true },
  );

  return results.map((r) => (r.status === "success" ? r.result : null));
}
```

Source: `docs/snippets/multicall-batch-reads.ts`, type-checked against the SDK.

Plain viem works too, because `pepuMainnet.contracts.multicall3` already holds PEPU's address: `client.multicall({ contracts })` on a client from `getPublicClient(pepuMainnet)` batches correctly. Use `pepuMulticall` when you want the guard.

In React with wagmi see [Batch Reads with Multicall3 in React](/recipes/multicall-in-react.md).

### Calling `aggregate3` yourself

For per-call failure control, `encodeAggregate3(calls)` and `decodeAggregate3Result(data)` wrap the `aggregate3` ABI. The contract is a normal Multicall3 deployment; only the address differs from other chains.

### Without the SDK

Set `contracts.multicall3` explicitly in your chain definition, with `address: "0x9CE19273Ae9c24437DFF512E8DFCAed4E4B001bd"` and `blockCreated: 10521048`. Never substitute the canonical address.

## What to expect

* One RPC round trip for all calls. Results are in order, each with a `status`.
* With `allowFailure: false` a failing call rejects the whole batch.

## Common failures

| Symptom                                | Cause                                         | Fix                                     |
| -------------------------------------- | --------------------------------------------- | --------------------------------------- |
| Every batched call fails               | Routed through the canonical address          | Use `pepuMainnet` or `pepuMulticall`    |
| `MULTICALL3_CANONICAL_ADDRESS`         | The canonical address reached `getMulticall3` | Use the registry entry, never a literal |
| `UNKNOWN` "Multicall3 is not deployed" | A non-mainnet chain ID                        | Use chain 97741                         |

## Related

* [The Multicall3 Trap](/contracts-and-addresses/multicall3.md)
* [Batch Reads with Multicall3 in React](/recipes/multicall-in-react.md)
* [Gate Content by Token Balance](/recipes/gate-content-by-token-balance.md)
* [Core](/sdk/core.md#multicall3-and-permit2)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.pepeunchained.com/recipes/batch-reads-with-multicall3.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
