Skip to content

multicall

multicall(provider, calls): Promise<MulticallResult[]>

Defined in: utils/multicall.ts:207

Batch multiple contract read calls into a single RPC request via Multicall3’s aggregate3.

Reduces the number of RPC round-trips from N to 1 when reading from multiple contracts (or multiple functions on the same contract).

Parameters

provider

MulticallProvider

An essential-eth provider (JsonRpcProvider, FallthroughProvider, etc.)

calls

MulticallCall[]

Array of calls to batch — each specifies a target address, ABI, function name, and optional args

Returns

Promise<MulticallResult[]>

Array of results in the same order as the input calls

Example

import { JsonRpcProvider, multicall } from 'essential-eth';
const provider = new JsonRpcProvider('https://free-eth-node.com/api/eth');
const results = await multicall(provider, [
{
target: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
abi: daiAbi,
functionName: 'balanceOf',
args: ['0x...'],
},
{
target: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
abi: daiAbi,
functionName: 'totalSupply',
},
]);
// results[0] = { success: true, data: 1000000000000000000n }
// results[1] = { success: true, data: 5000000000000000000000000n }