EvmRpc
EVM JSON-RPC 2.0 over an injected httpx.Client.
The client is REQUIRED and injected so cassettes plug in, url is
required because a node endpoint is host configuration, and the
constructor performs no I/O.
__init__
__init__(self, client: httpx.Client, url: str) -> None
Bind the injected client and endpoint URL. No I/O.
url is refused HERE, not by widening _post's except
tuple. Catching TypeError around the send did keep the
promise, and it also swallowed any TypeError this module got
wrong itself, dressed up as a node failure. A type check at the
door keeps the promise without buying that.
Parameters
clientrequired, httpx.ClientYour httpx.Client, injected so a cassette or a mock transport plugs in unchanged. No client is created for you.
urlrequired, strThe node endpoint. Host configuration, so it is required and never guessed from a chain id.
Raises
eth_call
eth_call(self, to: str, data: str, block: str = latest) -> str
eth_call against to with data; the result hex string.
Posts params exactly [{"to": to.lower(), "data": data}, block].
That array is what the wave-4 golden fixture keys on, so key
order, address casing and an added "from" key are all wire
contract. data is a lowercase 0x-prefixed hex string and
goes on the wire verbatim; block is a tag from
block_tag. The result is returned as received, with no
case folding and no padding change: decoding the word is
codec/abi.py's job.
Raises:
SourceError: on a to that is not a string, and on any
transport, envelope or shape failure, including a result
that is not a string.
Parameters
torequired, strnone
datarequired, strnone
blockoptional, str, default 'latest'none
Raises
eth_get_balance
eth_get_balance(self, address: str, block: str = latest) -> int
The address's native balance in wei.
Calls eth_getBalance with params [address, block]. The
result is a hex STRING and parses with int(x, 16), never
through float, so a JSON integer result is a malformed envelope
and not a lenient success.
Raises:
SourceError: on any transport or envelope failure, on a
result that is not a string, and on a string that is not
0x-prefixed hex.
Parameters
addressrequired, strnone
blockoptional, str, default 'latest'none
Raises
eth_block_number
eth_block_number(self) -> int
The chain head as an int.
Calls eth_blockNumber with params []. The result is a hex
STRING and parses with int(x, 16).
Raises: SourceError: on any transport or envelope failure and on a result that is not a hex string.
Raises
eth_get_logs
eth_get_logs(self, filter_object: dict) -> list[dict]
eth_getLogs rows for filter_object, raw and untyped.
The filter dict goes on the wire unvalidated as params
[filter_object] and the rows come back exactly as received,
in received order: logs.py owns both the filter keys and the
row typing.
Raises: SourceError: on any transport or envelope failure and when the result is not a list.
Parameters
filter_objectrequired, dictnone
Raises
batch
batch(self, requests: Sequence[tuple[str, list]]) -> tuple[BatchResult, ...]
Post (method, params) pairs as one JSON-RPC array.
Ids are 1..N assigned in request order and restart at 1 for
every batch. Each response is looked up by its id, never by
its array position, and the returned tuple is in REQUEST order.
An EMPTY requests returns () and issues NO request, the
same answer Multicall3.aggregate3 gives its own empty case.
A node may accept an empty JSON-RPC array or reject it as
invalid, so posting one asks a question with no agreed answer.
An item carrying an error member becomes a declared
BatchResult failure and does NOT raise: one reverting
call must not void the batch. An item matched to its request but
carrying no usable result is declared the same way, so a
null result is reported and never read as an answer.
Raises:
SourceError: on requests that is not a sequence and on an
entry that is not a (method, params) pair, on any
transport or envelope failure, on a body that is not a
list, on a length that differs from the request's, on an
item that is not an object or carries no id, on a
duplicate id, and on an id not in the batch.
Parameters
requestsrequired, Sequence[tuple[str, list]]none