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.2.tar.gz
(4.3 kB
view hashes)
Built Distribution
Close
Hashes for multicall3-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ae80683a1807b3cdf3be1404640fe202348c2abb02961409f1dad4542bf2049 |
|
MD5 | 3c8bb85719ff7d0c9670bf2aac825b02 |
|
BLAKE2b-256 | 4e8adec77a43be1d4dfe88b09564c0f89e1211e3e93ea034037690fbbbc42c08 |