A struct that wraps a transaction and its signature values.
Summary
Types
A transaction signature envelope that wraps transaction data with its signature components.
Functions
Calculates the y-parity or v value for transaction signatures.
Calculates the from address of a signed transaction using its signature.
Types
@type t() :: %Ethers.Transaction.Signed{ metadata: Ethers.Transaction.Metadata.t() | nil, payload: Ethers.Transaction.t_payload(), signature_r: binary(), signature_s: binary(), signature_y_parity_or_v: non_neg_integer() }
A transaction signature envelope that wraps transaction data with its signature components.
This type supports Legacy (pre-EIP-155 and EIP-155) transactions as well as all typed transactions (EIP-2930, EIP-1559, EIP-4844 and EIP-7702). The signature components consist of:
signature_r,signature_s: The ECDSA signature values as defined in Ethereum's Yellow Papersignature_y_parity_or_v: The recovery value that varies by transaction type:- For pre-EIP-155 Legacy transactions: v = recovery_id + 27
- For EIP-155 Legacy transactions: v = recovery_id + chain_id * 2 + 35
- For typed transactions (EIP-2930, EIP-1559, EIP-4844, EIP-7702): the y-parity, which is just the recovery_id (0 or 1), as introduced in EIP-2930
Related EIPs:
Functions
@spec calculate_y_parity_or_v(Ethers.Transaction.t_payload(), non_neg_integer()) :: non_neg_integer()
Calculates the y-parity or v value for transaction signatures.
Handles legacy (pre-EIP-155 and EIP-155) and typed (EIP-2930, EIP-1559, EIP-4844 and EIP-7702) transactions according to their specifications.
Parameters
tx- Transaction structrecovery_id- Recovery ID from the signature (0 or 1)
Returns
integer- Calculated y-parity or v value
@spec from_address(t()) :: {:ok, Ethers.Types.t_address()} | {:error, atom()}
Calculates the from address of a signed transaction using its signature.
The from address is inferred from the signature of the transaction rather than being explicitly specified. This is done by recovering the signer's public key from the signature and then deriving the corresponding Ethereum address.
Returns
{:ok, address}- Successfully recovered from address (checksummed){:error, :invalid_recovery_id}- The signature's v / y-parity does not give a recovery id of 0 or 1{:error, reason}- Failed to recover address (e.g.:invalid_ror:invalid_s)