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

Uploaded Source

File details

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

File metadata

  • Download URL: multicall_py-1.5.1.tar.gz
  • Upload date:
  • Size: 42.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.7

File hashes

Hashes for multicall_py-1.5.1.tar.gz
Algorithm Hash digest
SHA256 16edab1a18cc2ffdc03eadb22c2fc88ab287ef5738f971d04d71c4b551916085
MD5 3fbeb62a54ad62bdabea4b43167003cd
BLAKE2b-256 e0a9dba3ee384adb261ec932fe27cff3cde76756fbf82a6fe54b90eaf2825cf7

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