Public API¶
Schema¶
Primitives¶
- class ethereum_rpc.Amount(wei: int)[source]¶
Represents a sum in the chain’s native currency.
Can be subclassed to represent specific currencies of different networks (ETH, MATIC etc). Arithmetic and comparison methods perform strict type checking, so currency objects of different types cannot be compared or added to each other.
- classmethod ether(value: float) CustomAmount[source]¶
Creates a sum from the amount in the main currency unit.
- classmethod gwei(value: float) CustomAmount[source]¶
Creates a sum from the amount in gwei (
10^(-9)of the main unit).
- classmethod wei(value: int) CustomAmount[source]¶
Creates a sum from the amount in wei (
10^(-18)of the main unit).
- class ethereum_rpc.Address(value: bytes)[source]¶
Represents an Ethereum address.
Can be subclassed to represent specific addresses of different networks. Comparison methods perform strict type checking, so objects of different types cannot be compared to each other.
- classmethod from_hex(address_str: str) CustomAddress[source]¶
Creates the address from a hex representation (with or without the
0xprefix, checksummed or not).
- ethereum_rpc.Block¶
alias of
int|BlockLabel
Inputs¶
- class ethereum_rpc.EthCallParams(to: Address, from_: None | Address = None, gas: None | int = None, gas_price: None | Amount = None, value: None | Amount = None, data: None | bytes = None)[source]¶
Transaction fields for
eth_call.- from_: None | Address = None¶
The transaction sender. May matter for some contract methods that depend on
msg.sender.
- class ethereum_rpc.EstimateGasParams(from_: Address, to: None | Address = None, gas: None | int = None, gas_price: None | Amount = None, nonce: None | int = None, value: None | Amount = None, data: None | bytes = None)[source]¶
Transaction fields for
eth_estimateGas.
- class ethereum_rpc.FilterParams(from_block: None | int | BlockLabel = None, to_block: None | int | BlockLabel = None, address: None | Address | tuple[Address, ...] = None, topics: None | tuple[None | LogTopic | tuple[LogTopic, ...], ...] = None)[source]¶
Filter parameters for
eth_getLogsoreth_newFilter.- from_block: None | int | BlockLabel = None¶
The starting block of the filter.
- to_block: None | int | BlockLabel = None¶
The ending block of the filter (inclusive).
- class ethereum_rpc.FilterParamsEIP234(block_hash: BlockHash, address: None | Address | tuple[Address, ...] = None, topics: None | tuple[None | LogTopic | tuple[LogTopic, ...], ...] = None)[source]¶
Alternative filter parameters for
eth_getLogs(introduced in EIP-234).
- class ethereum_rpc.Type2Transaction(chain_id: int, value: Amount, gas: int, max_fee_per_gas: Amount, max_priority_fee_per_gas: Amount, nonce: int, to: None | Address = None, data: None | bytes = None)[source]¶
An EIP-1559 (dynamic fee) transaction.
- max_priority_fee_per_gas: Amount¶
Maximum miner fee (in addition to the base fee) the sender is willing to pay.
Outputs¶
- class ethereum_rpc.TxReceipt[source]¶
Transaction receipt.
- contract_address: None | Address¶
If it was a successful deployment transaction, contains the address of the deployed contract.
- cumulative_gas_used: int¶
The total amount of gas used when this transaction was executed in the block.
- class ethereum_rpc.BlockInfo[source]¶
Block info.
- nonce: None | BlockNonce¶
Block’s nonce.
Nonefor pending blocks.
- sha3_uncles: UnclesHash¶
SHA3 of the uncles data in the block.
- class ethereum_rpc.TxInfo[source]¶
Transaction info.
- block_hash: None | BlockHash¶
The hash of the block this transaction belongs to.
Nonefor pending transactions.
- max_fee_per_gas: None | Amount¶
maxFeePerGasvalue specified by the sender. Only for EIP1559 transactions.
RPC errors¶
- class ethereum_rpc.ErrorCode¶
NewType creates simple unique types with almost zero runtime overhead. NewType(name, tp) is considered a subtype of tp by static type checkers. At runtime, NewType(name, tp) returns a dummy callable that simply returns its argument. Usage:
UserId = NewType('UserId', int) def name_by_id(user_id: UserId) -> str: ... UserId('user') # Fails type check name_by_id(42) # Fails type check name_by_id(UserId(42)) # OK num = UserId(5) + 1 # type: int
alias of
int
- class ethereum_rpc.RPCError(code: ErrorCode, message: str, data: None | bytes = None)[source]¶
Bases:
ExceptionA general problem with fulfilling the request at the provider’s side.
This means the provider sent a correct response with an error code and possibly some associated data (
"error": {"code": ..., "message": ..., "data": ...}sub-dictionary in the RPC response).- classmethod with_code(code: RPCErrorCode, message: str, data: None | bytes = None) RPCError[source]¶
Creates this error given a known error code.
- code: ErrorCode¶
The error type.
- property parsed_code: None | RPCErrorCode¶
If the error code is known, returns the corresponding enum entry.
- class ethereum_rpc.RPCErrorCode(value)[source]¶
Standard RPC error codes returned by providers.
- EXECUTION_ERROR = 3¶
Contract transaction failed during execution. See the data for details.
- INTERNAL_ERROR = -32603¶
Internal JSON-RPC error.
- INVALID_PARAMETER = -32602¶
Invalid method parameter(s).
- INVALID_REQUEST = -32600¶
The JSON sent is not a valid Request object.
- METHOD_NOT_FOUND = -32601¶
The method does not exist / is not available.
- PARSE_ERROR = -32700¶
Invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
- SERVER_ERROR = -32000¶
Reserved for implementation-defined server-errors. See the message for details.
Serialization¶
- class ethereum_rpc.JSON¶
A JSON-ifiable object (
bool,int,float,str,None, iterable ofJSON, or mapping ofstrtoJSON).