Multicall¶
- class arbitrum_py.utils.multicall.MultiCaller(provider, address)[source]¶
Bases:
objectA class for making batch calls to smart contracts using the Multicall2 contract.
This class provides functionality to execute multiple contract calls in a single request, reducing RPC calls and improving performance. It uses the Multicall2 contract deployed on various networks.
- Variables:
provider – The Web3 provider instance
address – The address of the deployed Multicall2 contract
- __init__(provider, address)[source]¶
Initialize the MultiCaller.
- Parameters:
provider (
Union[Web3,SignerOrProvider,ArbitrumProvider]) – A Web3 instance, SignerOrProvider, or ArbitrumProvideraddress (
str) – The address of the deployed Multicall2 contract
- Raises:
ArbSdkError – If the provider is invalid or no underlying provider is found
- static from_provider(provider)[source]¶
Create a MultiCaller instance using the provider’s network.
This method automatically looks up the Multicall2 contract address for the network that the provider is connected to.
- Parameters:
provider (
Union[Web3,SignerOrProvider,ArbitrumProvider]) – A Web3, SignerOrProvider, or ArbitrumProvider instance- Return type:
- Returns:
A new MultiCaller instance configured for the provider’s network
- get_block_number_input()[source]¶
Get the call input for retrieving the current block number.
- Return type:
Dict[str,Any]- Returns:
A dictionary containing the formatted call input for the Multicall2 contract
- get_current_block_timestamp_input()[source]¶
Returns a structured call input for retrieving the current block timestamp from Multicall2.
- Return type:
Dict[str,Any]- Returns:
A dict with ‘targetAddr’, ‘encoder’, ‘decoder’
- multi_call(params, require_success=False)[source]¶
Execute a batch of calls against the multicall contract. Each item in ‘params’ should contain:
‘targetAddr’: The address to call
‘encoder’: A function returning the encoded call data
‘decoder’: A function to decode the returned data
- Parameters:
params (
List[Dict[str,Any]]) – A list of dict objects describing how to encode/decode each callrequire_success (
bool) – If True, will revert if any sub-call fails
- Return type:
List[Any]- Returns:
A list of decoded results, or None if the call failed (when require_success = False)
- get_token_data(erc20_addresses, options=None)[source]¶
Retrieves token info (balanceOf, allowance, symbol, decimals, name) for each address in erc20_addresses, according to ‘options’.
- Parameters:
erc20_addresses (
List[str]) – List of token addressesoptions (
Optional[dict]) – A dictionary specifying which fields to retrieve, e.g. { “balanceOf”: { “account”: “0x…” }, “allowance”: {“owner”: “0x…”,”spender”: “0x…”},”symbol”:True,”decimals”:True,”name”:True }
- Return type:
List[dict]- Returns:
A list of dicts where each dict has the results for that token in the same order as erc20_addresses