Ethereum Types
Table of Contents
Introduction
Types re-used throughout the specification, which are specific to Ethereum.
Module Contents
Classes
Atomic operation performed on the block chain. |
|
The transaction type added in EIP-2930 to support access lists. |
|
The transaction type added in EIP-1559. |
|
State associated with an address. |
|
Header portion of a block on the chain. |
|
A complete block. |
|
Data record produced during the execution of a transaction. |
|
Result of a transaction. |
Functions
Encode a transaction. Needed because non-legacy transactions aren’t RLP. |
|
Decode a transaction. Needed because non-legacy transactions aren’t RLP. |
|
Encode Account dataclass. |
Attributes
Module Details
Address
- Address
Address = Bytes20
Root
- Root
Root = Hash32
Bloom
- Bloom
Bloom = Bytes256
TX_BASE_COST
- TX_BASE_COST
TX_BASE_COST = 21000
TX_DATA_COST_PER_NON_ZERO
- TX_DATA_COST_PER_NON_ZERO
TX_DATA_COST_PER_NON_ZERO = 16
TX_DATA_COST_PER_ZERO
- TX_DATA_COST_PER_ZERO
TX_DATA_COST_PER_ZERO = 4
TX_CREATE_COST
- TX_CREATE_COST
TX_CREATE_COST = 32000
TX_ACCESS_LIST_ADDRESS_COST
- TX_ACCESS_LIST_ADDRESS_COST
TX_ACCESS_LIST_ADDRESS_COST = 2400
TX_ACCESS_LIST_STORAGE_KEY_COST
- TX_ACCESS_LIST_STORAGE_KEY_COST
TX_ACCESS_LIST_STORAGE_KEY_COST = 1900
LegacyTransaction
Atomic operation performed on the block chain.
- class LegacyTransaction
- nonce :ethereum.base_types.U256
- gas_price :ethereum.base_types.Uint
- gas :ethereum.base_types.Uint
- to :Union[ethereum.base_types.Bytes0, Address]
- value :ethereum.base_types.U256
- data :ethereum.base_types.Bytes
- v :ethereum.base_types.U256
- r :ethereum.base_types.U256
- s :ethereum.base_types.U256
AccessListTransaction
The transaction type added in EIP-2930 to support access lists.
- class AccessListTransaction
- chain_id :ethereum.base_types.U64
- nonce :ethereum.base_types.U256
- gas_price :ethereum.base_types.Uint
- gas :ethereum.base_types.Uint
- to :Union[ethereum.base_types.Bytes0, Address]
- value :ethereum.base_types.U256
- data :ethereum.base_types.Bytes
- access_list :Tuple[Tuple[Address, Tuple[ethereum.base_types.Bytes32, Ellipsis]], Ellipsis]
- y_parity :ethereum.base_types.U256
- r :ethereum.base_types.U256
- s :ethereum.base_types.U256
FeeMarketTransaction
The transaction type added in EIP-1559.
- class FeeMarketTransaction
- chain_id :ethereum.base_types.U64
- nonce :ethereum.base_types.U256
- max_priority_fee_per_gas :ethereum.base_types.Uint
- max_fee_per_gas :ethereum.base_types.Uint
- gas :ethereum.base_types.Uint
- to :Union[ethereum.base_types.Bytes0, Address]
- value :ethereum.base_types.U256
- data :ethereum.base_types.Bytes
- access_list :Tuple[Tuple[Address, Tuple[ethereum.base_types.Bytes32, Ellipsis]], Ellipsis]
- y_parity :ethereum.base_types.U256
- r :ethereum.base_types.U256
- s :ethereum.base_types.U256
Transaction
- Transaction
Transaction = Union[
LegacyTransaction, AccessListTransaction, FeeMarketTransaction
]
encode_transaction
- encode_transaction(tx: Transaction) → Union[LegacyTransaction, ethereum.base_types.Bytes]
Encode a transaction. Needed because non-legacy transactions aren’t RLP.
def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
if isinstance(tx, LegacyTransaction):
return tx
elif isinstance(tx, AccessListTransaction):
return b"\x01" + rlp.encode(tx)
elif isinstance(tx, FeeMarketTransaction):
return b"\x02" + rlp.encode(tx)
else:
raise Exception(f"Unable to encode transaction of type {type(tx)}")
decode_transaction
- decode_transaction(tx: Union[LegacyTransaction, ethereum.base_types.Bytes]) → Transaction
Decode a transaction. Needed because non-legacy transactions aren’t RLP.
def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
if isinstance(tx, Bytes):
if tx[0] == 1:
return rlp.decode_to(AccessListTransaction, tx[1:])
elif tx[0] == 2:
return rlp.decode_to(FeeMarketTransaction, tx[1:])
else:
raise InvalidBlock
else:
return tx
Account
State associated with an address.
EMPTY_ACCOUNT
- EMPTY_ACCOUNT
EMPTY_ACCOUNT = Account(
nonce=Uint(0),
balance=U256(0),
code=bytearray(),
)
encode_account
- encode_account(raw_account_data: Account, storage_root: ethereum.base_types.Bytes) → ethereum.base_types.Bytes
Encode Account dataclass.
Storage is not stored in the Account dataclass, so Accounts cannot be encoded with providing a storage root.
def encode_account(raw_account_data: Account, storage_root: Bytes) -> Bytes:
return rlp.encode(
(
raw_account_data.nonce,
raw_account_data.balance,
storage_root,
keccak256(raw_account_data.code),
)
)
Header
Header portion of a block on the chain.
- class Header
- parent_hash :ethereum.crypto.hash.Hash32
- ommers_hash :ethereum.crypto.hash.Hash32
- coinbase :Address
- state_root :Root
- transactions_root :Root
- receipt_root :Root
- bloom :Bloom
- difficulty :ethereum.base_types.Uint
- number :ethereum.base_types.Uint
- gas_limit :ethereum.base_types.Uint
- gas_used :ethereum.base_types.Uint
- timestamp :ethereum.base_types.U256
- extra_data :ethereum.base_types.Bytes
- prev_randao :ethereum.base_types.Bytes32
- nonce :ethereum.base_types.Bytes8
- base_fee_per_gas :ethereum.base_types.Uint
Block
A complete block.
Log
Data record produced during the execution of a transaction.
Receipt
Result of a transaction.