# `Cartouche.Transaction.V_2930`
[🔗](https://github.com/ZenHive/onchain-stack/blob/cartouche-v0.9.0/packages/cartouche/lib/cartouche/transaction/v_2930.ex#L2)

Represents a type-1 EIP-2930 access-list transaction.

## Examples

    iex> tx =
    ...>   Cartouche.Transaction.V_2930.new(
    ...>     1,
    ...>     {1, :gwei},
    ...>     100_000,
    ...>     <<1::160>>,
    ...>     {2, :wei},
    ...>     <<1, 2, 3>>,
    ...>     [],
    ...>     :goerli
    ...>   )
    ...> tx = Cartouche.Transaction.V_2930.add_signature(tx, true, <<0x01::256>>, <<0x02::256>>)
    iex> {:ok, decoded} = tx |> Cartouche.Transaction.V_2930.encode() |> Cartouche.Transaction.V_2930.decode()
    iex> decoded == tx
    true

# `access_list`

```elixir
@type access_list() :: [{&lt;&lt;_::160&gt;&gt;, [&lt;&lt;_::256&gt;&gt;]}]
```

# `t`

```elixir
@type t() :: %Cartouche.Transaction.V_2930{
  access_list: access_list(),
  amount: non_neg_integer(),
  chain_id: non_neg_integer(),
  data: binary(),
  destination: &lt;&lt;_::160&gt;&gt; | nil,
  gas_limit: non_neg_integer(),
  gas_price: non_neg_integer(),
  nonce: non_neg_integer(),
  signature_r: &lt;&lt;_::256&gt;&gt; | nil,
  signature_s: &lt;&lt;_::256&gt;&gt; | nil,
  signature_y_parity: boolean() | nil
}
```

# `add_signature`

```elixir
@spec add_signature(t(), &lt;&lt;_::512, _::_*8&gt;&gt;) :: t()
```

Adds a signature to a transaction from a packed binary (`r <> s <> v`).

# `add_signature`

```elixir
@spec add_signature(t(), boolean(), &lt;&lt;_::256&gt;&gt;, &lt;&lt;_::256&gt;&gt;) :: t()
```

Adds explicit signature fields to a transaction.

# `decode`

```elixir
@spec decode(binary()) :: {:ok, t()} | {:error, String.t()}
```

Decodes an EIP-2930 typed RLP transaction.

# `encode`

```elixir
@spec encode(t()) :: binary()
```

Build an EIP-2718 typed RLP-encoded access-list transaction.

Signed payloads are `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to,
value, data, accessList, yParity, r, s])` per EIP-2930. If any signature
field is `nil`, the encoded payload omits `yParity`, `r`, and `s` and is the
signing preimage `0x01 || rlp([chainId, nonce, gasPrice, gasLimit, to, value,
data, accessList])`.

# `from_json`

```elixir
@spec from_json(map()) :: t() | no_return()
```

Decodes an EIP-2930 (type 1) transaction object from block JSON-RPC.

# `get_signature`

```elixir
@spec get_signature(t()) :: {:ok, binary()} | {:error, String.t()}
```

Recovers a signature from a transaction, if it has been signed.

# `hash`

```elixir
@spec hash(t()) :: &lt;&lt;_::256&gt;&gt;
```

Hashes the typed transaction bytes.

# `new`

```elixir
@spec new(
  non_neg_integer(),
  non_neg_integer() | {non_neg_integer(), :wei | :gwei},
  non_neg_integer(),
  &lt;&lt;_::160&gt;&gt;,
  non_neg_integer() | {non_neg_integer(), :wei | :gwei},
  binary(),
  access_list(),
  atom() | integer() | nil
) :: t()
```

Constructs an unsigned EIP-2930 access-list transaction.

# `recover_signer`

```elixir
@spec recover_signer(t()) :: {:ok, &lt;&lt;_::160&gt;&gt;} | {:error, String.t()}
```

Recovers the signer from a signed type-1 transaction.

# `sign`

```elixir
@spec sign(t(), GenServer.server()) :: {:ok, t()} | {:error, String.t()}
```

Signs a type-1 transaction with the given signer process.

---

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