Skip to main content

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.7.0.tar.gz (31.8 kB view details)

Uploaded Source

File details

Details for the file multicall_py-1.7.0.tar.gz.

File metadata

  • Download URL: multicall_py-1.7.0.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for multicall_py-1.7.0.tar.gz
Algorithm Hash digest
SHA256 5707627025bdbeeb89212eaa84399b503b26ea8fd9cd38b1e1f8d1bc00b75e74
MD5 2b5db8279934cc9dbc2fbe93e39eb899
BLAKE2b-256 cf3780974e1e6d6c0f264a5664415ab636ebe80cabf422e9f5329c003d3b7d03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page