w3multicall


Namew3multicall JSON
Version 0.3.0 PyPI version JSON
download
home_pagehttps://github.com/0rtis/w3multicall
SummaryPython interface and utilities for Solidity multicall contract
upload_time2023-06-14 12:41:53
maintainer
docs_urlNone
authorOrtis
requires_python>=3.8
licenseMIT License Copyright (c) 2022 Ortis (ortis@ortis.io) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords blockchain web3 etherum solidity
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
[![Pypi_repo](https://img.shields.io/pypi/v/w3multicall?style=flat-square)](https://pypi.org/project/w3multicall/)
[![GitHub license](https://img.shields.io/github/license/0rtis/w3multicall.svg?style=flat-square)](https://github.com/0rtis/w3multicall/blob/master/LICENSE)
[![GitHub stars](https://img.shields.io/github/stars/0rtis?style=flat-square)](https://github.com/0rtis)
[![Follow @twitter handle](https://img.shields.io/twitter/follow/Knockturn_io.svg?style=flat-square)](https://twitter.com/intent/follow?screen_name=Knockturn_io)


Install with `pip install w3multicall`

https://pypi.org/project/w3multicall/


**Want to support this project ? You can help us by:**
- Delegating AVAX to our Avalanche node **NodeID-4btZGj8TmrycK22kwgBK5wJEFighAFWiZ**
- Making a donation to **0xA68fBfa3E0c86D1f3fF071853df6DAe8753095E2**


*This software is derived from [multicall.py](https://github.com/banteg/multicall.py).
However, [multicall.py](https://github.com/banteg/multicall.py) is built on [asyncio](https://docs.python.org/3/library/asyncio.html) and
[does not support multi-threading](https://github.com/banteg/multicall.py/issues/77)*

This implementation fixes that.

# W3Multicall

## Build and install locally
From the root folder `w3multicall` do `pip install .` to build and install the package in the current python environment 

## Multicall Smart Contract
[Multicall](https://github.com/mds1/multicall) smart contract are deployed on numerous chains and can help reduce the strain
put on RPC by order of magnitude by *batching* multiple requests into a single one.

## Simple Multicall

```
from web3 import Web3
from w3multicall.multicall import W3Multicall

w3 = Web3(Web3.HTTPProvider(rpc))

w3_multicall = W3Multicall(w3)

w3_multicall.add(W3Multicall.Call(
    '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',  # USDC contract address
    'balanceOf(address)(uint256)',  # method signature to call
    '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')  # vitalik.eth
)

results = w3_multicall.call()

print("Vitalik holds {:.2f} USDC".format(results[0]/10**6))

```

[See full example](/examples/simple_multicall.py)

## Multithread Multicall

```
w3_pool = W3Pool([
        W3(Web3(Web3.HTTPProvider('https://eth-rpc.gateway.pokt.network')), 5),
        W3(Web3(Web3.HTTPProvider('https://ethereum.publicnode.com')), 5),
        W3(Web3(Web3.HTTPProvider('https://rpc.flashbots.net/')), 5)
    ], logger)

executor = W3MulticallExecutor(w3_pool, processes=len(w3_pool.w3s))

bayc_futures = []
azuki_futures = []
moonbird_futures = []
for i in range(1, 10):

    bayc_futures.append(executor.submit(W3Multicall.Call(
        '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',  # BAYC NFT contract address
        'ownerOf(uint256)(address)',
        i)))

    azuki_futures.append(executor.submit(W3Multicall.Call(
        '0xED5AF388653567Af2F388E6224dC7C4b3241C544',  # Azuki NFT contract address
        'ownerOf(uint256)(address)',
        i)))

    moonbird_futures.append(executor.submit(W3Multicall.Call(
        '0x23581767a106ae21c074b2276D25e5C3e136a68b',  # Moonbird NFT contract address
        'ownerOf(uint256)(address)',
        i)))        
    
for i in range(len(bayc_futures)):
    print("The owner of the BAYC Nº{} is {}".format(i + 1, bayc_futures[i].get()))

for i in range(len(azuki_futures)):
    print("The owner of the Azuki Nº{} is {}".format(i + 1, azuki_futures[i].get()))

for i in range(len(moonbird_futures)):
    print("The owner of the Moonbird Nº{} is {}".format(i + 1, moonbird_futures[i].get()))
```

[See full example](/examples/mutithread_multicall.py)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/0rtis/w3multicall",
    "name": "w3multicall",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "",
    "keywords": "blockchain,web3,etherum,solidity",
    "author": "Ortis",
    "author_email": "Ortis <ortis@ortis.io>",
    "download_url": "https://files.pythonhosted.org/packages/91/32/8b1efb149cfdc89954932f7a9a8f1840c125ab5703d4bc8a8bd6fbdd9133/w3multicall-0.3.0.tar.gz",
    "platform": null,
    "description": "\n[![Pypi_repo](https://img.shields.io/pypi/v/w3multicall?style=flat-square)](https://pypi.org/project/w3multicall/)\n[![GitHub license](https://img.shields.io/github/license/0rtis/w3multicall.svg?style=flat-square)](https://github.com/0rtis/w3multicall/blob/master/LICENSE)\n[![GitHub stars](https://img.shields.io/github/stars/0rtis?style=flat-square)](https://github.com/0rtis)\n[![Follow @twitter handle](https://img.shields.io/twitter/follow/Knockturn_io.svg?style=flat-square)](https://twitter.com/intent/follow?screen_name=Knockturn_io)\n\n\nInstall with `pip install w3multicall`\n\nhttps://pypi.org/project/w3multicall/\n\n\n**Want to support this project ? You can help us by:**\n- Delegating AVAX to our Avalanche node **NodeID-4btZGj8TmrycK22kwgBK5wJEFighAFWiZ**\n- Making a donation to **0xA68fBfa3E0c86D1f3fF071853df6DAe8753095E2**\n\n\n*This software is derived from [multicall.py](https://github.com/banteg/multicall.py).\nHowever, [multicall.py](https://github.com/banteg/multicall.py) is built on [asyncio](https://docs.python.org/3/library/asyncio.html) and\n[does not support multi-threading](https://github.com/banteg/multicall.py/issues/77)*\n\nThis implementation fixes that.\n\n# W3Multicall\n\n## Build and install locally\nFrom the root folder `w3multicall` do `pip install .` to build and install the package in the current python environment \n\n## Multicall Smart Contract\n[Multicall](https://github.com/mds1/multicall) smart contract are deployed on numerous chains and can help reduce the strain\nput on RPC by order of magnitude by *batching* multiple requests into a single one.\n\n## Simple Multicall\n\n```\nfrom web3 import Web3\nfrom w3multicall.multicall import W3Multicall\n\nw3 = Web3(Web3.HTTPProvider(rpc))\n\nw3_multicall = W3Multicall(w3)\n\nw3_multicall.add(W3Multicall.Call(\n    '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',  # USDC contract address\n    'balanceOf(address)(uint256)',  # method signature to call\n    '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045')  # vitalik.eth\n)\n\nresults = w3_multicall.call()\n\nprint(\"Vitalik holds {:.2f} USDC\".format(results[0]/10**6))\n\n```\n\n[See full example](/examples/simple_multicall.py)\n\n## Multithread Multicall\n\n```\nw3_pool = W3Pool([\n        W3(Web3(Web3.HTTPProvider('https://eth-rpc.gateway.pokt.network')), 5),\n        W3(Web3(Web3.HTTPProvider('https://ethereum.publicnode.com')), 5),\n        W3(Web3(Web3.HTTPProvider('https://rpc.flashbots.net/')), 5)\n    ], logger)\n\nexecutor = W3MulticallExecutor(w3_pool, processes=len(w3_pool.w3s))\n\nbayc_futures = []\nazuki_futures = []\nmoonbird_futures = []\nfor i in range(1, 10):\n\n    bayc_futures.append(executor.submit(W3Multicall.Call(\n        '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',  # BAYC NFT contract address\n        'ownerOf(uint256)(address)',\n        i)))\n\n    azuki_futures.append(executor.submit(W3Multicall.Call(\n        '0xED5AF388653567Af2F388E6224dC7C4b3241C544',  # Azuki NFT contract address\n        'ownerOf(uint256)(address)',\n        i)))\n\n    moonbird_futures.append(executor.submit(W3Multicall.Call(\n        '0x23581767a106ae21c074b2276D25e5C3e136a68b',  # Moonbird NFT contract address\n        'ownerOf(uint256)(address)',\n        i)))        \n    \nfor i in range(len(bayc_futures)):\n    print(\"The owner of the BAYC N\u00ba{} is {}\".format(i + 1, bayc_futures[i].get()))\n\nfor i in range(len(azuki_futures)):\n    print(\"The owner of the Azuki N\u00ba{} is {}\".format(i + 1, azuki_futures[i].get()))\n\nfor i in range(len(moonbird_futures)):\n    print(\"The owner of the Moonbird N\u00ba{} is {}\".format(i + 1, moonbird_futures[i].get()))\n```\n\n[See full example](/examples/mutithread_multicall.py)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2022 Ortis (ortis@ortis.io)  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Python interface and utilities for Solidity multicall contract",
    "version": "0.3.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/0rtis/w3multicall/issues",
        "Homepage": "https://github.com/0rtis/w3multicall"
    },
    "split_keywords": [
        "blockchain",
        "web3",
        "etherum",
        "solidity"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "81945d5a11525386e213a09222dae80b9c1496ff8a3d084fce7c164687c9dacc",
                "md5": "163c3c8c86ecbde7b34c322966c4b85f",
                "sha256": "e787533ba880ad71187c0dcfc4f029433b11e43e0ce0dbd3ca334fdf56de1eb9"
            },
            "downloads": -1,
            "filename": "w3multicall-0.3.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "163c3c8c86ecbde7b34c322966c4b85f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 9623,
            "upload_time": "2023-06-14T12:41:51",
            "upload_time_iso_8601": "2023-06-14T12:41:51.436330Z",
            "url": "https://files.pythonhosted.org/packages/81/94/5d5a11525386e213a09222dae80b9c1496ff8a3d084fce7c164687c9dacc/w3multicall-0.3.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "91328b1efb149cfdc89954932f7a9a8f1840c125ab5703d4bc8a8bd6fbdd9133",
                "md5": "ac08f913296883522a0606d10e4ce456",
                "sha256": "088d61b6881550c0cb24798b075a82b6c205bbecdd4bd38452f530356bcb43e7"
            },
            "downloads": -1,
            "filename": "w3multicall-0.3.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ac08f913296883522a0606d10e4ce456",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 10550,
            "upload_time": "2023-06-14T12:41:53",
            "upload_time_iso_8601": "2023-06-14T12:41:53.364650Z",
            "url": "https://files.pythonhosted.org/packages/91/32/8b1efb149cfdc89954932f7a9a8f1840c125ab5703d4bc8a8bd6fbdd9133/w3multicall-0.3.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-14 12:41:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "0rtis",
    "github_project": "w3multicall",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "w3multicall"
}
        
Elapsed time: 0.08019s