百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
E

ethereum-multicall

> 编程语言
开源

在 1 个 JSONRPC 请求中调用多个以太坊常量函数调用

382 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

在 1 个 JSONRPC 请求中调用多个以太坊常量函数调用

ethereum-multicall

ethereum-multicall is a lightweight library for interacting with the Multicall3 smart contract.

Multicall allows multiple smart contract constant function calls to be grouped into a single call and the results aggregated into a single result. This reduces the number of separate JSON RPC requests that need to be sent over the network if using a remote node like Infura, and provides the guarantee that all values returned are from the same block. The latest block number is also returned along with the aggregated results.

ethereum-multicall is fully written in typescript so has full compile time support. The motivation of this package was to expose a super simple and easy to understand interface for you to take the full benefits of the multicalls. Also to not being opinionated on how you use it, you can use it with web3, ethers or even pass in a custom nodeUrl and we do it for you. This package takes care of the decoding for you but at the same time if you dont want it to you can turn that part off.

Supports

The below networks are supported by default, and custom networks can be supported by providing your own instance of a deployed Multicall contract.

Chain Chain ID
Mainnet 1
Ropsten 3
Rinkeby 4
Görli 5
Optimism 10
Kovan 42
Matic 137
KovanOptimism 69
xDai 100
xDaiTestnet 10200
GoerliOptimism 420
SepoliaOptimism 11155420
Arbitrum 42161
RinkebyArbitrum 421611
GoerliArbitrum 421613
SepoliaArbitrum 421614
Mumbai 80001
Sepolia 11155111
AvalancheMainnet 43114
AvalancheFuji 43113
FantomTestnet 4002
Fantom 250
BSC 56
BSC_Testnet 97
Moonbeam 1284
Moonriver 1285
MoonbaseAlphaTestnet 1287
Harmony 1666600000
Cronos 25
Fuse 122
SongbirdCanaryNetwork 19
CostonTestnet 16
Boba 288
Aurora 1313161554
Astar 592
OKC 66
Heco 128
Metis 1088
RSK 30
RSKTestnet 31
Evmos 9001
EvmosTestnet 9000
Thundercore 108
ThundercoreTestnet 18
Oasis 26863
Celo 42220
Godwoken 71402
GodwokenTestnet 71401
Klatyn 8217
Milkomeda 2001
KCC 321
Etherlite 111
Linea Testnet 59140
Linea 59144
Scroll 534352
Scroll Sepolia 534531
zkSync Era 324
zkSync Era Testnet 280
zkSync Era Sepolia 300
Sei 1328
Shibarium 109
Mantle 5000
Mantle Testnet 5001
Base 8453
Base Testnet 84531
Blast Sepolia 168587773
PolygonZkEvm 1101
PolygonZkEvmTestnet 1442
Zora 7777777
Zora Testnet 999
Flare Mainnet 14
Pulsechain Mainnet 369
Starknet 300
Starknet Testnet 301
Blast 81457
Amoy 80002
Mode 34443
Mode Testnet 919
Manta Pacific Mainnet 169
Bob Mainnet 60808
Soneium 1868
Soneium Minato 1946

Installation

npm:

javascript
$ npm install ethereum-multicall

yarn:

javascript
$ yarn add ethereum-multicall

Usage

Overloaded methods

As the official docs mentions here:

Due to signature overloading, multiple functions can have the same name. The first function specified in the ABI will be bound to its name. To access overloaded functions, use the full typed signature of the functions (e.g. contract["foobar(address,uint256)"]).

So, when creating the contract call context, under the calls array property we should have that in mind and use the method signature rather than the method name. E.g.

…

Import examples:

JavaScript (ES3)

javascript
var ethereumMulticall = require('ethereum-multicall');

JavaScript (ES5 or ES6)

javascript
const ethereumMulticall = require('ethereum-multicall');

JavaScript (ES6) / TypeScript

javascript
import {
  Multicall,
  ContractCallResults,
  ContractCallContext,
} from 'ethereum-multicall';

ethers usage example

…

web3 usage example

…

specify call block number

The multicall instance call method has an optional second argument of type ContractCallOptions.

One of the options is the blockNumber, so you can choose the height where you want the data from.

It is compatible with both ethers and web3 providers.

…

passing extra context to the call

If you want to store any context or state so you don't need to look back over arrays once you got the result back. it can be stored in context within ContractCallContext.

…

try aggregate

By default if you dont turn tryAggregate to true if 1 eth_call fails in your multicall the whole result will throw. If you turn tryAggregate to true it means if 1 of your eth_call methods fail it still return you the rest of the results. It will still be in the same order as you expect but you have a success boolean to check if it passed or failed. Keep in mind that if using a custom multicall contract deployment, Multicall version 1's will not work. Use a Multicall2 deployment (contract can be found here).

…

custom jsonrpc provider usage example

…

Multicall contracts

by default it looks at your network from the provider you passed in and makes the contract address to the known multicall contract addresses 0xcA11bde05977b3631167028862bE2a173976CA11 this is deployed on every single network but etherlite which uses 0x21681750D7ddCB8d1240eD47338dC984f94AF2aC.

typescript

If you wanted this to point at a different multicall contract address just pass that in the options when creating the multicall instance, example:

```ts
const multicall = new Multicall({
  multicallCustomContractAddress: '0x5BA1e12693Dc8F9c48aAD8770482f4739bEeD696',
  // your rest of your config depending on the provider your using.
});

Issues

Please raise any issues in the below link.

https://github.com/joshstevens19/ethereum-multicall/issues

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言