Onchain.Tempo.Faucet (onchain_tempo v0.2.2)

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 (polls for confirmation 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:

fresh_funded_wallet/1 additionally accepts:

  • :settle_ms — maximum milliseconds to wait for the funding transaction to confirm. Defaults to 10_000. Set to 0 to skip the wait entirely (used by unit tests that mock the RPC layer).
  • :poll_interval_ms — interval between eth_getBalance polls. Defaults to 200.

Summary

Functions

Generate a fresh 32-byte keypair, fund it via tempo_fundAddress, and poll eth_getBalance until the funding transaction lands on-chain.

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 poll eth_getBalance until the funding transaction lands on-chain.

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

Polling is bounded by :settle_ms (default 10_000 ms); pass 0 to skip the wait entirely. The interval between polls is controlled by :poll_interval_ms (default 200 ms).

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.