Skip to main content

Multicallable: Simplified Interface for Multicall

Multicallable provides a streamlined way to work with the Multicall package, allowing you to batch multiple contract calls into a single request.

Installation

Install the package using the following command:

pip install -U multicallable

Getting Started

Initialize Web3 or AsyncWeb3

First, import the Web3 library and set up a Web3 instance. The setup differs depending on whether you are using synchronous or asynchronous operations.

For synchronous operations:

from web3 import Web3

# Specify Ethereum RPC URL
ETH_RPC_URL = 'https://rpc.ankr.com/eth'

# Initialize Web3 instance
w3 = Web3(Web3.HTTPProvider(ETH_RPC_URL))

For asynchronous operations:

from web3 import AsyncWeb3

# Initialize AsyncWeb3 instance
w3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider(ETH_RPC_URL))

Import and Initialize Multicallable

Next, import the Multicallable class and initialize it for a specific token:

from multicallable import Multicallable

# Truncated ERC20 ABI for demonstration
ERC20_ABI = '[{"constant":true,"inputs":[],"name":"name", ...'

# sample token contract address
TOKEN = '0xDE5ed76E7c05eC5e4572CfC88d1ACEA165109E44'

# Initialize Multicallable instance
multicallable = Multicallable(TOKEN, ERC20_ABI, w3)

AsyncMulticallable: The Asynchronous Alternative

For asynchronous use-cases, AsyncMulticallable is available. Unlike Multicallable, its constructor is empty, and it includes an asynchronous setup function that takes the same parameters:

from multicallable import AsyncMulticallable

# Initialize AsyncMulticallable instance
async_multicallable = AsyncMulticallable()
await async_multicallable.setup(TOKEN, ERC20_ABI, w3)  # Make sure w3 is an AsyncWeb3 instance

Basic Operations

Querying Multiple Balances

For synchronous operations:

addresses = [
    # List of addresses
]
balances = multicallable.balanceOf(addresses).call()

For asynchronous operations:

addresses = [
    # List of addresses
]
balances = await async_multicallable.balanceOf(addresses).call()

Detailed Call Information

For synchronous operations:

detailed_info = multicallable.balanceOf(addresses).detailed_call()

For asynchronous operations:

detailed_info = await async_multicallable.balanceOf(addresses).detailed_call()

Advanced Features

Handling Failed Calls

By default, all calls must succeed for the batch call to return successfully. Use require_success=False to allow partial success:

mc = Multicallable(contract_address, contract_abi, w3)
partial_result = mc.getNum(list(range(7))).call(require_success=False)

Batching Large Number of Calls

For large number of calls, you can specify the number of buckets using the n parameter:

result = mc.getNum(list(range(70000))).call(require_success=False, n=100)

Progress Indicator

Enable a progress bar for better visibility into the batch processing:

result = mc.getNum(list(range(70000))).call(n=100, progress_bar=True, require_success=False)

Custom Multicall Instance

You can also use a custom Multicall instance with a custom address and ABI:

from multicallable.multicall import Multicall

multicall = Multicall(w3, custom_address, custom_abi)
mc = Multicallable(contract_address, contract_abi, multicall=multicall)

Authors

Release files for multicallable 7.2.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 multicallable 7.2.1
File Size Uploaded
multicallable-7.2.1.tar.gz 13.3 kB Details

Built distribution (wheel)

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

Total release size: 28.6 kB

Release files / multicallable-7.2.1.tar.gz

Download URL multicallable-7.2.1.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
36d7d36990118202ab3fd94a098c4c61a1c7e4453a22cb9ec12032d04277482d
BLAKE2b-256 checksum
How to use checksums
52edab5df29ef4e424e713c0c85a055497fe25ef78ff8b4fd5915642bc44895d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release files / multicallable-7.2.1-py3-none-any.whl

Download URL multicallable-7.2.1-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cea81ae0398ba1c6238eb643d53901a12df9337fb755334c7cc6330050ff91c1
BLAKE2b-256 checksum
How to use checksums
cea33bf0824319d8221bf044782e19223c3cec3f8811d57f1f1d52ef0aad0fe0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

7.2.1 This release

2 release files

7.2.0

2 release files

7.1.0

2 release files

7.0.0

2 release files

6.0.4

2 release files

6.0.3

2 release files

6.0.2

2 release files

6.0.1

2 release files

6.0.0

2 release files

5.1.3

2 release files

5.1.2

2 release files

5.1.1

2 release files

5.1.0

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.0.0

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