Python 3 interface Mutlicall3 smart contract
Project description
multicall3.py
Python 3 interface for Multicall3.
Installation
Install via pip:
pip install multicall3
Install via pdm:
pdm add multicall3
Example
from multicall3 import Multicall3
from web3 import Web3, AsyncWeb3, AsyncHTTPProvider
import asyncio
ERC20_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] == 6
asyncio.run(main())
Contributing
Install pdm
using pipx:
pipx install pdm --python $(which python)
Install dependencies:
pdm install
Activate the virtualenv:
$(pdm venv activate)
Run the test:
pytest
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
multicall3-0.1.4.tar.gz
(4.7 kB
view details)
Built Distribution
File details
Details for the file multicall3-0.1.4.tar.gz
.
File metadata
- Download URL: multicall3-0.1.4.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.11.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26563b9296b913ba6122517ee45f8d1bf7ab15c3325f87f2f479610e51c5733b |
|
MD5 | 13ef73fc2a261709f705c47859fdd024 |
|
BLAKE2b-256 | f91b4304546a8f3560e217c939c2cf1d4e0ec86d1748b5ff12220e1ce73d4a5a |
File details
Details for the file multicall3-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: multicall3-0.1.4-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.11.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d30fdc7f6a08774c45033408b5bd406f0ad489625d79764014194cf8abd616b4 |
|
MD5 | 23a3382ec1460f36d14046850783d4c4 |
|
BLAKE2b-256 | 444db6927631de3f73e62e34fa7dc0a5626d13f9e93eab829c529fce875c29d5 |