## 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:
```shell
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:
```python
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:
```python
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:
```python
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:
```python
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:
```python
addresses = [
# List of addresses
]
balances = multicallable.balanceOf(addresses).call()
```
For asynchronous operations:
```python
addresses = [
# List of addresses
]
balances = await async_multicallable.balanceOf(addresses).call()
```
#### Detailed Call Information
For synchronous operations:
```python
detailed_info = multicallable.balanceOf(addresses).detailed_call()
```
For asynchronous operations:
```python
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:
```python
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:
```python
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:
```python
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:
```python
from multicallable.multicall import Multicall
multicall = Multicall(w3, custom_address, custom_abi)
mc = Multicallable(contract_address, contract_abi, multicall=multicall)
```
## Authors
- **[MiKO](https://github.com/MiKoronjoo)** - *Initial work*
- **[Naveed](https://github.com/Navid-Fkh)** - *Contributor*
Raw data
{
"_id": null,
"home_page": "https://github.com/deusfinance/multicallable",
"name": "multicallable",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.8.0",
"maintainer_email": null,
"keywords": null,
"author": "MiKO, Naveed",
"author_email": "mikoronjoo@gmail.com, naveedinno@proton.me",
"download_url": "https://files.pythonhosted.org/packages/09/f6/e5e47f05d3ff87d8067ef806dae6d58f1d7f551370a43f33908e1478ee35/multicallable-7.2.0.tar.gz",
"platform": null,
"description": "## Multicallable: Simplified Interface for Multicall\n\n`Multicallable` provides a streamlined way to work with the Multicall package, allowing you to batch multiple contract calls into a single request.\n\n### Installation\n\nInstall the package using the following command:\n\n```shell\npip install -U multicallable\n```\n\n### Getting Started\n\n#### Initialize Web3 or AsyncWeb3\n\nFirst, import the Web3 library and set up a Web3 instance. The setup differs depending on whether you are using synchronous or asynchronous operations.\n\nFor synchronous operations:\n\n```python\nfrom web3 import Web3\n\n# Specify Ethereum RPC URL\nETH_RPC_URL = 'https://rpc.ankr.com/eth'\n\n# Initialize Web3 instance\nw3 = Web3(Web3.HTTPProvider(ETH_RPC_URL))\n```\n\nFor asynchronous operations:\n\n```python\nfrom web3 import AsyncWeb3\n\n# Initialize AsyncWeb3 instance\nw3 = AsyncWeb3(AsyncWeb3.AsyncHTTPProvider(ETH_RPC_URL))\n```\n\n#### Import and Initialize Multicallable\n\nNext, import the `Multicallable` class and initialize it for a specific token:\n\n```python\nfrom multicallable import Multicallable\n\n# Truncated ERC20 ABI for demonstration\nERC20_ABI = '[{\"constant\":true,\"inputs\":[],\"name\":\"name\", ...'\n\n# sample token contract address\nTOKEN = '0xDE5ed76E7c05eC5e4572CfC88d1ACEA165109E44'\n\n# Initialize Multicallable instance\nmulticallable = Multicallable(TOKEN, ERC20_ABI, w3)\n```\n\n#### AsyncMulticallable: The Asynchronous Alternative\n\nFor asynchronous use-cases, `AsyncMulticallable` is available. Unlike `Multicallable`, its constructor is empty, and it includes an asynchronous `setup` function that takes the same parameters:\n\n```python\nfrom multicallable import AsyncMulticallable\n\n# Initialize AsyncMulticallable instance\nasync_multicallable = AsyncMulticallable()\nawait async_multicallable.setup(TOKEN, ERC20_ABI, w3) # Make sure w3 is an AsyncWeb3 instance\n```\n\n### Basic Operations\n\n#### Querying Multiple Balances\n\nFor synchronous operations:\n\n```python\naddresses = [\n # List of addresses\n]\nbalances = multicallable.balanceOf(addresses).call()\n```\n\nFor asynchronous operations:\n\n```python\naddresses = [\n # List of addresses\n]\nbalances = await async_multicallable.balanceOf(addresses).call()\n```\n\n#### Detailed Call Information\n\nFor synchronous operations:\n\n```python\ndetailed_info = multicallable.balanceOf(addresses).detailed_call()\n```\n\nFor asynchronous operations:\n\n```python\ndetailed_info = await async_multicallable.balanceOf(addresses).detailed_call()\n```\n\n### Advanced Features\n\n#### Handling Failed Calls\n\nBy default, all calls must succeed for the batch call to return successfully. Use `require_success=False` to allow partial success:\n\n```python\nmc = Multicallable(contract_address, contract_abi, w3)\npartial_result = mc.getNum(list(range(7))).call(require_success=False)\n```\n\n#### Batching Large Number of Calls\n\nFor large number of calls, you can specify the number of buckets using the `n` parameter:\n\n```python\nresult = mc.getNum(list(range(70000))).call(require_success=False, n=100)\n```\n\n#### Progress Indicator\n\nEnable a progress bar for better visibility into the batch processing:\n\n```python\nresult = mc.getNum(list(range(70000))).call(n=100, progress_bar=True, require_success=False)\n```\n\n#### Custom Multicall Instance\n\nYou can also use a custom Multicall instance with a custom address and ABI:\n\n```python\nfrom multicallable.multicall import Multicall\n\nmulticall = Multicall(w3, custom_address, custom_abi)\nmc = Multicallable(contract_address, contract_abi, multicall=multicall)\n```\n\n## Authors\n\n- **[MiKO](https://github.com/MiKoronjoo)** - *Initial work*\n- **[Naveed](https://github.com/Navid-Fkh)** - *Contributor*\n",
"bugtrack_url": null,
"license": null,
"summary": "Easy way to work with Multicall package",
"version": "7.2.0",
"project_urls": {
"Bug Tracker": "https://github.com/deusfinance/multicallable/issues",
"Homepage": "https://github.com/deusfinance/multicallable"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "cef6fc08b17a9a9a02159eeaafe430cf01df58d73ba08c9bab8c795df48b650f",
"md5": "4faa41df437cfa1f2b9c59ec3cd8556a",
"sha256": "d1417f264e863f56339d7cbe1280acc098664785bc20309b54f5039daca695e0"
},
"downloads": -1,
"filename": "multicallable-7.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4faa41df437cfa1f2b9c59ec3cd8556a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.8.0",
"size": 15330,
"upload_time": "2025-01-21T08:13:33",
"upload_time_iso_8601": "2025-01-21T08:13:33.315856Z",
"url": "https://files.pythonhosted.org/packages/ce/f6/fc08b17a9a9a02159eeaafe430cf01df58d73ba08c9bab8c795df48b650f/multicallable-7.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "09f6e5e47f05d3ff87d8067ef806dae6d58f1d7f551370a43f33908e1478ee35",
"md5": "d2eb9608c4c5a1f8d0200efe74c97d14",
"sha256": "3ac79861c65fa378d9ee396afe7b776db08cfe1a4b012ce38ff4eed55b1d4e5b"
},
"downloads": -1,
"filename": "multicallable-7.2.0.tar.gz",
"has_sig": false,
"md5_digest": "d2eb9608c4c5a1f8d0200efe74c97d14",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.8.0",
"size": 13329,
"upload_time": "2025-01-21T08:13:35",
"upload_time_iso_8601": "2025-01-21T08:13:35.605386Z",
"url": "https://files.pythonhosted.org/packages/09/f6/e5e47f05d3ff87d8067ef806dae6d58f1d7f551370a43f33908e1478ee35/multicallable-7.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-21 08:13:35",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "deusfinance",
"github_project": "multicallable",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "web3",
"specs": [
[
">=",
"7.0.0"
],
[
"<",
"8.0.0"
]
]
}
],
"lcname": "multicallable"
}