# `Cartouche.RPC`
[🔗](https://github.com/zenhive/cartouche/blob/main/lib/cartouche/rpc.ex#L1)

Excessively simple RPC client for Ethereum.

# `call_trx`

```elixir
@spec call_trx(
  Cartouche.Transaction.V1.t() | Cartouche.Transaction.V2.t(),
  Keyword.t()
) ::
  {:ok, binary()} | {:error, term()}
```

RPC call to call a transaction and preview results.

## Examples

    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.call_trx()
    {:ok, <<0x0c>>}

    iex> Cartouche.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
    iex> |> Cartouche.RPC.call_trx()
    {:ok, <<0x0d>>}

    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.call_trx(decode: :hex_unsigned)
    {:ok, 0x0c}

    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<10::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.call_trx()
    {:error, %{code: 3, message: "execution reverted", revert: <<61, 115, 139, 46>>}}

    iex> errors = ["Unauthorized()", "BadNonce()", "NotEnoughSigners()", "NotActiveWithdrawalAddress()", "NotActiveOperator()", "DuplicateSigners()"]
    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<10::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.call_trx(errors: errors)
    {:error, %{code: 3, message: "execution reverted", error_abi: "NotActiveOperator()", error_params: [], revert: <<61, 115, 139, 46>>}}

    iex> errors = ["Cool(uint256,string)"]
    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<11::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.call_trx(errors: errors)
    {:error, %{code: 3, message: "execution reverted", error_abi: "Cool(uint256,string)", error_params: [1, "cat"], revert: ABI.encode("Cool(uint256,string)", [1, "cat"])}}

    iex> errors = ["Cool(uint256,string)"]
    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<12::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.call_trx(errors: errors)
    {:error, %{code: 3, message: "execution reverted", revert: <<>>}}

    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<13::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.call_trx()
    {:error, %{code: -32602, message: "Failed to decode transaction"}}

# `debug_trace_call`

```elixir
@spec debug_trace_call(
  Cartouche.Transaction.V1.t() | Cartouche.Transaction.V2.t(),
  Keyword.t()
) ::
  {:ok, Cartouche.DebugTrace.t()} | {:error, term()}
```

RPC to trace a transaction call speculatively via debug API.

## Examples

    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>)
    ...> |> Cartouche.RPC.debug_trace_call()
    {:ok,
      %Cartouche.DebugTrace{
      failed: false,
      gas: 24034,
      return_value: ~h[0x0000000000000000000000000000000000000000000000000858898f93629000],
      struct_logs: [
        %Cartouche.DebugTrace.StructLog{
          depth: 1,
          gas: 599978568,
          gas_cost: 3,
          op: :PUSH1,
          pc: 0,
          stack: []
        },
        %Cartouche.DebugTrace.StructLog{
          depth: 1,
          gas: 599978565,
          gas_cost: 3,
          op: :PUSH1,
          pc: 2,
          stack: [~h[0x80]]
        },
        %Cartouche.DebugTrace.StructLog{
          depth: 1,
          gas: 599978562,
          gas_cost: 12,
          op: :MSTORE,
          pc: 4,
          stack: [~h[0x80], ~h[0x40]]
        }
      ]
    }}

# `estimate_gas`

```elixir
@spec estimate_gas(
  Cartouche.Transaction.V1.t() | Cartouche.Transaction.V2.t(),
  Keyword.t()
) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

RPC call to call to estimate gas used by a given call.

## Examples

    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> |> Cartouche.RPC.estimate_gas()
    {:ok, 0x0d}

    iex> Cartouche.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
    iex> |> Cartouche.RPC.estimate_gas()
    {:ok, 0xdd}

    iex> use Cartouche.Hex
    iex> Cartouche.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<10::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
    iex> |> Cartouche.RPC.estimate_gas()
    {:error, %{code: 3, message: "execution reverted: Dai/insufficient-balance", revert: ~h[0x08c379a0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000184461692f696e73756666696369656e742d62616c616e63650000000000000000]}}

# `eth_block_number`

```elixir
@spec eth_block_number(Keyword.t()) :: {:ok, non_neg_integer()} | {:error, term()}
```

RPC to get the current block number.

Docs: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_blocknumber

## Examples

    iex> Cartouche.RPC.eth_block_number()
    {:ok, 0x44}

# `eth_chain_id`

```elixir
@spec eth_chain_id(Keyword.t()) :: {:ok, non_neg_integer()} | {:error, term()}
```

RPC to get the current chain id.

Docs: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_chainid

## Examples

    iex> Cartouche.RPC.eth_chain_id()
    {:ok, 0x22}

# `execute_trx`

```elixir
@spec execute_trx(&lt;&lt;_::160&gt;&gt;, binary() | {String.t(), [term()]}, Keyword.t()) ::
  {:ok, binary()} | {:error, term()}
```

Helper function to work with other Cartouche modules to get a nonce, sign a transction, and transmit it to the network.

If you need higher-level functionality, like manual nonce tracking, you may want to use the more granular function calls.

Options:
  * `gas_price` - Set the base gas for the transaction, overrides all other gas prices listed below (default `nil`) [note: only compatible with V1 transaction]
  * `base_fee` - Set the base price for the transaction, if nil, will use base gas price from `eth_gasPrice` call (default `nil`) [note: only compatible with V2 transactions]
  * `base_fee_buffer` - Buffer for the gas price when estimating gas (default: 1.2 = 120%) [note: only compatible with V2 transactions]
  * `priority_fee` - Additional gas to send as a priority fee. (default: `{0, :gwei}`) [note: only compatible with V2 transactions]
  * `gas_limit` - Set the gas limit for the transaction (default: calls `eth_estimateGas`)
  * `gas_buffer` - Buffer if estimating gas limit (default: 1.5 = 150%)
  * `value` - Value to provide with transaction in wei (default: 0)
  * `nonce` - Nonce to send with transaction. (default: lookup via `eth_transactionCount`)
  * `verify` - Verify the function is likely to succeed (default: true)
  * `trx_type` - :v1 for V1 (pre-EIP-1559 transactions), :v2 for V2 (EIP-1559) transactions, and `nil` for auto-detect.

  Note: if we don't `verify`, then `estimateGas` will likely fail if the transaction were to fail.
        To prevent this, `gas_limit` should always be supplied when `verify` is set to false.

## Examples
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx_id} = Cartouche.RPC.execute_trx(<<1::160>>, {"baz(uint,address)", [50, :binary.decode_unsigned(<<1::160>>)]}, gas_price: {50, :gwei}, value: 0, signer: signer_proc)
    iex> <<nonce::integer-size(8), gas_price::integer-size(64), gas_limit::integer-size(24), to::binary>> = trx_id
    iex> {nonce, gas_price, gas_limit, to}
    {4, 50000000000, 20, <<1::160>>}

    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> Cartouche.RPC.execute_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_price: {50, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, signer: signer_proc)
    {:error, %{code: 3, message: "execution reverted", revert: <<61, 115, 139, 46>>}}

    iex> # Set base fee and priority fee (v2)
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx_id} = Cartouche.RPC.execute_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, base_fee: {1, :gwei}, priority_fee: {3, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, verify: false, signer: signer_proc)
    iex> <<nonce::integer-size(8), max_priority_fee_per_gas::integer-size(64), max_fee_per_gas::integer-size(64), gas_limit::integer-size(24), to::binary>> = trx_id
    iex> {nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, to}
    {10, 3000000000, 4000000000, 100000, <<10::160>>}

# `fee_history`

```elixir
@spec fee_history(Keyword.t()) :: {:ok, Cartouche.FeeHistory.t()} | {:error, term()}
```

RPC call to call to get the Eip-1559 fee history data.

## Examples

    iex> Cartouche.RPC.fee_history()
    {:ok, %Cartouche.FeeHistory{
      base_fee_per_gas: [20566340803, 20460504186, 19629790325, 19239635811, 19090900440, 19048391846],
      gas_used_ratio: [0.4794155666666667, 0.3375966, 0.42049746666666665, 0.4690773, 0.49109343333333333],
      oldest_block: 16607861,
      reward: [[1000000000, 1000000000, 1500000000], [1000000000, 1000000000, 2000000000], [1000000000, 1000000000, 1000000000], [780000000, 1000000000, 2000000000], [1000000000, 1000000000, 1500000000]]
    }}

# `gas_price`

```elixir
@spec gas_price(Keyword.t()) :: {:ok, non_neg_integer()} | {:error, term()}
```

RPC call to call to get the current gas price.

## Examples

    iex> Cartouche.RPC.gas_price()
    {:ok, 1000000000}

# `get_balance`

```elixir
@spec get_balance(&lt;&lt;_::160&gt;&gt;, Keyword.t()) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

RPC to get an account's eth balance.

Docs: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getbalance

## Examples

    iex> Cartouche.RPC.get_balance(~h[0x0000000000000000000000000000000000000001])
    {:ok, 0x55}

# `get_block_by_hash`

```elixir
@spec get_block_by_hash(binary(), Keyword.t()) ::
  {:ok, Cartouche.Block.t()} | {:error, term()}
```

RPC to get a block by its block hash.

Docs: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbyhash

## Examples

    iex> Cartouche.RPC.get_block_by_hash(~h[0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae])
    {:ok, %Cartouche.Block{
      difficulty: 0x4ea3f27bc,
      extra_data: ~h[0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32],
      gas_limit: 0x1388,
      gas_used: 0x0,
      hash: ~h[0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae],
      logs_bloom: ~h[ ],
      miner: ~h[0xbb7b8287f3f0a933474a79eae42cbca977791171],
      mix_hash: ~h[0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843],
      nonce: 0x689056015818adbe,
      number: 0x1b4,
      parent_hash: ~h[0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54],
      receipts_root: ~h[0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421],
      sha3_uncles: ~h[0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347],
      size: 0x220,
      state_root: ~h[0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d],
      timestamp: 0x55ba467c,
      total_difficulty: 0x78ed983323d,
      transactions: [],
      transactions_root: ~h[0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421],
      uncles: [],
      base_fee_per_gas: nil,
      withdrawals_root: nil,
      withdrawals: nil,
      parent_beacon_block_root: nil,
      blob_gas_used: nil,
      excess_blob_gas: nil
    }}

## Options

- `:include_transaction_details` — when `true`, the node returns full transaction
  objects in `transactions`; when `false` (default), just hashes. Forwarded to
  `eth_getBlockByHash` as the second wire param (real nodes reject single-param
  calls with `-32602 Invalid params`). Note: `Cartouche.Block.deserialize/1`
  currently returns `transactions: []` regardless — see ROADMAP Task 66.

Plus any option accepted by `send_rpc/3` (e.g. `:ethereum_node`, `:timeout`, `:client`).

# `get_block_by_number`

```elixir
@spec get_block_by_number(non_neg_integer() | String.t(), Keyword.t()) ::
  {:ok, Cartouche.Block.t()} | {:error, term()}
```

RPC to get a block by its block number.

Docs: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_getblockbynumber

## Examples

    iex> Cartouche.RPC.get_block_by_number(55)
    {:ok, %Cartouche.Block{
      difficulty: 0x4ea3f27bc,
      extra_data: ~h[0x476574682f4c5649562f76312e302e302f6c696e75782f676f312e342e32],
      gas_limit: 0x1388,
      gas_used: 0x0,
      hash: ~h[0xdc0818cf78f21a8e70579cb46a43643f78291264dda342ae31049421c82d21ae],
      logs_bloom: ~h[ ],
      miner: ~h[0xbb7b8287f3f0a933474a79eae42cbca977791171],
      mix_hash: ~h[0x4fffe9ae21f1c9e15207b1f472d5bbdd68c9595d461666602f2be20daf5e7843],
      nonce: 0x689056015818adbe,
      number: 0x1b4,
      parent_hash: ~h[0xe99e022112df268087ea7eafaf4790497fd21dbeeb6bd7a1721df161a6657a54],
      receipts_root: ~h[0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421],
      sha3_uncles: ~h[0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347],
      size: 0x220,
      state_root: ~h[0xddc8b0234c2e0cad087c8b389aa7ef01f7d79b2570bccb77ce48648aa61c904d],
      timestamp: 0x55ba467c,
      total_difficulty: 0x78ed983323d,
      transactions: [],
      transactions_root: ~h[0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421],
      uncles: [],
      base_fee_per_gas: nil,
      withdrawals_root: nil,
      withdrawals: nil,
      parent_beacon_block_root: nil,
      blob_gas_used: nil,
      excess_blob_gas: nil
    }}

## Options

- `:include_transaction_details` — when `true`, the node returns full transaction
  objects in `transactions`; when `false` (default), just hashes. Forwarded to
  `eth_getBlockByNumber` as the second wire param. Note: `Cartouche.Block.deserialize/1`
  currently returns `transactions: []` regardless — see ROADMAP Task 66.

Plus any option accepted by `send_rpc/3` (e.g. `:ethereum_node`, `:timeout`, `:client`).

# `get_code`

```elixir
@spec get_code(&lt;&lt;_::160&gt;&gt;, Keyword.t()) :: {:ok, binary()} | {:error, term()}
```

RPC call to get code for a contract at an address.

## Examples

    iex> Cartouche.RPC.get_code(<<1::160>>)
    {:ok, <<0x11, 0x22, 0x33>>}

# `get_nonce`

```elixir
@spec get_nonce(&lt;&lt;_::160&gt;&gt;, Keyword.t()) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

RPC call to get account nonce.

## Examples

    iex> use Cartouche.Hex
    iex> Cartouche.RPC.get_nonce(~h[0x407d73d8a49eeb85d32cf465507dd71d507100c1])
    {:ok, 4}

# `get_transaction_count`

```elixir
@spec get_transaction_count(&lt;&lt;_::160&gt;&gt;, Keyword.t()) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

RPC to get an account's transaction count (i.e. nonce)

Docs: https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_gettransactioncount

## Examples

    iex> Cartouche.RPC.get_transaction_count(~h[0x0000000000000000000000000000000000000001])
    {:ok, 0x4}

# `get_trx_receipt`

```elixir
@spec get_trx_receipt(binary() | String.t(), Keyword.t()) ::
  {:ok, Cartouche.Receipt.t() | nil} | {:error, term()}
```

RPC call to get a transaction receipt. Note, this will return {:ok, %Cartouche.Receipt{}} or {:ok, nil} if the
receipt is not yet available.

## Examples

    iex> Cartouche.RPC.get_trx_receipt(~h[0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5])
    {:ok,
      %Cartouche.Receipt{
        transaction_hash: ~h[0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5],
        transaction_index: 0x66,
        block_hash: ~h[0xa957d47df264a31badc3ae823e10ac1d444b098d9b73d204c40426e57f47e8c3],
        block_number: 0xeff35f,
        from: ~h[0x6221a9c005f6e47eb398fd867784cacfdcfff4e7],
        to: ~h[0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2],
        cumulative_gas_used: 0xa12515,
        effective_gas_price: 0x5a9c688d4,
        gas_used: 0xb4c8,
        contract_address: nil,
        logs: [
          %Cartouche.Receipt.Log{
            log_index: 1,
            block_number: 0x01b4,
            block_hash: ~h[0xaa8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d],
            transaction_hash: ~h[0xaadf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf],
            transaction_index: 0,
            address: ~h[0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d],
            data: ~h[0x0000000000000000000000000000000000000000000000000000000000000000],
            topics: [
              ~h[0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5]
            ]
          }
        ],
        logs_bloom: ~h[ ],
        type: 0x02,
        status: 0x01,
      }
    }

    iex> Cartouche.RPC.get_trx_receipt("0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5")
    {:ok,
      %Cartouche.Receipt{
        transaction_hash: ~h[0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5],
        transaction_index: 0x66,
        block_hash: ~h[0xa957d47df264a31badc3ae823e10ac1d444b098d9b73d204c40426e57f47e8c3],
        block_number: 0xeff35f,
        from: ~h[0x6221a9c005f6e47eb398fd867784cacfdcfff4e7],
        to: ~h[0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2],
        cumulative_gas_used: 0xa12515,
        effective_gas_price: 0x5a9c688d4,
        gas_used: 0xb4c8,
        contract_address: nil,
        logs: [
          %Cartouche.Receipt.Log{
            log_index: 1,
            block_number: 0x01b4,
            block_hash: ~h[0xaa8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcfdf829c5a142f1fccd7d],
            transaction_hash: ~h[0xaadf829c5a142f1fccd7d8216c5785ac562ff41e2dcfdf5785ac562ff41e2dcf],
            transaction_index: 0,
            address: ~h[0x16c5785ac562ff41e2dcfdf829c5a142f1fccd7d],
            data: ~h[0x0000000000000000000000000000000000000000000000000000000000000000],
            topics: [
              ~h[0x59ebeb90bc63057b6515673c3ecf9438e5058bca0f92585014eced636878c9a5]
            ]
          }
        ],
        logs_bloom: ~h[ ],
        type: 0x02,
        status: 0x01,
      }
    }

    iex> Cartouche.RPC.get_trx_receipt("0xf9e69be4f1ae524854e14dc820c519d8f2b86e52c60e54448abf920d22fb6fe2")
    {:ok, %Cartouche.Receipt{
      transaction_hash: ~h[0xf9e69be4f1ae524854e14dc820c519d8f2b86e52c60e54448abf920d22fb6fe2],
      transaction_index: 0,
      block_hash: ~h[0x4bc3c26b1a599ced9876d9bf9a17c9bd58ec8b71a68e75335de7f2820e9336ca],
      block_number: 10493428,
      from: ~h[0xb03d1100c68e58aa1895f8c1f230c0851ff41851],
      to: ~h[0x9d8ec03e9ddb71f04da9db1e38837aaac1782a97],
      cumulative_gas_used: 222642,
      effective_gas_price: 1200000010,
      gas_used: 222642,
      contract_address: nil,
      logs: [
        %Cartouche.Receipt.Log{
          log_index: 0,
          block_number: 10493428,
          block_hash: ~h[0x4bc3c26b1a599ced9876d9bf9a17c9bd58ec8b71a68e75335de7f2820e9336ca],
          transaction_hash: ~h[0xf9e69be4f1ae524854e14dc820c519d8f2b86e52c60e54448abf920d22fb6fe2],
          transaction_index: 0,
          address: ~h[0x9d8ec03e9ddb71f04da9db1e38837aaac1782a97],
          data: ~h[0x000000000000000000000000cb372382aa9a9e6f926714f4305afac4566f75380000000000000000000000000000000000000000000000000000000000000000],
          topics: [
            ~h[0x3ffe5de331422c5ec98e2d9ced07156f640bb51e235ef956e50263d4b28d3ae4],
            ~h[0x0000000000000000000000002326aba712500ae3114b664aeb51dba2c2fb416d],
            ~h[0x0000000000000000000000002326aba712500ae3114b664aeb51dba2c2fb416d]
          ]
        },
        %Cartouche.Receipt.Log{
          log_index: 1,
          block_number: 10493428,
          block_hash: ~h[0x4bc3c26b1a599ced9876d9bf9a17c9bd58ec8b71a68e75335de7f2820e9336ca],
          transaction_hash: ~h[0xf9e69be4f1ae524854e14dc820c519d8f2b86e52c60e54448abf920d22fb6fe2],
          transaction_index: 0,
          address: ~h[0xcb372382aa9a9e6f926714f4305afac4566f7538],
          data: ~h[0x0000000000000000000000000000000000000000000000000000000000000000],
          topics: [
            ~h[0xe0d20d95fbbe7375f6edead77b5ce5c5b096e7dac85848c45c37a95eaf17fe62],
            ~h[0x0000000000000000000000009d8ec03e9ddb71f04da9db1e38837aaac1782a97],
            ~h[0x00000000000000000000000054f0a87eb5c8c8ba70243de1ac19e735b41b10a2],
            ~h[0x0000000000000000000000000000000000000000000000000000000000000000]
          ]
        },
        %Cartouche.Receipt.Log{
          log_index: 2,
          block_number: 10493428,
          block_hash: ~h[0x4bc3c26b1a599ced9876d9bf9a17c9bd58ec8b71a68e75335de7f2820e9336ca],
          transaction_hash: ~h[0xf9e69be4f1ae524854e14dc820c519d8f2b86e52c60e54448abf920d22fb6fe2],
          transaction_index: 0,
          address: ~h[0xcb372382aa9a9e6f926714f4305afac4566f7538],
          data: <<>>,
          topics: [
            ~h[0x0000000000000000000000000000000000000000000000000000000000000055]
          ]
        }
      ],
      logs_bloom: ~h[ ],
      type: 0,
      status: 1
    }}

    iex> Cartouche.RPC.get_trx_receipt(<<1::256>>)
    {:error, "failed to decode `eth_getTransactionReceipt` response: %FunctionClauseError{module: Cartouche.Hex, function: :decode_hex_, arity: 1, kind: nil, args: nil, clauses: nil}"}

    iex> Cartouche.RPC.get_trx_receipt(<<1::256>>, verbose: true)
    {:error, "failed to decode `eth_getTransactionReceipt` response: %FunctionClauseError{module: Cartouche.Hex, function: :decode_hex_, arity: 1, kind: nil, args: nil, clauses: nil}"}

    iex> Cartouche.RPC.get_trx_receipt(<<2::256>>)
    {:ok, nil}

# `max_priority_fee_per_gas`

```elixir
@spec max_priority_fee_per_gas(Keyword.t()) ::
  {:ok, non_neg_integer()} | {:error, term()}
```

RPC call to call to get the current max priority fee per gas.

## Examples

    iex> Cartouche.RPC.max_priority_fee_per_gas()
    {:ok, 1000000001}

# `prepare_trx`

```elixir
@spec prepare_trx(&lt;&lt;_::160&gt;&gt;, binary() | {String.t(), [term()]}, Keyword.t()) ::
  {:ok, Cartouche.Transaction.V1.t() | Cartouche.Transaction.V2.t()}
  | {:error, term()}
```

Helper function to work with other Cartouche modules to get a nonce, sign a transction, and prepare it to be submitted on-chain.

If you need higher-level functionality, like manual nonce tracking, you may want to use the more granular function calls.

Options:
  * `gas_price` - Set the gas price for a v1 (non-Eip1559) transaction, if nil, comes from `eth_gasPrice` (default `nil`) [note: only compatible with V1 transaction]
  * `base_fee` - Set the base price for the transaction, if nil, will use base gas price from `eth_feeHistory` (default `nil`) [note: only compatible with V2 transactions]
  * `base_fee_buffer` - Buffer for the gas price or base fee when estimating gas price. Ingored if `gas_price` (for v1) or `base_fee` (for v2) is specified directly (default: 1.2 = 120%)
  * `priority_fee` - Additional gas to send as a priority fee. (default: `{0, :gwei}`) [note: only compatible with V2 transactions]
  * `gas_limit` - Set the gas limit for the transaction (default: calls `eth_estimateGas`)
  * `gas_buffer` - Buffer if estimating gas limit (default: 1.5 = 150%)
  * `value` - Value to provide with transaction in wei (default: 0)
  * `nonce` - Nonce to send with transaction. (default: lookup via `eth_transactionCount`)
  * `verify` - Verify the function is likely to succeed (default: true)
  * `trx_type` - :v1 for V1 (pre-EIP-1559 transactions), :v2 for V2 (EIP-1559) transactions, and `nil` for auto-detect.

  Note: if we don't `verify`, then `estimateGas` will likely fail if the transaction were to fail.
        To prevent this, `gas_limit` should always be supplied when `verify` is set to false.

## Examples
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<1::160>>, {"baz(uint,address)", [50, :binary.decode_unsigned(<<1::160>>)]}, gas_price: {50, :gwei}, nonce: 10, value: 0, signer: signer_proc)
    iex> %{trx|v: nil, r: nil, s: nil}
    %Cartouche.Transaction.V1{
      nonce: 10,
      gas_price: 50000000000,
      gas_limit: 20,
      to: <<1::160>>,
      value: 0,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>
    }

    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<1::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_price: {50, :gwei}, gas_limit: 100_000, value: 0, signer: signer_proc)
    iex> %{trx|v: nil, r: nil, s: nil}
    %Cartouche.Transaction.V1{
      nonce: 4,
      gas_price: 50000000000,
      gas_limit: 100000,
      to: <<1::160>>,
      value: 0,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>
    }

    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<1::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_price: {50, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, signer: signer_proc)
    iex> %{trx|v: nil, r: nil, s: nil}
    %Cartouche.Transaction.V1{
      nonce: 10,
      gas_price: 50000000000,
      gas_limit: 100000,
      to: <<1::160>>,
      value: 0,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>
    }

    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_price: {50, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, signer: signer_proc)
    {:error, %{code: 3, message: "execution reverted", revert: <<61, 115, 139, 46>>}}

    iex> # Set gas price directly
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_price: {50, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, verify: false, signer: signer_proc)
    iex> %{trx|v: nil, r: nil, s: nil}
    %Cartouche.Transaction.V1{
      nonce: 10,
      gas_price: 50000000000,
      gas_limit: 100000,
      to: <<10::160>>,
      value: 0,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>
    }

    iex> # Default gas price v1
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_limit: 100_000, trx_type: :v1, value: 0, nonce: 10, verify: false, signer: signer_proc)
    iex> %{trx|v: nil, r: nil, s: nil}
    %Cartouche.Transaction.V1{
      nonce: 10,
      gas_price: 1200000000,
      gas_limit: 100000,
      to: <<10::160>>,
      value: 0,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>
    }

    iex> # Default gas price v2
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_limit: 100_000, trx_type: :v2, value: 0, nonce: 10, verify: false, signer: signer_proc)
    iex> %{trx|signature_y_parity: nil, signature_r: nil, signature_s: nil}
    %Cartouche.Transaction.V2{
      chain_id: 5,
      nonce: 10,
      gas_limit: 100000,
      destination: <<10::160>>,
      amount: 0,
      max_fee_per_gas: 25679608965,
      max_priority_fee_per_gas: 1000000001,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>,
      access_list: []
    }

    iex> # Default gas price (trx_type: nil)
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, gas_limit: 100_000, value: 0, nonce: 10, verify: false, signer: signer_proc)
    iex> %{trx|signature_y_parity: nil, signature_r: nil, signature_s: nil}
    %Cartouche.Transaction.V2{
      chain_id: 5,
      nonce: 10,
      gas_limit: 100000,
      destination: <<10::160>>,
      amount: 0,
      max_fee_per_gas: 25679608965,
      max_priority_fee_per_gas: 1000000001,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>,
      access_list: []
    }

    iex> # Set priority fee (v2)
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, priority_fee: {3, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, verify: false, signer: signer_proc)
    iex> %{trx|signature_y_parity: nil, signature_r: nil, signature_s: nil}
    %Cartouche.Transaction.V2{
      chain_id: 5,
      nonce: 10,
      gas_limit: 100000,
      destination: <<10::160>>,
      amount: 0,
      max_fee_per_gas: 27679608964,
      max_priority_fee_per_gas: 3000000000,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>,
      access_list: []
    }

    iex> # Set base fee and priority fee (v2)
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, base_fee: {1, :gwei}, priority_fee: {3, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, verify: false, signer: signer_proc)
    iex> %{trx|signature_y_parity: nil, signature_r: nil, signature_s: nil}
    %Cartouche.Transaction.V2{
      chain_id: 5,
      nonce: 10,
      gas_limit: 100000,
      destination: <<10::160>>,
      amount: 0,
      max_fee_per_gas: 4000000000,
      max_priority_fee_per_gas: 3000000000,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>,
      access_list: []
    }

    iex> # Sets chain id
    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, trx} = Cartouche.RPC.prepare_trx(<<10::160>>, {"baz(uint,address)", [50, <<1::160>> |> :binary.decode_unsigned]}, base_fee: {1, :gwei}, priority_fee: {3, :gwei}, gas_limit: 100_000, value: 0, nonce: 10, verify: false, signer: signer_proc, chain_id: 99)
    iex> %{trx|signature_y_parity: nil, signature_r: nil, signature_s: nil}
    %Cartouche.Transaction.V2{
      chain_id: 99,
      nonce: 10,
      gas_limit: 100000,
      destination: <<10::160>>,
      amount: 0,
      max_fee_per_gas: 4000000000,
      max_priority_fee_per_gas: 3000000000,
      data: <<162, 145, 173, 214, 0::248, 50, 0::248, 1>>,
      access_list: []
    }

# `send_rpc`

```elixir
@spec send_rpc(String.t(), [term()], Keyword.t()) ::
  {:ok, term()} | {:error, %{code: integer(), message: String.t()}}
```

Simple RPC client for a JSON-RPC Ethereum node.

## Examples

    iex> Cartouche.RPC.send_rpc("net_version", [])
    {:ok, "3"}

    iex> use Cartouche.Hex
    iex> Cartouche.RPC.send_rpc("get_balance", ["0x407d73d8a49eeb85d32cf465507dd71d507100c1", "latest"], ethereum_node: "http://example.com")
    {:ok, "0x0234c8a3397aab58"}

## Options

Common options (other RPC wrappers forward `opts` here):

- `:ethereum_node` — node URL; falls back to `Application.get_env(:cartouche, :ethereum_node)`
- `:timeout` — Finch `receive_timeout` in ms
- `:headers` — extra request headers
- `:verbose` — when `true`, decode failures log at `:error` instead of `:info`
- `:client` — HTTP client module (must expose `request/3`); private testing seam, defaults to
  `Application.get_env(:cartouche, :client, Finch)` so the test env's mock client wins
  automatically. Set to `Finch` per-call to bypass the mock (see `Cartouche.Test.Live`).

# `send_trx`

```elixir
@spec send_trx(
  Cartouche.Transaction.V1.t() | Cartouche.Transaction.V2.t(),
  Keyword.t()
) ::
  {:ok, binary()} | {:error, term()}
```

RPC call to send a raw transaction.

## Examples

    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, signed_trx} = Cartouche.Transaction.build_signed_trx(<<1::160>>, 5, {"baz(uint,address)", [50, :binary.decode_unsigned(<<1::160>>)]}, {50, :gwei}, 100_000, 0, chain_id: :goerli, signer: signer_proc)
    iex> {:ok, trx_id} = Cartouche.RPC.send_trx(signed_trx)
    iex> <<nonce::integer-size(8), gas_price::integer-size(64), gas_limit::integer-size(24), to::binary>> = trx_id
    iex> {nonce, gas_price, gas_limit, to}
    {5, 50000000000, 100000, <<1::160>>}

    iex> signer_proc = Cartouche.Test.Signer.start_signer()
    iex> {:ok, signed_trx} = Cartouche.Transaction.build_signed_trx_v2(<<1::160>>, 5, {"baz(uint,address)", [50, :binary.decode_unsigned(<<1::160>>)]}, {50, :gwei}, {10, :gwei}, 100_000, 0, [], chain_id: :goerli, signer: signer_proc)
    iex> {:ok, trx_id} = Cartouche.RPC.send_trx(signed_trx)
    iex> <<nonce::integer-size(8), max_priority_fee_per_gas::integer-size(64), max_fee_per_gas::integer-size(64), gas_limit::integer-size(24), to::binary>> = trx_id
    iex> {nonce, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, to}
    {5, 50000000000, 10000000000, 100000, <<1::160>>}

# `trace_call`

```elixir
@spec trace_call(
  Cartouche.Transaction.V1.t() | Cartouche.Transaction.V2.t(),
  Keyword.t()
) ::
  {:ok, Cartouche.TraceCall.t()} | {:error, term()}
```

RPC to trace a transaction call speculatively.

## Examples

    iex> Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>)
    ...> |> Cartouche.RPC.trace_call()
    {:ok,
      %Cartouche.TraceCall{
        output: "",
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: <<0::160>>,
              gas: 499_978_072,
              input: ~h[0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000],
              to: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 492_166_471,
            error: "Reverted",
            output: "",
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: nil,
              init: ~h[ ],
              from: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              gas: 492_133_529,
              input: nil,
              to: nil,
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: nil,
            error: "contract address collision",
            output: nil,
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "create"
          }
        ],
        vm_trace: nil
      }
    }

    iex> Cartouche.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
    ...> |> Cartouche.RPC.trace_call()
    {:ok,
      %Cartouche.TraceCall{
        output: "",
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: <<0::160>>,
              gas: 499_978_072,
              input: ~h[0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000],
              to: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 492_166_471,
            error: "Reverted",
            output: "",
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: nil,
              init: ~h[ ],
              from: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              gas: 492_133_529,
              input: nil,
              to: nil,
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: nil,
            error: "contract address collision",
            output: nil,
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "create"
          }
        ],
        vm_trace: nil
      }
    }

# `trace_call_many`

```elixir
@spec trace_call_many(
  [
    Cartouche.Transaction.V1.t()
    | Cartouche.Transaction.V2.t()
    | {Cartouche.Transaction.V1.t() | Cartouche.Transaction.V2.t(),
       &lt;&lt;_::160&gt;&gt; | nil}
  ],
  Keyword.t()
) :: {:ok, [Cartouche.TraceCall.t()]} | {:error, term()}
```

RPC to trace many transaction calls speculatively.

## Examples

    iex> t1 = Cartouche.Transaction.V1.new(1, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>)
    iex> t2 = Cartouche.Transaction.V2.new(1, {1, :gwei}, {100, :gwei}, 100_000, <<1::160>>, {2, :wei}, <<1, 2, 3>>, [<<2::160>>, <<3::160>>], :goerli)
    iex> Cartouche.RPC.trace_call_many([t1, t2])
    {:ok, [
      %Cartouche.TraceCall{
        output: "",
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: <<0::160>>,
              gas: 499_978_072,
              input: ~h[0xd1692f56000000000000000000000000142da9114e5a98e015aa95afca0585e84832a612000000000000000000000000142da9114e5a98e015aa95afca0585e84832a6120000000000000000000000000000000000000000000000000000000000000000],
              to: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 492_166_471,
            error: "Reverted",
            output: "",
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: nil,
              init: ~h[ ],
              from: ~h[0x13172EE393713FBA9925A9A752341EBD31E8D9A7],
              gas: 492_133_529,
              input: nil,
              to: nil,
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: nil,
            error: "contract address collision",
            output: nil,
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "create"
          }
        ],
        vm_trace: nil
      },
      %Cartouche.TraceCall{
        output: ~h[0x00000000000000000000000079EDBC4F3A6AA2266CD469CC544501743BE8B078],
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: <<0::160>>,
              gas: 499_945_916,
              input: ~h[ ],
              to: ~h[0x2926631647877E9A84BB7E3A0821D643BF8D63C0],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 4298,
            error: nil,
            output: ~h[0x00000000000000000000000079EDBC4F3A6AA2266CD469CC544501743BE8B078],
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          }
        ],
        vm_trace: nil
      },
      %Cartouche.TraceCall{
        output: <<130, 180, 41, 0>>,
        state_diff: nil,
        trace: [
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "call",
              init: nil,
              from: <<0::160>>,
              gas: 499_977_072,
              input: ~h[ ],
              to: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 4202,
            error: "Reverted",
            output: ~h[0x82B42900],
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "delegatecall",
              init: nil,
              from: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              gas: 492_162_171,
              input: ~h[ ],
              to: ~h[0x49E5D261E95F6A02505078BB339FECB210A0B634],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 1362,
            error: "Reverted",
            output: <<130, 180, 41, 0>>,
            result_code: nil,
            result_address: nil,
            subtraces: 1,
            trace_address: [0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          },
          %Cartouche.Trace{
            action: %Cartouche.Trace.Action{
              call_type: "staticcall",
              init: nil,
              from: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              gas: 484_471_386,
              input: ~h[0xC34C08E5],
              to: ~h[0x6E995746B61C48C5BDF58FC788B1AEA08DFB7E43],
              value: 0
            },
            block_hash: nil,
            block_number: nil,
            gas_used: 190,
            error: nil,
            output: ~h[0x000000000000000000000000142DA9114E5A98E015AA95AFCA0585E84832A612],
            result_code: nil,
            result_address: nil,
            subtraces: 0,
            trace_address: [0, 0],
            transaction_hash: nil,
            transaction_position: nil,
            type: "call"
          }
        ],
        vm_trace: nil
      }
    ]}

# `trace_trx`

```elixir
@spec trace_trx(binary() | String.t(), Keyword.t()) ::
  {:ok, [Cartouche.Trace.t()]} | {:error, term()}
```

RPC call to get a transaction receipt

## Examples

    iex> Cartouche.RPC.trace_trx("0x85d995eba9763907fdf35cd2034144dd9d53ce32cbec21349d4b12823c6860c5")
    {:ok,
      [
      %Cartouche.Trace{
        action: %Cartouche.Trace.Action{
          call_type: "call",
          from: ~h[0x83806d539d4ea1c140489a06660319c9a303f874],
          gas: 0x01a1f8,
          input: <<>>,
          to: ~h[0x1c39ba39e4735cb65978d4db400ddd70a72dc750],
          value: 0x7a16c911b4d00000,
        },
        block_hash: ~h[0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add],
        block_number: 3068185,
        gas_used: 0x2982,
        output: <<>>,
        subtraces: 2,
        trace_address: [~h[0x1c39ba39e4735cb65978d4db400ddd70a72dc750]],
        transaction_hash: ~h[0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3],
        transaction_position: 2,
        type: "call"
      },
      %Cartouche.Trace{
        action: %Cartouche.Trace.Action{
          call_type: "call",
          from: ~h[0x83806d539d4ea1c140489a06660319c9a303f874],
          gas: 0x01a1f8,
          input: <<>>,
          to: ~h[0x1c39ba39e4735cb65978d4db400ddd70a72dc750],
          value: 0x7a16c911b4d00000,
        },
        block_hash: ~h[0x7eb25504e4c202cf3d62fd585d3e238f592c780cca82dacb2ed3cb5b38883add],
        block_number: 3068186,
        gas_used: 0x2982,
        output: <<>>,
        subtraces: 2,
        trace_address: [~h[0x1c39ba39e4735cb65978d4db400ddd70a72dc750]],
        transaction_hash: ~h[0x17104ac9d3312d8c136b7f44d4b8b47852618065ebfa534bd2d3b5ef218ca1f3],
        transaction_position: 2,
        type: "call"
      }
    ]}

---

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