multicall-py


Namemulticall-py JSON
Version 1.3.4 PyPI version JSON
download
home_pagehttps://github.com/jsvisa/multicall.py
SummaryEthereum multiple contract/rpc calls
upload_time2024-04-29 00:53:17
maintainerNone
docs_urlNone
authorWenbiao Zheng
requires_python>=3.6
licenseMIT
keywords ethereum jsonrpc contract multicall
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Multicall

fork from https://github.com/banteg/multicall.py, but implements the multicall in client's side.

## Install

```bash
pip install multicall-py
```

## Example

```python

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:

```python
[{'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}]
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jsvisa/multicall.py",
    "name": "multicall-py",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "ethereum jsonrpc contract multicall",
    "author": "Wenbiao Zheng",
    "author_email": "delweng@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/da/88/e285e82bd7110f0ccb7709ec270ee2c32058db00371f2448ad4382176447/multicall-py-1.3.4.tar.gz",
    "platform": null,
    "description": "# Multicall\n\nfork from https://github.com/banteg/multicall.py, but implements the multicall in client's side.\n\n## Install\n\n```bash\npip install multicall-py\n```\n\n## Example\n\n```python\n\nfrom decimal import Decimal\nfrom multicall import Multicall, Call\n\nmc = Multicall(\"https://mainnet.infura.io/v3/xyz\")\n\ndef from_wad(value):\n    return Decimal(value) / 10 ** 18\n\n\ndef from_ray(value):\n    return Decimal(value) / 10 ** 27\n\n\ndef from_rad(value):\n    return Decimal(value) / 10 ** 45\n\n\ndef from_ilk(values):\n    print(values)\n    return {\n        \"Art\": from_wad(values[0]),\n        \"rate\": from_ray(values[1]),\n        \"spot\": from_ray(values[2]),\n        \"line\": from_rad(values[3]),\n        \"dust\": from_rad(values[4]),\n    }\n\n\nresult = mc.aggrate(\n    [\n        Call(\n            target=\"0xdac17f958d2ee523a2206206994597c13d831ec7\",\n            function=\"balanceOf(address)(uint256)\",\n            args=(\"0xa929022c9107643515f5c777ce9a910f0d1e490c\",),\n            returns=[],\n        ),\n        Call(\n            target=\"0xdac17f958d2ee523a2206206994597c13d831ec7\",\n            function=\"balanceOf(address)(uint256)\",\n            args=(\"0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503\",),\n            request_id=\"0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503\",\n        ),\n        Call(\n            \"0x35d1b3f3d7966a1dfe207aa4514c12a259a0492b\",\n            \"ilks(bytes32)((uint256,uint256,uint256,uint256,uint256))\",\n            args=[b\"ETH-A\"],\n            request_id=\"ETH-A\",\n            returns=[\n                [\"Art\", from_wad],\n                [\"rate\", from_ray],\n                [\"spot\", from_ray],\n                [\"line\", from_rad],\n                [\"dust\", None],\n            ],\n        ),\n    ]\n)\n\nprint(result)\n```\n\n> response as below:\n\n```python\n[{'request_id': '5a7bd54c680592746135b37a6476eb6c',\n  'result': 1701108488000000},\n {'request_id': '0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503',\n  'result': 1350000115495224},\n {'request_id': 'ETH-A',\n  'Art': Decimal('2789424592.115625600914086111'),\n  'rate': Decimal('1.059237159709500809006237604'),\n  'spot': Decimal('3001.379310344827586206896552'),\n  'line': Decimal('3090847838.001970634131021155'),\n  'dust': 10000000000000000000000000000000000000000000000000}]\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Ethereum multiple contract/rpc calls",
    "version": "1.3.4",
    "project_urls": {
        "Homepage": "https://github.com/jsvisa/multicall.py"
    },
    "split_keywords": [
        "ethereum",
        "jsonrpc",
        "contract",
        "multicall"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "da88e285e82bd7110f0ccb7709ec270ee2c32058db00371f2448ad4382176447",
                "md5": "27abffe3f646a03511ce13edd7979835",
                "sha256": "eaa3a64e91277f89d094b3b654db1251c5d47e394018547f37e2ab62d9696e50"
            },
            "downloads": -1,
            "filename": "multicall-py-1.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "27abffe3f646a03511ce13edd7979835",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 22731,
            "upload_time": "2024-04-29T00:53:17",
            "upload_time_iso_8601": "2024-04-29T00:53:17.164145Z",
            "url": "https://files.pythonhosted.org/packages/da/88/e285e82bd7110f0ccb7709ec270ee2c32058db00371f2448ad4382176447/multicall-py-1.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-29 00:53:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jsvisa",
    "github_project": "multicall.py",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "multicall-py"
}
        
Elapsed time: 0.20839s