multicall.py
python interface for makerdao's multicall and a port of multicall.js.
This fork supports multithreading/processing in dockerized env which breaks with original module, by disabling Async execution of w3 requests.
To enable threaded/parallel execution with docker set env variable ASYNC_W3=0.
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
- MULTICALL_PROCESSES: pass an integer > 1 to use multiprocessing for encoding args and decoding results. Default: 1, which executes all code in the main process.
- AIOHTTP_TIMEOUT: sets aiohttp timeout period in seconds for async calls to node. Default: 30
- ASYNC_W3: enables/disables web3 async execution, 0 = Disable, 1 = Enable.
test
export WEB3_INFURE_PROJECT_ID=<your_infura_id>
export PYTEST_NETWORK='mainnet'
poetry run python -m pytest
Metadata
Release files for multicall-thread-safe 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| multicall_thread_safe-0.1.5.tar.gz | 15.6 kB | Without provenance | Details for multicall_thread_safe-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| multicall_thread_safe-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for multicall_thread_safe-0.1.5-py3-none-any.whl |
Total release size: 31.4 kB
Release files / multicall_thread_safe-0.1.5.tar.gz
| Download URL | multicall_thread_safe-0.1.5.tar.gz |
|---|---|
| Size | 15.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f2d49aff8869d77caf5f28ce5825c3009b2c5ad625c3d351e6bbe14c6f9c2046
|
|
BLAKE2b-256 checksum How to use checksums |
8b880a7c3674ab7e24a3fe5d87d0849f042e441ef6c0794c6aed9ea4deaf07d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.15.0-58-generic
|
Release files / multicall_thread_safe-0.1.5-py3-none-any.whl
| Download URL | multicall_thread_safe-0.1.5-py3-none-any.whl |
|---|---|
| Size | 15.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9cf986de729ba054ab78b3f1f998744a31da31739eeb470466c486c2ac86668a
|
|
BLAKE2b-256 checksum How to use checksums |
a53b1a3e8fe727d178da7c68e5f6c094321d6ed072c5be9d9d201ff1a9250cba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.8.10 Linux/5.15.0-58-generic
|
Security for multicall-thread-safe 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.