> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloak.ag/llms.txt
> Use this file to discover all available pages before exploring further.

# Payment links

> Create links that hold money, claim them, and request payments, compatible with cloak.ag

A **payment link** holds money. Whoever opens it can claim it, into their own private balance or to a
Solana address. A **payment request** asks for money: whoever opens it pays it from their private
balance. Both use cloak.ag's format, so links made with the SDK open on cloak.ag and in the Cloak app,
and the other way round.

## Create a link that holds money

```ts theme={null}
const link = await cloak.createPaymentLink({
  token: "USDC",
  amount: "15",
  ref: "gift-alice", // optional: the same ref always rebuilds the same link
});
console.log(link.url); // https://cloak.ag/pay#…
```

The call funds a note for the link from the private balance. Creating a link carries no protocol fee.

> [!WARNING]
>
> **The URL is the money.** Its secret is the part after `#`, which browsers never send to a server.
> Anyone with the full URL can claim the funds. Share it over a private channel and never log it.

## Claim a link

```ts theme={null}
// Into this account's private balance: free.
const claimed = await cloak.claimPaymentLink(url);

// Or straight to a Solana address: the withdrawal fee comes off.
const toWallet = await cloak.claimPaymentLink(url, { to: "<a Solana address>" });
```

A link someone already claimed throws `link.claimed`. The creator can claim their own unclaimed link
to take the money back.

## Track the links an account made

```ts theme={null}
for (const l of await cloak.paymentLinks()) {
  console.log(l.amount, l.token, l.ref ?? "", l.claimed ? "claimed" : "open");
}
```

## Request a payment

```ts theme={null}
const request = await cloak.requestPayment({ token: "USDC", amount: "40", label: "Invoice 1042" });
console.log(request.url); // share it; no transaction happens yet

// The payer, from their own private balance:
await payerCloak.payRequest(request.url);

// Back on the requester's side:
const paid = (await cloak.requests()).find((r) => r.id === request.id)?.paid;
```

`label` is free text up to 32 bytes, shown to the payer and never verified. The payment arrives as a
private note in the requester's balance.

## Decode without an account

`decodeClaimablePaymentLink(url)` and `decodePaymentRequestLink(fragment)` read a link's token and
amount without opening an account, for example to render a preview. The fragment still carries the
secret, so treat decoded data as sensitive.

## Errors

| Code | Meaning |
| - | - |
| `link.claimed` | Someone already claimed it |
| `link.invalid`, `link.is_request` | Not a claimable link, or a request passed to `claimPaymentLink` |
| `link.ref_used` | This `ref` already made a link for a different amount |
| `link.failed`, `link.claim_failed` | Funding or claiming did not complete; retryable |
| `request.pay_failed` | Paying the request did not complete; retryable |

## Related

* [Payment links for users](https://docs.cloak.ag/guide/payment-links.md)
* [Private transfers](https://docs.cloak.ag/guides/private-transfers.md): the same mechanism, addressed to a known recipient.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.