# `EEVM.TxEnv`
[🔗](https://github.com/mw2000/eevm/blob/v0.1.0/lib/eevm/tx_env.ex#L1)

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

| Field | Opcode | Description |
|-------|--------|-------------|
| `type` | — | `:legacy`, `:eip2930`, `:eip1559`, `:eip4844`, or `:eip7702` |
| `origin` | ORIGIN (0x32) | The externally owned account (EOA) that signed the tx, or the impersonated sender |
| `gas_price` | GASPRICE (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_hashes` | BLOBHASH (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.

# `authorization`

```elixir
@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`

```elixir
@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()
}
```

# `new`

```elixir
@spec new() :: t()
```

Creates a new transaction environment with default values.

# `new`

```elixir
@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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
