Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pyk/multicall3.py
Python 3 interface for Multicall3
https://github.com/pyk/multicall3.py
ethereum multicall
Last synced: 22 days ago
JSON representation
Python 3 interface for Multicall3
- Host: GitHub
- URL: https://github.com/pyk/multicall3.py
- Owner: pyk
- Created: 2024-01-17T17:28:06.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-01-19T08:02:50.000Z (10 months ago)
- Last Synced: 2024-04-11T18:19:56.784Z (7 months ago)
- Topics: ethereum, multicall
- Language: Python
- Homepage: https://www.multicall3.com/
- Size: 78.1 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# multicall3.py
Python 3 interface for [Multicall3](https://www.multicall3.com/).
## Installation
Install via pip:
```shell
pip install multicall3
```Install via [pdm](https://pdm-project.org/):
```shell
pdm add multicall3
```## Example
```python
from multicall3 import Multicall3
from web3 import Web3, AsyncWeb3, AsyncHTTPProvider
import asyncioERC20_ABI = [
{
"constant": True,
"inputs": [],
"name": "name",
"outputs": [{"name": "", "type": "string"}],
"payable": False,
"stateMutability": "view",
"type": "function",
},
{
"constant": True,
"inputs": [],
"name": "decimals",
"outputs": [{"name": "", "type": "uint8"}],
"payable": False,
"stateMutability": "view",
"type": "function",
},
{
"constant": True,
"inputs": [],
"name": "symbol",
"outputs": [{"name": "", "type": "string"}],
"payable": False,
"stateMutability": "view",
"type": "function",
}
]async def main():
w3 = AsyncWeb3(AsyncHTTPProvider("https://ethereum.publicnode.com"))
multicall3 = Multicall3(w3=w3)
usdc_contract = w3.eth.contract(
address=Web3.to_checksum_address("0xA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48"),
abi=ERC20_ABI,
)results = await multicall3.aggregate3(
usdc_contract.functions.name(),
usdc_contract.functions.symbol(),
usdc_contract.functions.decimals(),
)
assert results[0] == "USD Coin"
assert results[1] == "USDC"
assert results[2] == 6asyncio.run(main())
```## Contributing
Install `pdm` using [pipx](https://github.com/pypa/pipx):
```shell
pipx install pdm --python $(which python)
```Install dependencies:
```shell
pdm install
```Activate the virtualenv:
```shell
$(pdm venv activate)
```Run the test:
```shell
pytest
```