ethereum.shanghai.transactionsethereum.cancun.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
22 | TX_BASE_COST = 21000 |
---|
TX_DATA_COST_PER_NON_ZERO
23 | TX_DATA_COST_PER_NON_ZERO = 16 |
---|
TX_DATA_COST_PER_ZERO
24 | TX_DATA_COST_PER_ZERO = 4 |
---|
TX_CREATE_COST
25 | TX_CREATE_COST = 32000 |
---|
TX_ACCESS_LIST_ADDRESS_COST
26 | TX_ACCESS_LIST_ADDRESS_COST = 2400 |
---|
TX_ACCESS_LIST_STORAGE_KEY_COST
27 | TX_ACCESS_LIST_STORAGE_KEY_COST = 1900 |
---|
LegacyTransaction
Atomic operation performed on the block chain.
30 | @slotted_freezable |
---|
31 | @dataclass |
---|
class LegacyTransaction:
nonce
37 | nonce: U256 |
---|
gas_price
38 | gas_price: Uint |
---|
gas
39 | gas: Uint |
---|
to
40 | to: Union[Bytes0, Address] |
---|
value
41 | value: U256 |
---|
data
42 | data: Bytes |
---|
v
43 | v: U256 |
---|
r
44 | r: U256 |
---|
s
45 | s: U256 |
---|
AccessListTransaction
The transaction type added in EIP-2930 to support access lists.
48 | @slotted_freezable |
---|
49 | @dataclass |
---|
class AccessListTransaction:
chain_id
55 | chain_id: U64 |
---|
nonce
56 | nonce: U256 |
---|
gas_price
57 | gas_price: Uint |
---|
gas
58 | gas: Uint |
---|
to
59 | to: Union[Bytes0, Address] |
---|
value
60 | value: U256 |
---|
data
61 | data: Bytes |
---|
access_list
62 | access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] |
---|
y_parity
63 | y_parity: U256 |
---|
r
64 | r: U256 |
---|
s
65 | s: U256 |
---|
FeeMarketTransaction
The transaction type added in EIP-1559.
68 | @slotted_freezable |
---|
69 | @dataclass |
---|
class FeeMarketTransaction:
chain_id
75 | chain_id: U64 |
---|
nonce
76 | nonce: U256 |
---|
max_priority_fee_per_gas
77 | max_priority_fee_per_gas: Uint |
---|
max_fee_per_gas
78 | max_fee_per_gas: Uint |
---|
gas
79 | gas: Uint |
---|
to
80 | to: Union[Bytes0, Address] |
---|
value
81 | value: U256 |
---|
data
82 | data: Bytes |
---|
access_list
83 | access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] |
---|
y_parity
84 | y_parity: U256 |
---|
r
85 | r: U256 |
---|
s
86 | s: U256 |
---|
BlobTransaction
The transaction type added in EIP-4844.
89 | @slotted_freezable |
---|
90 | @dataclass |
---|
class BlobTransaction:
chain_id
96 | chain_id: U64 |
---|
nonce
97 | nonce: U256 |
---|
max_priority_fee_per_gas
98 | max_priority_fee_per_gas: Uint |
---|
max_fee_per_gas
99 | max_fee_per_gas: Uint |
---|
gas
100 | gas: Uint |
---|
to
101 | to: Address |
---|
value
102 | value: U256 |
---|
data
103 | data: Bytes |
---|
access_list
104 | access_list: Tuple[Tuple[Address, Tuple[Bytes32, ...]], ...] |
---|
max_fee_per_blob_gas
105 | max_fee_per_blob_gas: U256 |
---|
blob_versioned_hashes
106 | blob_versioned_hashes: Tuple[VersionedHash, ...] |
---|
y_parity
107 | y_parity: U256 |
---|
r
108 | r: U256 |
---|
s
109 | s: U256 |
---|
Transaction
112 | Transaction = Union[ |
---|---|
90 | LegacyTransaction, AccessListTransaction, FeeMarketTransaction |
113 | LegacyTransaction, |
114 | AccessListTransaction, |
115 | FeeMarketTransaction, |
116 | BlobTransaction, |
117 | ] |
encode_transaction
Encode a transaction. Needed because non-legacy transactions aren't RLP.
def encode_transaction(tx: Transaction) -> Union[LegacyTransaction, Bytes]:
121 | """ |
---|---|
122 | Encode a transaction. Needed because non-legacy transactions aren't RLP. |
123 | """ |
124 | if isinstance(tx, LegacyTransaction): |
125 | return tx |
126 | elif isinstance(tx, AccessListTransaction): |
127 | return b"\x01" + rlp.encode(tx) |
128 | elif isinstance(tx, FeeMarketTransaction): |
129 | return b"\x02" + rlp.encode(tx) |
104 | else: |
105 | raise Exception(f"Unable to encode transaction of type {type(tx)}") |
130 | elif isinstance(tx, BlobTransaction): |
131 | return b"\x03" + rlp.encode(tx) |
132 | else: |
133 | 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:
137 | """ |
---|---|
138 | Decode a transaction. Needed because non-legacy transactions aren't RLP. |
139 | """ |
140 | if isinstance(tx, Bytes): |
141 | if tx[0] == 1: |
142 | return rlp.decode_to(AccessListTransaction, tx[1:]) |
143 | elif tx[0] == 2: |
144 | return rlp.decode_to(FeeMarketTransaction, tx[1:]) |
117 | else: |
118 | raise InvalidBlock |
145 | elif tx[0] == 3: |
146 | return rlp.decode_to(BlobTransaction, tx[1:]) |
147 | else: |
148 | raise InvalidBlock |
149 | else: |
150 | return tx |