LDGR/Docs
DocsDevelopersLDGR cookbook

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 →

Read prompt.md →

Start with the first request.

RecipePackage / surfaceUse it for
Install the published packagesnpmChoose the smallest runtime-appropriate entry point.
Choose testnet or mainnetnetwork configKeep endpoint, ledger ID, asset ID, and address format aligned.
Verify a payment@ldgr/clientConfirm terms and transaction hash before fulfilling an order.
Code example
import { createLdgrClient } from "@ldgr/client";

const client = createLdgrClient({ network: "testnet" });
const balance = await client.accounts.getBalance(address, "t0");
console.log(balance.amount); // exact decimal string

Sell 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.

RecipePackage / surfaceUse it for
Verify a plain transfer@ldgr/clientFulfil an order once after the hash matches asset, amount, and recipient.
Verify Ledra Checkout@ldgr/clientAccept a transfer_batch with merchant + fee outputs in one hash.
Gate an API with LDGR402wallet SDK + @ldgr/clientCharge per HTTP response with a 402 challenge and hash proof.
Embed a payment buttonwallet SDK custom elementsDrop a branded pay card instead of building the form yourself.
Code example
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);

Code example
// 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) },
});

Code example
// 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.

RecipePackage / surfaceUse it for
Sell a subscription tierwallet SDK + @ldgr/clientCreate a plan, let the wallet lock it, gate access by entitlement.
Fund recipient claimswallet SDK + @ldgr/clientPrepay fixed allocations, let recipients claim independently, and recover unclaimed funds after expiry.
Pay ordered milestoneswallet SDK + @ldgr/clientPrepay fixed steps, approve each immediate payout, and refund only the expired residual.
Pay ordered milestoneswallet SDK + @ldgr/clientPrepay fixed steps, approve each immediate payout, and refund only the expired residual.
Schedule payroll or releaseswallet SDKPre-fund up to 120 fixed payouts without debiting the wallet later.
Split revenue atomicallywallet SDKDivide one payment across recipients in a single settlement.
Code example
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);

Code example
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 debit

Code example
const 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.

RecipePackage / surfaceUse it for
Create a fixed-supply tokenwallet SDKMint a meme, points, or event credit in one confirmation.
Brand it with icon and linkswallet SDKSet the display name, icon, website, and socials buyers see.
Read balances from a backend@ldgr/clientShow holdings and gate features without holding keys.
Code example
const receipt = await wallet.createAsset({
  displayName: "Example Coin",
  ticker: "EXMPL",
  decimals: 6,
  supplyMode: "fixed",
  initialSupply: "1000000",
});
console.log(receipt.transactionHash);

Code example
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.

RecipePackage / surfaceUse it for
Mint an NFT editionwallet SDKCreate a collection, then mint items to fans.
Send a claim link giftwallet SDKLock funds behind a secret; share the link, not the keys.
Fund an NFT purchase offerwallet SDKLock a buyer-funded offer for an existing item and bound seller.
Code example
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",
});

Code example
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.

RecipePackage / surfaceUse it for
Connect with Ledra Connectwallet SDKAsk the extension or Web Wallet to approve a session.
Share a transfer QRldgr:// linkPrefill recipient, asset, and amount for one scan.
Resolve a username@ldgr/clientLet people pay myshop instead of a Bech32 string.
Accept a confidential payment@ldgr/clientGive each payer a fresh one-time address from one reusable code.
Code example
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);

Code example
ldgr://transfer/<ADDRESS>?asset=t0&amount=12.50

Code example
await 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.

RecipePackage / surfaceUse it for
Quote a route@ldgr/clientEstimate an AMM route, then re-quote immediately before a wallet-confirmed swap.
Embed a swap widgetwallet SDKConfigure token A, token B, search policy, whitelist, and ledger ID.
Seed a pool and add liquiditywallet SDKCreate the market your token trades on.
Bound pool repricingwallet SDKPre-fund bounded reprices plus an after-swap hook.
Code example
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);

Code example
<ldgr-swap-widget
  api-base="https://tst.ldgr.ltd"
  ledger-id="0"
  token-a="t0"
  token-b="t0f8eaa3828cfa3b"
  allow-search>
</ldgr-swap-widget>

Code example
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.

RecipePackage / surfaceUse it for
Save a user profilewallet SDK + @ldgr/clientWrite once with the wallet, read everywhere by namespace + key.
Watch settlement livewallet SDKRefresh UI on ledger events, then re-check the hash over HTTP.
Pay out from a backend@ldgr/clientSend rewards or refunds from a secret-managed service wallet.
Code example
await wallet.createObject({ data: { displayName: "Ada", bio: "Builder" }, namespace: "myapp.profiles", key: accountAddress });
const profile = await client.objects.getByKey("myapp.profiles", accountAddress);

Code example
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();

Code example
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.

  1. 01
    Prepare

    Read the current state and keep amounts as exact decimal strings at the API boundary.

  2. 02
    Confirm

    Let the user’s wallet approve customer funds; a quote is not a settlement promise.

  3. 03
    Verify

    Use the settled transaction hash and expected terms as the public receipt.

Keep going

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.