Skip to content
Docs

Recipes

Track a send end to end

Create a prepared record, sign and broadcast with ledgerTxId, then confirm or fail it from the receipt.

Overview

Keep a ledger row for every user send so your app, support tools, and Cloud broadcast stay on the same tx_… id. Signing always stays in the wallet; Ledger only stores metadata and status.

Steps

  1. Resolve token metadata if needed (list / get).
  2. Optional: estimate gas, then prepare on Cloud. Remember: prepare does not create a ledger row.
  3. Create a ledger record with kind: "transfer" (or swap/defi/approval), from / to / value, and status: "prepared". Store _id.
  4. Sign the unsigned payload with your Wallet SDK or HSM.
  5. Broadcast with ledgerTxId set to that id (see Link to Cloud broadcast).
  6. Poll receipt until success or failure.
  7. PATCH ledger to confirmed (with receipt) or failed.

Server sketch

ts
// 1) Create ledger row (project key → ledger.gray3.io)
const created = await ledgerCreate({
  kind: "transfer",
  chainId: "ethereum-sepolia",
  from,
  to,
  value,
  status: "prepared",
});

// 2) Cloud prepare → sign locally → broadcast with link
const { unsignedPayload } = await cloudPrepare({ kind: "transfer", chainId, from, to, value });
const signedPayload = await wallet.sign(unsignedPayload);
const { txHash, ledgerTxId } = await cloudBroadcast({
  chainId,
  signedPayload,
  ledgerTxId: created._id,
});

// 3) Receipt → finalize ledger
const receipt = await pollReceipt(chainId, txHash);
await ledgerPatch(ledgerTxId, {
  status: receipt.status === "success" ? "confirmed" : "failed",
  receipt,
});

Failure paths

  • If the user abandons the send after the record is created, PATCH it to failed so lists stay clean.
  • If simulation fails before broadcast, do the same. Do not invent a hash.
  • If the receipt is pending, keep the record at broadcast and poll with backoff (see Cloud failure modes).

Status reference

Full status and kind tables: Status model.