Onchain.Tempo.RPC (onchain_tempo v0.2.0)

Copy Markdown View Source

Tempo-specific JSON-RPC operations — transaction broadcast and receipt fetching.

Provides both async (eth_sendRawTransaction) and sync (eth_sendRawTransactionSync) broadcast methods. The sync variant is Tempo-specific — it waits for block inclusion (~500ms on Tempo) and returns the receipt inline, eliminating the race condition of separate receipt polling.

Usage

{:ok, tx_hash} = Onchain.Tempo.RPC.broadcast_async(signed_hex, rpc_url)

{:ok, tx_hash, receipt} = Onchain.Tempo.RPC.broadcast_sync(signed_hex, rpc_url)

{:ok, receipt} = Onchain.Tempo.RPC.fetch_receipt(tx_hash, rpc_url)

Options

All functions accept an opts keyword list with:

  • :req_options — keyword list passed to Req.request/2 (timeouts, adapters, etc.)

Summary

Functions

Broadcast a signed transaction via async eth_sendRawTransaction.

Broadcast a signed transaction via Tempo's synchronous eth_sendRawTransactionSync.

Fetch a transaction receipt via eth_getTransactionReceipt.

Parse a raw JSON-RPC receipt map into atom-keyed format.

Functions

broadcast_async(raw_hex, rpc_url, opts \\ [])

@spec broadcast_async(String.t(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, String.t()}

Broadcast a signed transaction via async eth_sendRawTransaction.

Returns the transaction hash immediately without waiting for block inclusion.

broadcast_sync(raw_hex, rpc_url, opts \\ [])

@spec broadcast_sync(String.t(), String.t(), keyword()) ::
  {:ok, String.t(), map()} | {:error, String.t()}

Broadcast a signed transaction via Tempo's synchronous eth_sendRawTransactionSync.

Waits for block inclusion and returns the full receipt inline. Returns {:ok, tx_hash, receipt} on success.

fetch_receipt(tx_hash, rpc_url, opts \\ [])

@spec fetch_receipt(String.t(), String.t(), keyword()) ::
  {:ok, map()} | {:error, String.t()}

Fetch a transaction receipt via eth_getTransactionReceipt.

parse_receipt(raw)

@spec parse_receipt(map()) :: map()

Parse a raw JSON-RPC receipt map into atom-keyed format.

The output is compatible with Onchain.Transfer.parse_logs/1 and Onchain.Tempo.Transfer.parse_transfer_with_memo_logs/1.