Onchain.Tempo.Faucet (onchain_tempo v0.2.0)

Copy Markdown View Source

Moderato testnet faucet — wraps the non-standard tempo_fundAddress JSON-RPC.

Moderato exposes a custom JSON-RPC method, tempo_fundAddress, that funds an address with native gas + pathUSD in a single call. This module provides a thin wrapper plus a convenience helper for spinning up a fresh, funded keypair — useful for writing integration tests against Moderato without re-deriving the recipe.

Only Moderato (chain 42_431) supports this RPC. Mainnet (4_217) does not.

Usage

# Fund an existing address.
{:ok, [tx_hash | _]} = Onchain.Tempo.Faucet.fund_address("0xabc...")

# Generate + fund a fresh keypair (waits for settlement before returning).
{:ok, %{private_key: priv, address_hex: hex, address_bin: bin}} =
  Onchain.Tempo.Faucet.fresh_funded_wallet()

# Override the endpoint (defaults to https://rpc.moderato.tempo.xyz, or
# the TEMPO_RPC_URL env var if set).
Onchain.Tempo.Faucet.fund_address("0xabc...", rpc_url: "https://my-mirror")

Options

Both fund_address/2 and fresh_funded_wallet/1 accept:

  • :rpc_url — RPC endpoint URL. Defaults to rpc_url/0.
  • :req_options — keyword list passed to Req.request/2 (timeouts, adapters, Req.Test plug, etc.)
  • :settle_ms (fresh_funded_wallet/1 only) — milliseconds to sleep after funding before returning. Defaults to 2_500. Set 0 in unit tests.

Summary

Functions

Generate a fresh 32-byte keypair, fund it via tempo_fundAddress, and wait for settlement.

Fund an existing address via Moderato's tempo_fundAddress RPC.

RPC URL used by the faucet by default — TEMPO_RPC_URL env var if set, otherwise https://rpc.moderato.tempo.xyz.

Functions

fresh_funded_wallet(opts \\ [])

@spec fresh_funded_wallet(keyword()) ::
  {:ok,
   %{private_key: binary(), address_hex: String.t(), address_bin: binary()}}
  | {:error, String.t()}

Generate a fresh 32-byte keypair, fund it via tempo_fundAddress, and wait for settlement.

Returns the wallet as a map with :private_key (32 bytes), :address_hex ("0x" + 40 hex), and :address_bin (20 bytes).

fund_address(address_hex, opts \\ [])

@spec fund_address(
  String.t(),
  keyword()
) :: {:ok, [String.t()]} | {:error, String.t()}

Fund an existing address via Moderato's tempo_fundAddress RPC.

Returns {:ok, hashes} where hashes is the list of funding transaction hashes returned by the node.

rpc_url()

@spec rpc_url() :: String.t()

RPC URL used by the faucet by default — TEMPO_RPC_URL env var if set, otherwise https://rpc.moderato.tempo.xyz.