FromTxWithEncoded

Trait FromTxWithEncoded 

pub trait FromTxWithEncoded<Tx> {
    // Required method
    fn from_encoded_tx(tx: &Tx, sender: Address, encoded: Bytes) -> Self;
}
Available on crate feature evm only.
Expand description

Helper trait for building a transaction environment from a transaction with its encoded form.

This trait enables the conversion of consensus transaction types along with their EIP-2718 encoded bytes into the EVM’s transaction environment. It’s automatically used when a WithEncoded<Recovered<T>> type is passed to the EVM’s transact method.

The main purpose of this trait is to allow preserving the original encoded transaction data alongside the parsed transaction, which can be useful for:

  • Signature verification
  • Transaction hash computation
  • Re-encoding for network propagation
  • Optimism transaction handling (which requires encoded data, for Data availability costs).

§Implementation

Most implementations simply delegate to FromRecoveredTx, ignoring the encoded bytes. However, specialized implementations (like Optimism’s OpTransaction) may use the encoded data for additional functionality.

§Example

// Create a transaction with its encoded form
let encoded_bytes = tx.encoded_2718();
let recovered = tx.recover_signer()?;
let with_encoded = WithEncoded::new(recovered, encoded_bytes);

// The transaction with encoded data can be used with the EVM
evm.transact(with_encoded)?;

Required Methods§

fn from_encoded_tx(tx: &Tx, sender: Address, encoded: Bytes) -> Self

Builds a TxEnv from a transaction, its sender, and encoded transaction bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

§

impl FromTxWithEncoded<OpTxEnvelope> for OpTransaction<TxEnv>

§

impl FromTxWithEncoded<OpTxEnvelope> for TxEnv

§

impl FromTxWithEncoded<TxEip1559> for TxEnv

§

impl FromTxWithEncoded<TxEip2930> for TxEnv

§

impl FromTxWithEncoded<TxEip4844> for TxEnv

§

impl FromTxWithEncoded<TxEip7702> for TxEnv

§

impl FromTxWithEncoded<TxLegacy> for TxEnv

§

impl<Eip4844> FromTxWithEncoded<EthereumTxEnvelope<Eip4844>> for TxEnv
where Eip4844: AsRef<TxEip4844>,

§

impl<TxEnv, T> FromTxWithEncoded<&T> for TxEnv
where TxEnv: FromTxWithEncoded<T>,