ethereum.muir_glacier.transactionsethereum.berlin.transactions

Transactions are atomic units of work created externally to Ethereum and submitted to be executed. If Ethereum is viewed as a state machine, transactions are the events that move between states.

TX_BASE_COST

17
TX_BASE_COST = 21000

TX_DATA_COST_PER_NON_ZERO

18
TX_DATA_COST_PER_NON_ZERO = 16

TX_DATA_COST_PER_ZERO

19
TX_DATA_COST_PER_ZERO = 4

TX_CREATE_COST

20
TX_CREATE_COST = 32000

TX_ACCESS_LIST_ADDRESS_COST

21
TX_ACCESS_LIST_ADDRESS_COST = 2400

TX_ACCESS_LIST_STORAGE_KEY_COST

22
TX_ACCESS_LIST_STORAGE_KEY_COST = 1900

LegacyTransaction

Atomic operation performed on the block chain.

25
@slotted_freezable
26
@dataclass
class LegacyTransaction:

nonce

32
    nonce: U256

gas_price

33
    gas_price: Uint

gas

34
    gas: Uint

to

35
    to: Union[Bytes0, Address]

value

36
    value: U256

data

37
    data: Bytes

v

38
    v: U256

r

39
    r: U256

s

40
    s: U256

AccessListTransaction

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

43
@slotted_freezable
44
@dataclass
class AccessListTransaction:

chain_id

50
    chain_id: U64

nonce

51
    nonce: U256

gas_price

52
    gas_price: Uint

gas

53
    gas: Uint

to

54
    to: Union[Bytes0, Address]

value

55
    value: U256

data

56
    data: Bytes

access_list

57
    access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...]

y_parity

58
    y_parity: U256

r

59
    r: U256

s

60
    s: U256

Transaction

Atomic operation performed on the block chain.

21
@slotted_freezable
22
@dataclass
class Transaction:

nonce

28
    nonce: U256

gas_price

29
    gas_price: Uint

gas

30
    gas: Uint

to

31
    to: Union[Bytes0, Address]

value

32
    value: U256

data

33
    data: Bytes

v

34
    v: U256

r

35
    r: U256

s

36
    s: U256

Transaction

63
Transaction = Union[LegacyTransaction, AccessListTransaction]

encode_transaction

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

def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
67
    """
68
    Encode a transaction. Needed because non-legacy transactions aren't RLP.
69
    """
70
    if isinstance(tx, LegacyTransaction):
71
        return tx
72
    elif isinstance(tx, AccessListTransaction):
73
        return b"\x01" + rlp.encode(tx)
74
    else:
75
        raise Exception(f"Unable to encode transaction of type {type(tx)}")

decode_transaction

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

def decode_transaction(tx: Union[LegacyTransaction, Bytes]) -> Transaction:
79
    """
80
    Decode a transaction. Needed because non-legacy transactions aren't RLP.
81
    """
82
    if isinstance(tx, Bytes):
83
        if tx[0] != 1:
84
            raise TransactionTypeError(tx[0])
85
        return rlp.decode_to(AccessListTransaction, tx[1:])
86
    else:
87
        return tx