EEVM.TxEnv (eevm v0.1.0)

Copy Markdown View Source

The transaction environment code executes in: the signed transaction as the EVM sees it. EEVM.transact/4 builds one from the wire transaction. Set it yourself to give bytecode run with EEVM.run/2 a transaction context, through its :tx option, or to simulate a transaction from any address: EEVM.transact/4 also takes an unsigned TxEnv and treats its origin as the sender, without a signature. Set gas_price for a legacy or EIP-2930 type, and the max_* fee fields for the others.

Fields

FieldOpcodeDescription
type—:legacy, :eip2930, :eip1559, :eip4844, or :eip7702
originORIGIN (0x32)The externally owned account (EOA) that signed the tx, or the impersonated sender
gas_priceGASPRICE (0x3A)Effective gas price in wei the sender pays
nonce—The sender's nonce
gas_limit—The transaction's gas limit
to—The recipient address, or nil for a contract creation
value—Wei sent with the call
data—Calldata, or initcode for a creation
max_fee_per_gas, max_priority_fee_per_gas—EIP-1559 fee caps in wei
max_fee_per_blob_gas—EIP-4844 blob fee cap in wei
blob_hashesBLOBHASH (0x49)List of blob versioned hashes from EIP-4844 transaction payload
access_list—EIP-2930 [{address, [slot]}] warmed before execution
authorization_list—EIP-7702 authorizations applied before execution

Origin vs Caller

origin is always the EOA that signed the transaction — it never changes, even through nested contract calls. The caller (CALLER, and EEVM.run/2's :caller option) is the direct caller of the current frame and changes with each CALL.

Summary

Functions

Creates a new transaction environment with default values.

Creates a new transaction environment with the given overrides.

Types

authorization()

@type authorization() :: %{
  chain_id: non_neg_integer(),
  address: non_neg_integer(),
  nonce: non_neg_integer(),
  y_parity: 0..255,
  r: non_neg_integer(),
  s: non_neg_integer()
}

t()

@type t() :: %EEVM.TxEnv{
  access_list: [{non_neg_integer(), [non_neg_integer()]}],
  authorization_list: [authorization()],
  blob_hashes: [non_neg_integer()],
  data: binary(),
  gas_limit: non_neg_integer(),
  gas_price: non_neg_integer(),
  max_fee_per_blob_gas: non_neg_integer(),
  max_fee_per_gas: non_neg_integer(),
  max_priority_fee_per_gas: non_neg_integer(),
  nonce: non_neg_integer(),
  origin: non_neg_integer(),
  to: non_neg_integer() | nil,
  type: :legacy | :eip2930 | :eip1559 | :eip4844 | :eip7702,
  value: non_neg_integer()
}

Functions

new()

@spec new() :: t()

Creates a new transaction environment with default values.

new(opts)

@spec new(keyword()) :: t()

Creates a new transaction environment with the given overrides.

Example

iex> tx = EEVM.TxEnv.new(origin: 0xDEAD, gas_price: 20_000_000_000)
iex> tx.origin
0xDEAD