Repository navigation
Return Ethers.Transaction.Unknown for unregistered transaction types - #308
Merged
Merged
Conversation
Ethers.Transaction.from_rpc_map/1, and so Ethers.get_transaction/2 and
the batch :get_transaction action, returned {:error, :unsupported_type}
for any transaction type without a registered module. On L2s such types
are common (OP-stack deposit transactions are in every block), so code
scanning blocks or looking up arbitrary hashes could not read them.
Such transactions now decode into the read-only Ethers.Transaction.Unknown
passthrough struct: the numeric type id, the common fields (hash, from,
to, nonce, value, gas, input, chain_id) and block metadata decoded where
present, and the original RPC map in raw for type specific fields. Fields
with values that cannot be decoded are left nil instead of failing the
lookup. Encoding, hashing and to_rpc_map/1 raise an ArgumentError naming
the type. Registered types decode as before, and a type that is not a hex
quantity returns {:error, :invalid_type}.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Align Ethers.Transaction.Unknown with the library rule that every returned address is EIP-55 checksummed: accept the 0X prefix like Ethers.Utils.maybe_checksum_address/1 does, and test that from and to come back checksummed whatever casing the node uses. Malformed values still leave the field nil, with the original value kept in raw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
alisinabh
force-pushed
the
feat/unknown-transaction-types
branch
from
November 15, 2026 23:16
fb9c4ad to
55390c4
Compare
alisinabh
commented
Nov 16, 2026
alisinabh
commented
Nov 16, 2026
Since future transaction types cannot be anticipated, Unknown no longer
guesses at common fields. It keeps only the type id, block metadata and
the transaction as it was read:
- rpc_map: the JSON-RPC object, unchanged, from from_rpc_map/1
- raw_payload: the EIP-2718 TransactionPayload, undecoded, from decode/1
Transaction.decode/1 now returns an Unknown for a first byte in
0x01..0x7f without a registered module instead of
{:error, :unsupported_transaction_type}; a 0x00 type byte is still
rejected since legacy transactions have no type byte. An Unknown with
raw_payload encodes back to its bytes and hashes like any EIP-2718
transaction. One read from an RPC map still raises ArgumentError on
encode/1 and transaction_hash/2, to_rpc_map/1 raises for both, and
signing raises instead of producing a transaction with an unknown
signature layout.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ethers.Transaction.from_rpc_map/1(and soEthers.get_transaction/2and the batch:get_transactionaction) returned{:error, :unsupported_type}for any transaction type without a registered module, andEthers.Transaction.decode/1returned{:error, :unsupported_transaction_type}. On L2s such types are common (OP-stack deposit transactions, type0x7e, are in every block), so code that scans blocks, looks up arbitrary hashes or reads raw transactions could not handle them.Such transactions now come back as
Ethers.Transaction.Unknown, which keeps them undecoded.The struct
type_id: the numeric transaction typerpc_map: the JSON-RPC transaction object exactly as the node returned it, set byfrom_rpc_map/1raw_payload: the EIP-2718TransactionPayload(the bytes after the type byte), undecoded, set bydecode/1metadata: anEthers.Transaction.Metadata(block hash, block number, transaction index) read from the RPC map, the same structEthers.Transaction.Signedcarries for registered types; nil when decoded from bytesDesign decisions
hash,from,to, etc. are read fromrpc_map(e.g.transaction.rpc_map["hash"]).rpc_mapandraw_payloadeach have a single type; exactly one is set depending on where the transaction came from.decode/1. A first byte in0x01..0x7fwithout a registered module returns{:ok, %Unknown{type_id: byte, raw_payload: rest}}without validating the payload. A0x00first byte still returns{:error, :unsupported_transaction_type}: type 0 is legacy, which has no type byte (geth rejects it too).Unknownwithraw_payloadencodes back to<<type_id, raw_payload::binary>>andtransaction_hash/2returns the keccak hash of those bytes, as for any EIP-2718 transaction. One with onlyrpc_mapraisesArgumentErrorfor both (the hash message points atrpc_map["hash"]).to_rpc_map/1raises for both.Ethers.Transaction.Protocolis implemented with the realtype_id/1andtype_envelope/1(<<type_id>>for0x00..0x7f), andto_rlp_list/2raisesUnsupported transaction type 0x7E: Ethers.Transaction.Unknown cannot be signed or converted to an RLP list, which is whatEthers.Signer.Localhits.Ethers.Signer.JsonRPCfails onto_rpc_map/1.typeis parsed as an integer quantity and matched against each registered module'stype_id/0. Types registered through the compile-time:transaction_typesconfig take precedence overUnknown. Registered types decode exactly as before.Ethers.Transaction.t()now includesEthers.Transaction.Unknown.t();t_payload()is unchanged.Breaking change
Ethers.Transaction.from_rpc_map/1,Ethers.get_transaction/2and the batch:get_transactionaction return{:ok, %Ethers.Transaction.Unknown{}}for an unregistered transaction type instead of{:error, :unsupported_type}.{:error, :unsupported_type}is no longer returned: atypethat is not a hex quantity now returns{:error, :invalid_type}.Ethers.Transaction.decode/1returns{:ok, %Ethers.Transaction.Unknown{}}for an unregistered type byte instead of{:error, :unsupported_transaction_type}(still returned for a0x00type byte).Edge inputs for the RPC
type:type"0x7e"(unregistered){:error, :unsupported_type}{:ok, %Unknown{type_id: 0x7E}}"0x0002"{:error, :unsupported_type}Eip1559"0x"Legacy{:error, :invalid_type}"0xzz"ArgumentError{:error, :invalid_type}2,"7e"(not0xhex){:error, :unsupported_type}{:error, :invalid_type}LegacyLegacyDocumented in
CHANGELOG.mdandguides/upgrading.md.Tests and verification
eth_getTransactionByHashresponse for the OP Mainnet L1 attributes deposit transaction0x47b7a389d253158f3f2cb367dfd23eba2f95f641a3b671651515a673628d7c50(block 159588978), fetched from the public OP Mainnet RPC. Its fields match the OP-stack deposits specification and op-geth's RPC transaction encoding.0x7e || rlp([sourceHash, from, to, mint, value, gas, isSystemTx, data])(the public RPC does not expose raw transactions).decode/1returns it as anUnknown,encode/1round-trips it, andtransaction_hash/2returns the real OP Mainnet transaction hash.:invalid_type, payloads that are not validated, the0x00type byte, theArgumentErrormessages for encode/hash/to_rpc_map/signing, registered types unaffected, andEthers.get_transaction/2,get_transaction!/2andEthers.batch/2through a stub RPC client.anvil --network optimism(1.6.0-nightly), a deposit transaction sent witheth_sendTransactioncomes back fromEthers.get_transaction/2and the batch action as anUnknownwith the node's map. CI runs a single plain anvil, so no live test was added. (That anvil panics ondebug_getRawTransactionfor deposits, so the raw-bytes path could only be checked against the spec-encoded fixture.)0x7emodule registered in:transaction_types(compiled in a scratch copy),from_rpc_map/1returns the custom struct and other unregistered types still returnUnknown.Known follow-ups
hashandfromfrom the RPC map.Ethers.send_transaction/2andEthers.sign_transaction/2takeTxDataor parameter maps; passing any transaction struct (anUnknownas much as anEip1559) fails with aCollectableprotocol error, and atype: Ethers.Transaction.Unknownoverride fails with anUndefinedFunctionError, as any module that is not a transaction type does today.Closes #292
🤖 Generated with Claude Code
https://claude.ai/code/session_012hqvX8DbbP3mgXy5hVEDc6