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
- Resolve token metadata if needed (list / get).
- Optional: estimate gas, then prepare on Cloud. Remember: prepare does not create a ledger row.
- Create a ledger record with
kind: "transfer"(or swap/defi/approval),from/to/value, andstatus: "prepared". Store_id. - Sign the unsigned payload with your Wallet SDK or HSM.
- Broadcast with
ledgerTxIdset to that id (see Link to Cloud broadcast). - Poll receipt until success or failure.
- PATCH ledger to
confirmed(withreceipt) orfailed.
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
failedso 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
broadcastand poll with backoff (see Cloud failure modes).
Status reference
Full status and kind tables: Status model.