banteg/multicall.py
banteg/multicall.py has 273 GitHub stars and 111 forks. GitHot measured 0 stars in 24 hours and 0 in 7 days. Last checked 2026-11-24 02:03 UTC. Last push 2026-08-14.
实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 正在收集历史
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
关于
aggregate results of multiple smart contract calls into one
开发工具README.md
原文multicall.py
python interface for makerdao's multicall and a port of multicall.js
installation
pip install multicall
example
from multicall import Call, Multicall
# assuming you are on kovan
MKR_TOKEN = '0xaaf64bfcc32d0f15873a02163e7e500671a4ffcd'
MKR_WHALE = '0xdb33dfd3d61308c33c63209845dad3e6bfb2c674'
MKR_FISH = '0x2dfcedcb401557354d0cf174876ab17bfd6f4efd'
def from_wei(value):
return value / 1e18
multi = Multicall([
Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE], [('whale', from_wei)]),
Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_FISH], [('fish', from_wei)]),
Call(MKR_TOKEN, 'totalSupply()(uint256)', [('supply', from_wei)]),
])
multi() # {'whale': 566437.0921992733, 'fish': 7005.0, 'supply': 1000003.1220798912}
# seth-style calls
Call(MKR_TOKEN, ['balanceOf(address)(uint256)', MKR_WHALE])()
Call(MKR_TOKEN, 'balanceOf(address)(uint256)')(MKR_WHALE)
# return values processing
Call(MKR_TOKEN, 'totalSupply()(uint256)', [('supply', from_wei)])()
for a full example, see implementation of daistats. original daistats.com made by nanexcool.
api
Signature(signature)
signatureis a seth-style function signature offunction_name(input,types)(output,types). it also supports structs which need to be broken down to basic parts, e.g.(address,bytes)[].
use encode_data(args) with input args to get the calldata. use decode_data(output) with the output to decode the result.
Call(target, function, returns)
targetis thetoaddress which is supplied toeth_call.functioncan be either seth-style signature ofmethod(input,types)(output,types)or a list of[signature, *args].returnsis a list of tuples of(name, handler)for return values. ifreturnsargument is omitted, you get a tuple, otherwise you get a dict. to skip processing of a value, passNoneas a handler.
use Call(...)() with predefined args or Call(...)(args) to reuse a prepared call with different args.
use decode_output(output) with to decode the output and process it with returns handlers.
Multicall(calls)
callsis a list of calls with prepared values.
use Multicall(...)() to get the result of a prepared multicall.
Environment Variables
- GAS_LIMIT: sets overridable default gas limit for Multicall to prevent out of gas errors. Default: 50,000,000
- MULTICALL_DEBUG: if set, sets logging level for all library loggers to logging.DEBUG
- AIOHTTP_TIMEOUT: sets aiohttp timeout period in seconds for async calls to node. Default: 30
test
export WEB3_INFURE_PROJECT_ID=<your_infura_id>
export PYTEST_NETWORK='mainnet'
poetry run python -m pytest
探索相关项目
加载中…