# `Cartouche.Trace.Action`
[🔗](https://github.com/zenhive/cartouche/blob/main/lib/cartouche/trace.ex#L17)

A single sub-action inside a `Cartouche.Trace` — the `call`, `create`,
or `suicide` operation the traced transaction performed at one frame of
its call graph (from, to, value, gas, input, and call-type metadata).

# `t`

```elixir
@type t() :: %Cartouche.Trace.Action{
  balance: integer() | nil,
  call_type: String.t() | nil,
  from: &lt;&lt;_::160&gt;&gt; | nil,
  gas: integer() | nil,
  init: binary() | nil,
  input: binary() | nil,
  refund_address: binary() | nil,
  to: &lt;&lt;_::160&gt;&gt; | nil,
  value: integer() | nil
}
```

# `deserialize`

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

Deserializes a trace sub-action into a struct.

## Examples

    iex> use Cartouche.Hex
    iex> %{
    ...>   "callType" => "call",
    ...>   "from" => "0x83806d539d4ea1c140489a06660319c9a303f874",
    ...>   "gas" => "0x1a1f8",
    ...>   "input" => "0x",
    ...>   "to" => "0x1c39ba39e4735cb65978d4db400ddd70a72dc750",
    ...>   "value" => "0x7a16c911b4d00000"
    ...> }
    ...> |> Cartouche.Trace.Action.deserialize()
    %Cartouche.Trace.Action{
      call_type: "call",
      from: ~h[0x83806d539d4ea1c140489a06660319c9a303f874],
      gas: 0x01a1f8,
      input: <<>>,
      to: ~h[0x1c39ba39e4735cb65978d4db400ddd70a72dc750],
      value: 0x7a16c911b4d00000,
    }

    iex> use Cartouche.Hex
    iex> %{
    ...>   "callType" => "call",
    ...>   "from" => "0x0000000000000000000000000000000000000000",
    ...>   "gas" => "0x1dcd0f58",
    ...>   "input" =>
    ...>     "0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000",
    ...>   "to" => "0x13172ee393713fba9925a9a752341ebd31e8d9a7",
    ...>   "value" => "0x0"
    ...> }
    ...> |> Cartouche.Trace.Action.deserialize()
    %Cartouche.Trace.Action{
      call_type: "call",
      from: ~h[0x0000000000000000000000000000000000000000],
      gas: 0x1dcd0f58,
      input: ~h[0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000],
      to: ~h[0x13172ee393713fba9925a9a752341ebd31e8d9a7],
      value: 0x0,
    }

    iex> use Cartouche.Hex
    iex> %{
    ...>   "address" => "0x1a6b1b60d09944d56d39ef53a6b81097615f5ee4",
    ...>   "balance" => "0x0",
    ...>   "refundAddress" => "0x0000000000b3f879cb30fe243b4dfee438691c04"
    ...> }
    ...> |> Cartouche.Trace.Action.deserialize()
    %Cartouche.Trace.Action{
      refund_address: ~h[0x0000000000b3f879cb30fe243b4dfee438691c04],
      balance: 0x0,
    }

# `serialize`

```elixir
@spec serialize(t()) :: map()
```

Serializes a struct into a json map.

## Examples

    iex> use Cartouche.Hex
    iex> %Cartouche.Trace.Action{
    ...>   call_type: "call",
    ...>   from: ~h[0x83806d539d4ea1c140489a06660319c9a303f874],
    ...>   gas: 0x01a1f8,
    ...>   input: <<>>,
    ...>   to: ~h[0x1c39ba39e4735cb65978d4db400ddd70a72dc750],
    ...>   value: 0x7a16c911b4d00000,
    ...> }
    ...> |> Cartouche.Trace.Action.serialize()
    %{
      from: "0x83806d539D4Ea1c140489A06660319C9A303f874",
      gas: "0x1A1F8",
      input: "0x",
      to: "0x1C39BA39e4735CB65978d4Db400dDD70a72DC750",
      value: "0x7A16C911B4D00000",
      callType: "call",
      init: nil
    }

---

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