Skip to main content

Async EVM/Web3 library — connection pooling, request batching, ABI encoding/decoding, Multicall3

Project description

interevm

Async EVM/Web3 library for Python — connection pooling, request batching, ABI encoding/decoding, and Multicall3 support.

Installation

pip install interevm

Requirements: Python 3.11+, no web3.py dependency.


Quick start

RPCClient

import asyncio
from interevm import RPCClient

async def main():
    async with RPCClient("https://eth.llamarpc.com") as client:
        block  = await client.get_block_number()
        bal    = await client.get_balance("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")
        fees   = await client.get_eip1559_fees()
        print(block, bal, fees)

asyncio.run(main())

Pass a full RPCConfig to tune connection pool size, timeouts, retries, and TTL cache:

from interevm import RPCClient, RPCConfig

config = RPCConfig(
    rpc_url="https://eth.llamarpc.com",
    max_connections=50,
    max_retries=3,
    cache_ttl=60,
)
client = RPCClient(config)

Contract — encode / decode

from interevm import Contract

ERC20_ABI = [...]  # standard ERC-20 ABI list

token = Contract("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", ERC20_ABI)

# Build calldata manually
calldata = token.encode_function_data("balanceOf", "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")

# Decode a raw eth_call result
result = token.decode_function_result("balanceOf", "0x00000000000000000000000000000000000000000000000000000002540be400")
print(result)  # 10000000000

# Decode an event log
decoded = token.decode_log(receipt["logs"][0]["topics"], receipt["logs"][0]["data"])
print(decoded)  # {'from': '0x...', 'to': '0x...', 'value': 1000, '_event': 'Transfer'}

Multicall

import asyncio
from interevm import RPCClient, Contract, MulticallHelper

async def main():
    async with RPCClient("https://eth.llamarpc.com") as client:
        helper = MulticallHelper(client)

        usdc  = Contract("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", ERC20_ABI)
        weth  = Contract("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", ERC20_ABI)
        wallet = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"

        results = await helper.execute_multicall([
            (usdc.address, usdc, "balanceOf", (wallet,), "usdc_balance"),
            (weth.address, weth, "balanceOf", (wallet,), "weth_balance"),
        ])

        print(results["usdc_balance"])
        print(results["weth_balance"])

asyncio.run(main())

Public API

interevm.RPCClient

Method Description
get_chain_id() Chain ID (cached per instance)
get_block_number() Latest block number
get_balance(address, block) Balance in wei
get_nonce(address, block) Transaction count
get_bytecode(address, block) Contract bytecode
get_gas_price() Gas price in wei
call(to, data, ...) Raw eth_call
estimate_gas(tx) Gas estimate
send_raw_transaction(signed_tx) Broadcast signed tx
get_block_by_number(n, full_txs) Block data
batch_get_blocks(numbers) Batch block fetch
get_transaction(hash) Transaction by hash
get_transaction_receipt(hash) Receipt by hash
batch_get_transactions(hashes) Batch tx fetch
batch_get_receipts(hashes) Batch receipt fetch
get_eip1559_fees() base_fee / max_priority_fee / max_fee
get_params_for_eip1559_transaction(addr) nonce + fees in one call
multicall(multicall_contract, calls) Multicall3.tryAggregate
call_function(contract, name, *args) Typed contract call
debug_trace_transaction(hash, ...) debug_traceTransaction
close() Release all connections

interevm.RPCConfig

Dataclass with connection, timeout, retry, and cache settings.

interevm.RPCError

Exception raised on JSON-RPC error responses. Carries .code, .message, .data.

interevm.CallRequest

Dataclass representing one call in a batch (method, params, id).

interevm.Contract

Method Description
encode_function_data(name, *args) Build hex calldata
decode_function_result(name, data) Decode eth_call result
decode_log(topics, data) Decode event log
get_function(name)ABIFunction ABI function descriptor
get_event(name)ABIEvent ABI event descriptor
get_event_by_topic(topic0) Lookup event by topic0
has_function(name) / has_event(name) Membership check
list_functions() / list_events() List names

interevm.ABIFunction

Frozen dataclass: name, inputs, outputs, state_mutability, selector (computed). Methods: encode_input(*args), decode_output(data).

interevm.ABIEvent

Frozen dataclass: name, inputs, anonymous, topic0 (computed). Methods: decode_log(topics, data).

interevm.MulticallHelper

execute_multicall(calls, batch_size=100) — batch eth_calls via Multicall3.

Helper functions

Function Description
mkdata(sig, types, params) Build calldata from signature + params
compute_function_selector(sig) 4-byte selector (LRU cached)
compute_event_topic(sig) 32-byte topic0 hash (LRU cached)
topic_from_address(addr) Address → 32-byte topic
topic_from_uint(value) uint → 32-byte topic
ensure_hex_prefix(value) Ensure 0x prefix
format_tx_dict(tx) Convert int fields to hex for JSON-RPC
rpc_retry(coro, *args, retries, base_delay) Standalone retry wrapper

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

interevm-0.1.1.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

interevm-0.1.1-py3-none-any.whl (15.6 kB view details)

Uploaded Python 3

File details

Details for the file interevm-0.1.1.tar.gz.

File metadata

  • Download URL: interevm-0.1.1.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for interevm-0.1.1.tar.gz
Algorithm Hash digest
SHA256 464f0761ef07ceca6acfdb49b49de00e3b7ec07f75a152390e97c2567e5a00b5
MD5 8729500c98c18c048790ff315723e1a8
BLAKE2b-256 dc077007701ab5ca3af61309b2a1df8d52e2eb1cc430800ad85b50ffc86bb261

See more details on using hashes here.

File details

Details for the file interevm-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: interevm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for interevm-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e2cec5da5bfe7364c7135f8783c8925bbf1839c20ec3fa47b3ec71ddb304e324
MD5 648852617e801696c0d409ac0a366cb0
BLAKE2b-256 a8656f790278c286bf8b5f1ccd0e2f3dde857ea6c9eb220bc92f003fc38e6c03

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page