ethereum.forks.amsterdam.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.

IntrinsicGasCost

Intrinsic gas costs for a transaction, split by gas type.

31
@final
32
@dataclass
class IntrinsicGasCost:

regular

Regular execution gas (calldata, base cost, access list, etc.).

36
    regular: RegularGas

calldata_floor

Minimum gas cost based on calldata size per EIP-7623.

39
    calldata_floor: RegularGas

TX_MAX_GAS_LIMIT

47
TX_MAX_GAS_LIMIT = Uint(16_777_216)

ACCESS_LIST_ADDRESS_FLOOR_TOKENS

Floor data tokens contributed by a single access list address per EIP-7981.

49
ACCESS_LIST_ADDRESS_FLOOR_TOKENS = Uint(80)

ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS

Floor data tokens contributed by a single access list storage key per EIP-7981.

57
ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS = Uint(128)

LegacyTransaction

Atomic operation performed on the block chain. This represents the original transaction format used before EIP-1559, EIP-2930, EIP-4844, and EIP-7702.

66
@final
67
@slotted_freezable
68
@dataclass
class LegacyTransaction:

nonce

A scalar value equal to the number of transactions sent by the sender.

81
    nonce: U256

gas_price

The price of gas for this transaction, in wei.

86
    gas_price: Uint

gas

The maximum amount of gas that can be used by this transaction.

91
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

96
    to: Bytes0 | Address

value

The amount of ether (in wei) to send with this transaction.

102
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

107
    data: Bytes

v

The recovery id of the signature.

113
    v: U256

r

The first part of the signature.

118
    r: U256

s

The second part of the signature.

123
    s: U256

Access

A mapping from account address to storage slots that are pre-warmed as part of a transaction.

129
@final
130
@slotted_freezable
131
@dataclass
class Access:

account

The address of the account that is accessed.

138
    account: Address

slots

A tuple of storage slots that are accessed in the account.

143
    slots: Tuple[Bytes32, ...]

AccessListTransaction

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

This transaction type extends the legacy transaction with an access list and chain ID. The access list specifies which addresses and storage slots the transaction will access.

149
@final
150
@slotted_freezable
151
@dataclass
class AccessListTransaction:

chain_id

The ID of the chain on which this transaction is executed.

163
    chain_id: U64

nonce

A scalar value equal to the number of transactions sent by the sender.

168
    nonce: U256

gas_price

The price of gas for this transaction.

173
    gas_price: Uint

gas

The maximum amount of gas that can be used by this transaction.

178
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

183
    to: Bytes0 | Address

value

The amount of ether (in wei) to send with this transaction.

189
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

194
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

200
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

206
    y_parity: U256

r

The first part of the signature.

211
    r: U256

s

The second part of the signature.

216
    s: U256

FeeMarketTransaction

The transaction type added in EIP-1559.

This transaction type introduces a new fee market mechanism with two gas price parameters: max_priority_fee_per_gas and max_fee_per_gas.

222
@final
223
@slotted_freezable
224
@dataclass
class FeeMarketTransaction:

chain_id

The ID of the chain on which this transaction is executed.

235
    chain_id: U64

nonce

A scalar value equal to the number of transactions sent by the sender.

240
    nonce: U256

max_priority_fee_per_gas

The maximum priority fee per gas that the sender is willing to pay.

245
    max_priority_fee_per_gas: Uint

max_fee_per_gas

The maximum fee per gas that the sender is willing to pay, including the base fee and priority fee.

250
    max_fee_per_gas: Uint

gas

The maximum amount of gas that can be used by this transaction.

256
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

261
    to: Bytes0 | Address

value

The amount of ether (in wei) to send with this transaction.

267
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

272
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

278
    access_list: Tuple[Access, ...]

y_parity

The recovery id of the signature.

284
    y_parity: U256

r

The first part of the signature.

289
    r: U256

s

The second part of the signature.

294
    s: U256

BlobTransaction

The transaction type added in EIP-4844.

This transaction type extends the fee market transaction to support blob-carrying transactions.

300
@final
301
@slotted_freezable
302
@dataclass
class BlobTransaction:

chain_id

The ID of the chain on which this transaction is executed.

313
    chain_id: U64

nonce

A scalar value equal to the number of transactions sent by the sender.

318
    nonce: U256

max_priority_fee_per_gas

The maximum priority fee per gas that the sender is willing to pay.

323
    max_priority_fee_per_gas: Uint

max_fee_per_gas

The maximum fee per gas that the sender is willing to pay, including the base fee and priority fee.

328
    max_fee_per_gas: Uint

gas

The maximum amount of gas that can be used by this transaction.

334
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

339
    to: Address

value

The amount of ether (in wei) to send with this transaction.

345
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

350
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

356
    access_list: Tuple[Access, ...]

max_fee_per_blob_gas

The maximum fee per blob gas that the sender is willing to pay.

362
    max_fee_per_blob_gas: U256

blob_versioned_hashes

A tuple of objects that represent the versioned hashes of the blobs included in the transaction.

367
    blob_versioned_hashes: Tuple[VersionedHash, ...]

y_parity

The recovery id of the signature.

373
    y_parity: U256

r

The first part of the signature.

378
    r: U256

s

The second part of the signature.

383
    s: U256

SetCodeTransaction

The transaction type added in EIP-7702.

This transaction type allows Ethereum Externally Owned Accounts (EOAs) to set code on their account, enabling them to act as smart contracts.

389
@final
390
@slotted_freezable
391
@dataclass
class SetCodeTransaction:

chain_id

The ID of the chain on which this transaction is executed.

402
    chain_id: U64

nonce

A scalar value equal to the number of transactions sent by the sender.

407
    nonce: U64

max_priority_fee_per_gas

The maximum priority fee per gas that the sender is willing to pay.

412
    max_priority_fee_per_gas: Uint

max_fee_per_gas

The maximum fee per gas that the sender is willing to pay, including the base fee and priority fee.

417
    max_fee_per_gas: Uint

gas

The maximum amount of gas that can be used by this transaction.

423
    gas: Uint

to

The address of the recipient. If empty, the transaction is a contract creation.

428
    to: Address

value

The amount of ether (in wei) to send with this transaction.

434
    value: U256

data

The data payload of the transaction, which can be used to call functions on contracts or to create new contracts.

439
    data: Bytes

access_list

A tuple of Access objects that specify which addresses and storage slots are accessed in the transaction.

445
    access_list: Tuple[Access, ...]

authorizations

A tuple of Authorization objects that specify what code the signer desires to execute in the context of their EOA.

451
    authorizations: Tuple[Authorization, ...]

y_parity

The recovery id of the signature.

457
    y_parity: U256

r

The first part of the signature.

462
    r: U256

s

The second part of the signature.

467
    s: U256

Transaction

Union type representing any valid transaction type.

473
Transaction = (
474
    LegacyTransaction
475
    | AccessListTransaction
476
    | FeeMarketTransaction
477
    | BlobTransaction
478
    | SetCodeTransaction
479
)

AccessListCapableTransaction

Transaction types that include an EIP-2930-style access list.

See has_access_list and Access for more details.

485
AccessListCapableTransaction = (
486
    AccessListTransaction
487
    | FeeMarketTransaction
488
    | BlobTransaction
489
    | SetCodeTransaction
490
)

FeeMarketCapableTransaction

Transaction types that include the EIP-1559-style fee structure.

See FeeMarketTransaction for more details.

502
FeeMarketCapableTransaction = (
503
    FeeMarketTransaction | BlobTransaction | SetCodeTransaction
504
)

encode_transaction

Encode a transaction into its RLP or typed transaction format. Needed because non-legacy transactions aren't RLP.

Legacy transactions are returned as-is, while other transaction types are prefixed with their type identifier and RLP encoded.

def encode_transaction(tx: Transaction) -> LegacyTransaction | Bytes:
516
    <snip>
523
    if isinstance(tx, LegacyTransaction):
524
        return tx
525
    elif isinstance(tx, AccessListTransaction):
526
        return b"\x01" + rlp.encode(tx)
527
    elif isinstance(tx, FeeMarketTransaction):
528
        return b"\x02" + rlp.encode(tx)
529
    elif isinstance(tx, BlobTransaction):
530
        return b"\x03" + rlp.encode(tx)
531
    elif isinstance(tx, SetCodeTransaction):
532
        return b"\x04" + rlp.encode(tx)
533
    else:
534
        raise Exception(f"Unable to encode transaction of type {type(tx)}")

decode_transaction

Decode a transaction from its RLP or typed transaction format. Needed because non-legacy transactions aren't RLP.

Accept a LegacyTransaction object (returned as-is) or raw bytes.

EIP-2718 states that the first byte distinguishes the format: [0x00, 0x7f] is a typed transaction, [0xc0, 0xfe] is a legacy transaction (RLP list prefix).

def decode_transaction(tx: LegacyTransaction | Bytes) -> Transaction:
538
    <snip>
549
    if isinstance(tx, Bytes):
550
        if tx[0] == 1:
551
            return rlp.decode_to(AccessListTransaction, tx[1:])
552
        elif tx[0] == 2:
553
            return rlp.decode_to(FeeMarketTransaction, tx[1:])
554
        elif tx[0] == 3:
555
            return rlp.decode_to(BlobTransaction, tx[1:])
556
        elif tx[0] == 4:
557
            return rlp.decode_to(SetCodeTransaction, tx[1:])
558
        elif tx[0] >= 0xC0:
559
            assert tx[0] <= 0xFE
560
            return rlp.decode_to(LegacyTransaction, tx)
561
        else:
562
            raise TransactionTypeError(tx[0])
563
    else:
564
        return tx

validate_transaction

Verifies a transaction.

The gas in a transaction gets used to pay for the intrinsic cost of operations, therefore if there is insufficient gas then it would not be possible to execute a transaction and it will be declared invalid.

Additionally, the nonce of a transaction must not equal or exceed the limit defined in EIP-2681. In practice, defining the limit as 2**64-1 has no impact because sending 2**64-1 transactions is improbable. It's not strictly impossible though, 2**64-1 transactions is the entire capacity of the Ethereum blockchain at 2022 gas limits for a little over 22 years.

Also, the code size of a contract creation transaction must be within limits of the protocol.

This function takes a transaction and gas_limit as parameters and returns the intrinsic gas costs for the transaction after validation. It throws an InsufficientTransactionGasError exception if the transaction does not provide enough gas to cover the intrinsic cost, and a NonceOverflowError exception if the nonce overflows. It also raises an InitCodeTooLargeError if the code size of a contract creation transaction exceeds the maximum allowed size.

def validate_transaction(tx: Transaction, ​​sender: Address) -> IntrinsicGasCost:
568
    <snip>
597
    from .vm.interpreter import MAX_INIT_CODE_SIZE
598
599
    intrinsic = calculate_intrinsic_cost(tx, sender)
600
    intrinsic_gas = Uint(intrinsic.regular)
601
    if intrinsic_gas > tx.gas:
602
        raise InsufficientTransactionGasError("Insufficient intrinsic gas")
603
    if intrinsic.calldata_floor > tx.gas:
604
        raise InsufficientTransactionGasError("Insufficient calldata floor")
605
    if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
606
        raise InitCodeTooLargeError("Code size too large")
607
    if intrinsic.regular > TX_MAX_GAS_LIMIT:
608
        raise InsufficientTransactionGasError(
609
            "Intrinsic regular gas exceeds TX_MAX_GAS_LIMIT"
610
        )
611
    if intrinsic.calldata_floor > TX_MAX_GAS_LIMIT:
612
        raise InsufficientTransactionGasError(
613
            "Intrinsic calldata floor exceeds TX_MAX_GAS_LIMIT"
614
        )
615
    if U256(tx.nonce) >= U256(U64.MAX_VALUE):
616
        raise NonceOverflowError("Nonce too high")
617
618
    return intrinsic

calculate_intrinsic_cost

Calculates the gas that is charged before execution is started.

The intrinsic cost of the transaction is charged before execution has begun. Functions/operations in the EVM cost money to execute so this intrinsic cost is for the operations that need to be paid for as part of the transaction. Data transfer, for example, is part of this intrinsic cost. It costs ether to send data over the wire and that ether is accounted for in the intrinsic cost calculated in this function. This intrinsic cost must be calculated and paid for before execution in order for all operations to be implemented.

The intrinsic cost includes:

  1. Sender cost (TX_BASE).

  2. Recipient cost (COLD_ACCOUNT_ACCESS for a non-self-transfer call, or CREATE_ACCESS for a contract creation). The created account's NEW_ACCOUNT state gas is state-dependent and is charged at the top frame, not here.

  3. Value cost (TRANSFER_LOG_COST, plus TX_VALUE_COST for a non-self-transfer call) when tx.value > 0.

  4. Calldata cost (zero and non-zero bytes).

  5. Access list entries (if applicable).

  6. Authorizations (if applicable): only the state-independent base cost (REGULAR_PER_AUTH_BASE_COST) per tuple. The state-dependent account-creation and delegation-write costs are charged at the top frame by set_delegation.

Self-transfers (sender == tx.to) skip the recipient and value charges.

This function takes a transaction and its sender as parameters and returns the intrinsic regular gas cost and the minimum (floor) gas cost based on the calldata size. The floor is anchored on the regular-gas portion of items 1 to 3 above rather than TX_BASE alone, so it never undercuts the transaction's own intrinsic base.

def calculate_intrinsic_cost(tx: Transaction, ​​sender: Address) -> IntrinsicGasCost:
624
    <snip>
660
    from .vm.gas import GasCosts, init_code_cost
661
662
    tokens_in_calldata = count_tokens_in_data(tx.data)
663
664
    data_cost = tokens_in_calldata * GasCosts.TX_DATA_TOKEN_STANDARD
665
666
    is_create = tx.to == Bytes0(b"")
667
    is_self_transfer = tx.to == sender
668
669
    recipient_regular_gas = Uint(0)
670
    init_code_gas = Uint(0)
671
    if is_create:
672
        recipient_regular_gas = GasCosts.CREATE_ACCESS
673
        init_code_gas = init_code_cost(ulen(tx.data))
674
        if tx.value > U256(0):
675
            recipient_regular_gas += GasCosts.TRANSFER_LOG_COST
676
    elif not is_self_transfer:
677
        recipient_regular_gas = GasCosts.COLD_ACCOUNT_ACCESS
678
        if tx.value > U256(0):
679
            recipient_regular_gas += (
680
                GasCosts.TRANSFER_LOG_COST + GasCosts.TX_VALUE_COST
681
            )
682
683
    access_list_cost = Uint(0)
684
    tokens_in_access_list = Uint(0)
685
    if has_access_list(tx):
686
        for access in tx.access_list:
687
            access_list_cost += GasCosts.TX_ACCESS_LIST_ADDRESS
688
            access_list_cost += (
689
                ulen(access.slots) * GasCosts.TX_ACCESS_LIST_STORAGE_KEY
690
            )
691
            tokens_in_access_list += ACCESS_LIST_ADDRESS_FLOOR_TOKENS
692
            tokens_in_access_list += (
693
                ulen(access.slots) * ACCESS_LIST_STORAGE_KEY_FLOOR_TOKENS
694
            )
695
696
    # Data token floor cost for access list bytes.
697
    access_list_cost += tokens_in_access_list * GasCosts.TX_DATA_TOKEN_FLOOR
698
699
    auth_cost = Uint(0)
700
    if isinstance(tx, SetCodeTransaction):
701
        auth_cost = GasCosts.REGULAR_PER_AUTH_BASE_COST * ulen(
702
            tx.authorizations
703
        )
704
705
    # EIP-7976 floor tokens: all calldata bytes count uniformly.
706
    floor_tokens_in_calldata = ulen(tx.data) * GasCosts.TX_DATA_TOKEN_STANDARD
707
708
    # Total floor tokens.
709
    total_floor_tokens = floor_tokens_in_calldata + tokens_in_access_list
710
711
    # Decomposed regular-gas intrinsic base (EIP-2780), which also anchors
712
    # the calldata floor.
713
    base_regular_gas = GasCosts.TX_BASE + recipient_regular_gas
714
715
    # Floor gas cost (EIP-7623: minimum gas for data-heavy transactions).
716
    data_floor_gas_cost = (
717
        total_floor_tokens * GasCosts.TX_DATA_TOKEN_FLOOR + base_regular_gas
718
    )
719
720
    return IntrinsicGasCost(
721
        regular=RegularGas(
722
            base_regular_gas
723
            + init_code_gas
724
            + data_cost
725
            + access_list_cost
726
            + auth_cost
727
        ),
728
        calldata_floor=RegularGas(data_floor_gas_cost),
729
    )

count_tokens_in_data

Count the data tokens in arbitrary input bytes.

Zero bytes count as 1 token; non-zero bytes count as 4 tokens.

def count_tokens_in_data(data: bytes) -> Uint:
733
    <snip>
738
    num_zeros = Uint(data.count(0))
739
    num_non_zeros = ulen(data) - num_zeros
740
741
    return num_zeros + num_non_zeros * Uint(4)

chain_id

Extract the chain identifier from a transaction. See EIP-155.

def chain_id(tx: Transaction) -> None | U64:
745
    <snip>
750
    if isinstance(tx, LegacyTransaction):
751
        if tx.v == 27 or tx.v == 28:
752
            return None
753
754
        if tx.v < U256(35):
755
            raise InvalidSignatureError("bad v")
756
757
        return U64((tx.v - U256(35)) >> U256(1))
758
    else:
759
        return tx.chain_id

recover_sender

Extracts the sender address from a transaction.

The v, r, and s values are the three parts that make up the signature of a transaction. In order to recover the sender of a transaction the two components needed are the signature (v, r, and s) and the signing hash of the transaction. The sender's public key can be obtained with these two values and therefore the sender address can be retrieved.

This function takes chain_id and a transaction as parameters and returns the address of the sender of the transaction. It raises an InvalidSignatureError if the signature values (r, s, v) are invalid.

def recover_sender(tx: Transaction) -> Address:
763
    <snip>
776
    r, s = tx.r, tx.s
777
    if U256(0) >= r or r >= SECP256K1N:
778
        raise InvalidSignatureError("bad r")
779
    if U256(0) >= s or s > SECP256K1N // U256(2):
780
        raise InvalidSignatureError("bad s")
781
782
    if isinstance(tx, LegacyTransaction):
783
        v = tx.v
784
        if v == 27 or v == 28:
785
            public_key = secp256k1_recover(
786
                r, s, v - U256(27), signing_hash_pre155(tx)
787
            )
788
        else:
789
            assert v >= U256(35), "call chain_id before recover_sender"
790
            tx_chain_id = U64((v - U256(35)) >> U256(1))
791
            v = (v - U256(35)) & U256(1)
792
            public_key = secp256k1_recover(
793
                r,
794
                s,
795
                v,
796
                signing_hash_155(tx, tx_chain_id),
797
            )
798
    elif isinstance(tx, AccessListTransaction):
799
        if tx.y_parity not in (U256(0), U256(1)):
800
            raise InvalidSignatureError("bad y_parity")
801
        public_key = secp256k1_recover(
802
            r, s, tx.y_parity, signing_hash_2930(tx)
803
        )
804
    elif isinstance(tx, FeeMarketTransaction):
805
        if tx.y_parity not in (U256(0), U256(1)):
806
            raise InvalidSignatureError("bad y_parity")
807
        public_key = secp256k1_recover(
808
            r, s, tx.y_parity, signing_hash_1559(tx)
809
        )
810
    elif isinstance(tx, BlobTransaction):
811
        if tx.y_parity not in (U256(0), U256(1)):
812
            raise InvalidSignatureError("bad y_parity")
813
        public_key = secp256k1_recover(
814
            r, s, tx.y_parity, signing_hash_4844(tx)
815
        )
816
    elif isinstance(tx, SetCodeTransaction):
817
        if tx.y_parity not in (U256(0), U256(1)):
818
            raise InvalidSignatureError("bad y_parity")
819
        public_key = secp256k1_recover(
820
            r, s, tx.y_parity, signing_hash_7702(tx)
821
        )
822
823
    return Address(keccak256(public_key)[12:32])

signing_hash_pre155

Compute the hash of a transaction used in a legacy (pre EIP-155) signature.

This function takes a legacy transaction as a parameter and returns the signing hash of the transaction.

def signing_hash_pre155(tx: LegacyTransaction) -> Hash32:
827
    <snip>
836
    return keccak256(
837
        rlp.encode(
838
            (
839
                tx.nonce,
840
                tx.gas_price,
841
                tx.gas,
842
                tx.to,
843
                tx.value,
844
                tx.data,
845
            )
846
        )
847
    )

signing_hash_155

Compute the hash of a transaction used in a EIP-155 signature.

This function takes a legacy transaction and a chain ID as parameters and returns the hash of the transaction used in an EIP-155 signature.

def signing_hash_155(tx: LegacyTransaction, ​​chain_id: U64) -> Hash32:
851
    <snip>
859
    return keccak256(
860
        rlp.encode(
861
            (
862
                tx.nonce,
863
                tx.gas_price,
864
                tx.gas,
865
                tx.to,
866
                tx.value,
867
                tx.data,
868
                chain_id,
869
                Uint(0),
870
                Uint(0),
871
            )
872
        )
873
    )

signing_hash_2930

Compute the hash of a transaction used in a EIP-2930 signature.

This function takes an access list transaction as a parameter and returns the hash of the transaction used in an EIP-2930 signature.

def signing_hash_2930(tx: AccessListTransaction) -> Hash32:
877
    <snip>
885
    return keccak256(
886
        b"\x01"
887
        + rlp.encode(
888
            (
889
                tx.chain_id,
890
                tx.nonce,
891
                tx.gas_price,
892
                tx.gas,
893
                tx.to,
894
                tx.value,
895
                tx.data,
896
                tx.access_list,
897
            )
898
        )
899
    )

signing_hash_1559

Compute the hash of a transaction used in an EIP-1559 signature.

This function takes a fee market transaction as a parameter and returns the hash of the transaction used in an EIP-1559 signature.

def signing_hash_1559(tx: FeeMarketTransaction) -> Hash32:
903
    <snip>
911
    return keccak256(
912
        b"\x02"
913
        + rlp.encode(
914
            (
915
                tx.chain_id,
916
                tx.nonce,
917
                tx.max_priority_fee_per_gas,
918
                tx.max_fee_per_gas,
919
                tx.gas,
920
                tx.to,
921
                tx.value,
922
                tx.data,
923
                tx.access_list,
924
            )
925
        )
926
    )

signing_hash_4844

Compute the hash of a transaction used in an EIP-4844 signature.

This function takes a transaction as a parameter and returns the signing hash of the transaction used in an EIP-4844 signature.

def signing_hash_4844(tx: BlobTransaction) -> Hash32:
930
    <snip>
938
    return keccak256(
939
        b"\x03"
940
        + rlp.encode(
941
            (
942
                tx.chain_id,
943
                tx.nonce,
944
                tx.max_priority_fee_per_gas,
945
                tx.max_fee_per_gas,
946
                tx.gas,
947
                tx.to,
948
                tx.value,
949
                tx.data,
950
                tx.access_list,
951
                tx.max_fee_per_blob_gas,
952
                tx.blob_versioned_hashes,
953
            )
954
        )
955
    )

signing_hash_7702

Compute the hash of a transaction used in a EIP-7702 signature.

This function takes a transaction as a parameter and returns the signing hash of the transaction used in a EIP-7702 signature.

def signing_hash_7702(tx: SetCodeTransaction) -> Hash32:
959
    <snip>
967
    return keccak256(
968
        b"\x04"
969
        + rlp.encode(
970
            (
971
                tx.chain_id,
972
                tx.nonce,
973
                tx.max_priority_fee_per_gas,
974
                tx.max_fee_per_gas,
975
                tx.gas,
976
                tx.to,
977
                tx.value,
978
                tx.data,
979
                tx.access_list,
980
                tx.authorizations,
981
            )
982
        )
983
    )

get_transaction_hash

Compute the hash of a transaction.

This function takes a transaction as a parameter and returns the keccak256 hash of the transaction. It can handle both legacy transactions and typed transactions (AccessListTransaction, FeeMarketTransaction, etc.).

def get_transaction_hash(tx: Bytes | LegacyTransaction) -> Hash32:
987
    <snip>
995
    assert isinstance(tx, (LegacyTransaction, Bytes))
996
    if isinstance(tx, LegacyTransaction):
997
        return keccak256(rlp.encode(tx))
998
    else:
999
        return keccak256(tx)

has_access_list

Return whether the transaction has an EIP-2930-style access list.

def has_access_list(tx: Transaction) -> TypeGuard[AccessListCapableTransaction]:
1005
    <snip>
1010
    return isinstance(
1011
        tx,
1012
        AccessListCapableTransaction,
1013
    )