Ethereum Types

Introduction

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

Module Contents

Classes

TransactionLegacyTransaction

Atomic operation performed on the block chain.

AccessListTransaction

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

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.U256
gas :ethereum.base_types.U256
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.Uint64
nonce :ethereum.base_types.U256
gas_price :ethereum.base_types.U256
gas :ethereum.base_types.U256
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]
v :ethereum.base_types.U256
r :ethereum.base_types.U256
s :ethereum.base_types.U256

Transaction

Atomic operation performed on the block chain.

class Transaction
nonce :ethereum.base_types.U256
gas_price :ethereum.base_types.U256
gas :ethereum.base_types.U256
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
Transaction = Union[LegacyTransaction, AccessListTransaction]

encode_transaction

encode_transaction(tx)

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)
    else:
        raise Exception(f"Unable to encode transaction of type {type(tx)}")

decode_transaction

decode_transaction(tx)

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

def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
    if isinstance(tx, Bytes):
        ensure(tx[0] == 1, InvalidBlock)
        return rlp.decode_to(AccessListTransaction, tx[1:])
    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, storage_root)

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[Transaction,: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]