Recipes for the parts you’ll repeat.
Short, copy-paste recipes for what builders actually ship on LDGR: selling, subscriptions, tokens, NFTs, markets, and app data. Each recipe names the package, the custody boundary, and the guide to open next.
Build with your agent
Bring your AI agent.
One prompt gives your AI coding tool the networks, packages, and guides to start building on LDGR.
Get testnet tLEDRA →Start with the first request.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Install the published packages | npm | Choose the smallest runtime-appropriate entry point. |
| Choose testnet or mainnet | network config | Keep endpoint, ledger ID, asset ID, and address format aligned. |
| Verify a payment | @ldgr/client | Confirm terms and transaction hash before fulfilling an order. |
import { createLdgrClient } from "@ldgr/client";
const client = createLdgrClient({ network: "testnet" });
const balance = await client.accounts.getBalance(address, "t0");
console.log(balance.amount); // exact decimal stringSell something.
Take a one-time payment in Ledra, Ledra Testnet, a user token, or Ledra Dollar (USDL). Save the expected terms first, then verify the settled transaction hash on your server.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Verify a plain transfer | @ldgr/client | Fulfil an order once after the hash matches asset, amount, and recipient. |
| Verify Ledra Checkout | @ldgr/client | Accept a transfer_batch with merchant + fee outputs in one hash. |
| Gate an API with LDGR402 | wallet SDK + @ldgr/client | Charge per HTTP response with a 402 challenge and hash proof. |
| Embed a payment button | wallet SDK custom elements | Drop a branded pay card instead of building the form yourself. |
import { createLdgrClient } from "@ldgr/client";
const client = createLdgrClient({ network: order.network });
const receipt = await client.payments.verifyTransfer(submitted.transactionHash, {
to: order.recipient,
asset: order.assetCode, // "t0" testnet, "t1" mainnet, or a token code
amount: order.amount, // decimal string, never a float
reference: order.publicReference,
});
if (receipt.status === "confirmed") await fulfilOnce(receipt.transactionHash);// Browser: pay a 402 requirement, then retry with proof.
import { encodeLdgr402Payment, parseLdgr402Requirement, payLdgr402 } from "@ldgr/wallet-sdk/browser";
const requirement = parseLdgr402Requirement(await response.json());
const payment = await payLdgr402(requirement);
const retry = await fetch(request, {
headers: { "LDGR402-Payment": encodeLdgr402Payment(payment) },
});// Server: verify the LDGR402 retry before returning paid content.
import { createLdgrClient } from "@ldgr/client";
const client = createLdgrClient({ network: "mainnet" });
const verification = await client.payments.verifyLdgr402(
request.headers.get("LDGR402-Payment") ?? "",
storedRequirement,
);
if (verification.status !== "confirmed") return new Response("Payment not settled", { status: 422 });
await challengeStore.fulfill(storedRequirement.challenge, verification.transactionHash);Get paid on repeat.
Subscriptions, payroll, vesting, and revenue splits are declarative contracts with fixed rules — not standing mandates on a wallet. The payer locks funds up front. Vesting beneficiaries and subscription payees claim unlocked funds; scheduled splits use prepaid automatic releases.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Sell a subscription tier | wallet SDK + @ldgr/client | Create a plan, let the wallet lock it, gate access by entitlement. |
| Fund recipient claims | wallet SDK + @ldgr/client | Prepay fixed allocations, let recipients claim independently, and recover unclaimed funds after expiry. |
| Pay ordered milestones | wallet SDK + @ldgr/client | Prepay fixed steps, approve each immediate payout, and refund only the expired residual. |
| Pay ordered milestones | wallet SDK + @ldgr/client | Prepay fixed steps, approve each immediate payout, and refund only the expired residual. |
| Schedule payroll or releases | wallet SDK | Pre-fund up to 120 fixed payouts without debiting the wallet later. |
| Split revenue atomically | wallet SDK | Divide one payment across recipients in a single settlement. |
import { createLdgrWallet } from "@ldgr/wallet-sdk";
const wallet = createLdgrWallet(window.ldgr);
const plan = await wallet.createSubscriptionPlan({
tier: "pro",
billedAsset: "t0",
periodAmount: "9.00",
periodCount: 12,
periodMs: String(30 * 24 * 60 * 60 * 1000),
});
console.log(plan.planId, plan.transactionHash);import { createLdgrClient } from "@ldgr/client";
const client = createLdgrClient({ network: "testnet" });
const entitlement = await client.subscriptions.getEntitlement({ payer: accountAddress, planId });
if (entitlement.active) allowAccess(); // read-only check, never a debitconst opened = await wallet.openContract({
template: "scheduled_split_v1",
asset: tokenCode,
recipients: [teammateA, teammateB],
shares: ["1", "1"],
steps: [{ at: String(releaseAtMs), amount: "100.00" }],
amount: "100.00",
feeReserve: "0.50", // separate native reserve for release fees
});
console.log(opened.contractId, opened.transactionHash);Launch a token.
Any funded wallet can create a fixed or mintable fungible token, brand it with an icon and links, and distribute it with ordinary wallet-confirmed transfers.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Create a fixed-supply token | wallet SDK | Mint a meme, points, or event credit in one confirmation. |
| Brand it with icon and links | wallet SDK | Set the display name, icon, website, and socials buyers see. |
| Read balances from a backend | @ldgr/client | Show holdings and gate features without holding keys. |
const receipt = await wallet.createAsset({
displayName: "Example Coin",
ticker: "EXMPL",
decimals: 6,
supplyMode: "fixed",
initialSupply: "1000000",
});
console.log(receipt.transactionHash);await wallet.setAssetIcon({ code: tokenCode, iconSource: "external", iconUri: "https://example.com/icon.png" });
await wallet.setAssetLinks({
code: tokenCode,
website: "https://example.com",
socials: [{ network: "x", url: "https://x.com/example" }],
});
await wallet.mintAsset({ code: tokenCode, to: fanAddress, amount: "500.00" });Drop NFTs, gifts, and promos.
Collections and hashlocked gifts cover raffles, onboarding credits, and limited editions. Every open and claim settles under a transaction hash you can link in Explorer.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Mint an NFT edition | wallet SDK | Create a collection, then mint items to fans. |
| Send a claim link gift | wallet SDK | Lock funds behind a secret; share the link, not the keys. |
| Fund an NFT purchase offer | wallet SDK | Lock a buyer-funded offer for an existing item and bound seller. |
const collection = await wallet.createNftCollection({ displayName: "Stickers" });
await wallet.mintNft({
collectionId: collection.transactionHash, // or the returned collection id
to: fanAddress,
displayName: "Sticker #1",
imageUri: "https://example.com/sticker-1.png",
});const gift = await wallet.openContract({
template: "gift_v1",
locks: [{ asset: "t0", amount: "5.00" }],
secret,
expiresAt: String(Date.now() + 7 * 24 * 60 * 60 * 1000),
});
// Share /explorer/gift?contract=<id> plus the secret out of band.
await wallet.claimGift({ contractId: gift.contractId, secret });Bring users without taking custody.
Connect a browser in seconds, resolve human-readable usernames, and accept private-by-default receives. Your site never sees a private key.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Connect with Ledra Connect | wallet SDK | Ask the extension or Web Wallet to approve a session. |
| Share a transfer QR | ldgr:// link | Prefill recipient, asset, and amount for one scan. |
| Resolve a username | @ldgr/client | Let people pay myshop instead of a Bech32 string. |
| Accept a confidential payment | @ldgr/client | Give each payer a fresh one-time address from one reusable code. |
import { createLdgrWallet } from "@ldgr/wallet-sdk";
const wallet = createLdgrWallet(window.ldgr);
await wallet.connect({ network: "testnet" });
const receipt = await wallet.send({ asset: "t0", to: recipientAddress, amount: "2.50" });
console.log(receipt.transactionHash);ldgr://transfer/<ADDRESS>?asset=t0&amount=12.50await wallet.registerName({ name: "myshop", durationMs: String(365 * 24 * 60 * 60 * 1000), primary: true });
const primary = await client.usernames.getPrimary(accountAddress);
const result = await client.silentPayments.send({
wallet: serviceWallet,
paymentCode: recipientPaymentCode,
asset: "t0",
amount: "1.00",
});Build markets with the AMM.
Quote a route, let the wallet confirm the swap with slippage protection, seed liquidity, or reprice a Ledra / USDL-style pool toward a target with a bounded reprice schedule.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Quote a route | @ldgr/client | Estimate an AMM route, then re-quote immediately before a wallet-confirmed swap. |
| Embed a swap widget | wallet SDK | Configure token A, token B, search policy, whitelist, and ledger ID. |
| Seed a pool and add liquidity | wallet SDK | Create the market your token trades on. |
| Bound pool repricing | wallet SDK | Pre-fund bounded reprices plus an after-swap hook. |
const quote = await client.amm.quoteRoute(assetIn, assetOut, "10.00", 3);
const receipt = await wallet.ammSwap({
poolId,
assetIn,
assetOut,
amountIn: "10.00",
amountOutMin: quotedMinimum, // re-quoted minimum protects against slippage
});
console.log(receipt.transactionHash);<ldgr-swap-widget
api-base="https://tst.ldgr.ltd"
ledger-id="0"
token-a="t0"
token-b="t0f8eaa3828cfa3b"
allow-search>
</ldgr-swap-widget>await wallet.createAmmPool({ asset0: "t0", asset1: tokenCode, amount0Desired: "100.00", amount1Desired: "10000.00" });
await wallet.ammAddLiquidity({ poolId, amount0Desired: "10.00", amount1Desired: "1000.00" });
await wallet.ammRepriceScheduleOpen({
poolId,
targetMode: "fixed_ratio",
target0: "1",
target1: "100",
asset0Escrow: "50.00",
asset1Escrow: "5000.00",
feeReserve: "1.00",
intervalMs: String(60 * 60 * 1000),
startAt: String(Date.now() + 60_000),
endAt: String(Date.now() + 7 * 24 * 60 * 60 * 1000),
maxExecutions: 100,
maxInput0: "5.00",
maxInput1: "500.00",
});
await wallet.ammRepriceScheduleSetHook({ contractId, swapTrigger: "after_swap" });Store app data and react live.
Keep profiles, settings, and content pointers in public objects, resolve them by key, watch settlement over WebSocket, and send automated payouts from a caller-owned service wallet.
| Recipe | Package / surface | Use it for |
|---|---|---|
| Save a user profile | wallet SDK + @ldgr/client | Write once with the wallet, read everywhere by namespace + key. |
| Watch settlement live | wallet SDK | Refresh UI on ledger events, then re-check the hash over HTTP. |
| Pay out from a backend | @ldgr/client | Send rewards or refunds from a secret-managed service wallet. |
await wallet.createObject({ data: { displayName: "Ada", bio: "Builder" }, namespace: "myapp.profiles", key: accountAddress });
const profile = await client.objects.getByKey("myapp.profiles", accountAddress);import { connectExplorerEvents } from "@ldgr/wallet-sdk";
const feed = connectExplorerEvents({
apiBase: "https://tst.ldgr.ltd",
filters: { addresses: [merchantAddress] },
onEvent: (event) => {
if (event.type === "ledger.transaction") refreshBalances(); // then verify the hash over HTTP
},
});
// Later: feed.close();import { createLdgrClient, loadLocalWallet } from "@ldgr/client";
const serviceWallet = await loadLocalWallet({
ledgerId: 0,
recoveryKey: await secretStore.read("ldgr-service-wallet"),
});
const result = await client.transfers.send({
wallet: serviceWallet,
asset: "t0",
amount: "2.50",
to: recipientAddress,
memo: "Refund 1234",
});
if (result.status === "settled") console.log("Settled", result.transactionHash);Every recipe ends the same way
Make the boundary visible.
- 01Prepare
Read the current state and keep amounts as exact decimal strings at the API boundary.
- 02Confirm
Let the user’s wallet approve customer funds; a quote is not a settlement promise.
- 03Verify
Use the settled transaction hash and expected terms as the public receipt.
These recipes are entry points, not a replacement for the product guides. Read the relevant guide when you need the custody, privacy, asset, or network details around an integration.