Ethereum multiple contract/rpc calls
Project description
Multicall
fork from https://github.com/banteg/multicall.py, but implements the multicall in client's side.
Install
pip install multicall-py
Example
from decimal import Decimal
from multicall import Multicall, Call
mc = Multicall("https://mainnet.infura.io/v3/xyz")
def from_wad(value):
return Decimal(value) / 10 ** 18
def from_ray(value):
return Decimal(value) / 10 ** 27
def from_rad(value):
return Decimal(value) / 10 ** 45
def from_ilk(values):
print(values)
return {
"Art": from_wad(values[0]),
"rate": from_ray(values[1]),
"spot": from_ray(values[2]),
"line": from_rad(values[3]),
"dust": from_rad(values[4]),
}
result = mc.aggrate(
[
Call(
target="0xdac17f958d2ee523a2206206994597c13d831ec7",
function="balanceOf(address)(uint256)",
args=("0xa929022c9107643515f5c777ce9a910f0d1e490c",),
returns=[],
),
Call(
target="0xdac17f958d2ee523a2206206994597c13d831ec7",
function="balanceOf(address)(uint256)",
args=("0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503",),
request_id="0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503",
),
Call(
"0x35d1b3f3d7966a1dfe207aa4514c12a259a0492b",
"ilks(bytes32)((uint256,uint256,uint256,uint256,uint256))",
args=[b"ETH-A"],
request_id="ETH-A",
returns=[
["Art", from_wad],
["rate", from_ray],
["spot", from_ray],
["line", from_rad],
["dust", None],
],
),
]
)
print(result)
response as below:
[{'request_id': '5a7bd54c680592746135b37a6476eb6c',
'result': 1701108488000000},
{'request_id': '0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503',
'result': 1350000115495224},
{'request_id': 'ETH-A',
'Art': Decimal('2789424592.115625600914086111'),
'rate': Decimal('1.059237159709500809006237604'),
'spot': Decimal('3001.379310344827586206896552'),
'line': Decimal('3090847838.001970634131021155'),
'dust': 10000000000000000000000000000000000000000000000000}]
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
multicall-py-1.3.4.tar.gz
(22.7 kB
view details)
File details
Details for the file multicall-py-1.3.4.tar.gz
.
File metadata
- Download URL: multicall-py-1.3.4.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaa3a64e91277f89d094b3b654db1251c5d47e394018547f37e2ab62d9696e50 |
|
MD5 | 27abffe3f646a03511ce13edd7979835 |
|
BLAKE2b-256 | da88e285e82bd7110f0ccb7709ec270ee2c32058db00371f2448ad4382176447 |