Ethereum Types

Introduction

Types re-used throughout the specification, which are specific to Ethereum.

Module Contents

Classes

LegacyTransaction

Atomic operation performed on the block chain.

AccessListTransaction

The transaction type added in EIP-2930 to support access lists.

FeeMarketTransaction

The transaction type added in EIP-1559.

Account

State associated with an address.

Header

Header portion of a block on the chain.

Block

A complete block.

Log

Data record produced during the execution of a transaction.

Receipt

Result of a transaction.

Functions

encode_transaction

Encode a transaction. Needed because non-legacy transactions aren’t RLP.

decode_transaction

Decode a transaction. Needed because non-legacy transactions aren’t RLP.

encode_account

Encode Account dataclass.

Attributes

Address

Root

Bloom

TX_BASE_COST

TX_DATA_COST_PER_NON_ZERO

TX_DATA_COST_PER_ZERO

TX_CREATE_COST

TX_ACCESS_LIST_ADDRESS_COST

TX_ACCESS_LIST_STORAGE_KEY_COST

Transaction

EMPTY_ACCOUNT

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.

class Account
nonce :ethereum.base_types.Uint
balance :ethereum.base_types.U256
code :bytes

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),
        )
    )

Block

A complete block.

class Block
header :Header
transactions :Tuple[Union[ethereum.base_types.Bytes, LegacyTransaction], Ellipsis]
ommers :Tuple[Header, Ellipsis]

Log

Data record produced during the execution of a transaction.

class Log
address :Address
topics :Tuple[ethereum.crypto.hash.Hash32, Ellipsis]
data :bytes

Receipt

Result of a transaction.

class Receipt
succeeded :bool
cumulative_gas_used :ethereum.base_types.Uint
bloom :Bloom
logs :Tuple[Log, Ellipsis]