Skip to main content

Pypi_repo GitHub license GitHub stars Follow @twitter handle

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. However, multicall.py is built on asyncio and does not support multi-threading. 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 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

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

Metadata

Release files for w3multicall 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for w3multicall 0.3.1
File Size Uploaded
w3multicall-0.3.1.tar.gz 10.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for w3multicall 0.3.1
File Interpreter ABI Platform
w3multicall-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 20.3 kB

Release files / w3multicall-0.3.1.tar.gz

Download URL w3multicall-0.3.1.tar.gz
Size 10.6 kB
Tags Source
SHA-256 checksum
How to use checksums
24c7bf3aac8cb8f8c62dd555212b3b5e87d6e7cf9cc4b3f3769a819bb9c55846
BLAKE2b-256 checksum
How to use checksums
01fa54ef6aec03f1ed041f23dc685bebee448861c9f1a8435920235365da0678
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / w3multicall-0.3.1-py3-none-any.whl

Download URL w3multicall-0.3.1-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
04f95d6ee64c9b2ab3bc9d7a3b2bac4a717fe9f8523f5aba6e7550086efcdad2
BLAKE2b-256 checksum
How to use checksums
e086a0e4cbedb4a297d980355852ce73776c4cdfb2b7c1846bbf15fa356339b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page