eth_tx_codec
Serialize tx fields into a raw transaction, or decode a raw tx.
Instructions
Serialize tx fields into a raw transaction, or decode a raw tx.
action=encode (needs fields) serializes the supplied fields (it does not
sign) -> {type, raw:'0x...', hash, signing_hash}. fields is an object; the
type is taken from a type key or inferred from which fields are present
(maxFeePerGas -> 1559, blobVersionedHashes -> 4844, accessList -> 2930, else
legacy). Numbers accept int / decimal / 0x-hex; to/data are 0x-hex.
action=decode (needs data, a 0x-hex raw tx) -> {type, fields, hash,
signing_hash, from}, recovering from from the signature; numeric fields
come back as decimal strings, addresses EIP-55 checksummed.
signing_hash is the digest the sender signs: keccak256 of the payload
without the signature (typed: type_byte || rlp(fields minus yParity/r/s);
legacy EIP-155: rlp(fields[:6] + [chainId, 0, 0]); pre-EIP-155:
rlp(fields[:6])). hash is the tx hash, which covers the signature too, so
it is only meaningful once signed. To sign: encode the unsigned fields, sign
signing_hash with eth_sign, then encode again with r, s and yParity —
legacy instead takes v = chainId*2 + 35 + yParity (27 + yParity
pre-EIP-155).
Example: eth_tx_codec("encode", fields={"nonce":0,"gasPrice":"0x09184e72a000", "gasLimit":"0x2710","to":"0x00..00","value":0,"data":"0x"}) -> type=0, raw="0xe5808609184e72a00082271094...808080".
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| data | No | 0x-prefixed raw transaction bytes to decode (required for action=decode): a legacy RLP list or an EIP-2718 typed envelope. | |
| action | Yes | 'encode' signed fields into a raw tx, or 'decode' a raw tx. | |
| fields | No | Tx fields object (required for action=encode); does NOT sign. Omit v/yParity/r/s for an unsigned tx, whose `signing_hash` is what to sign; a legacy tx's `chainId` makes it EIP-155 (it is carried in v, so a signed legacy v must encode it). The type comes from a `type` key or is inferred (maxFeePerGas->1559, blobVersionedHashes->4844, accessList->2930, else legacy). Numbers accept int/decimal/0x-hex; `to`/`data` are 0x-hex. A stringified JSON object is accepted. |