Take payments on your site
Sell an item from your coin's store on your own website. Your server opens a checkout session, you send the buyer to its link, the buyer pays on chaindaddy.io and comes back to your site. Your server learns the payment went through from a signed webhook or by reading the session.
No server? A coin's owner can put Item Store on the coin's site with one tag instead: Sell on your site with one tag.
Run it first
The example is a whole site for your own machine: one server file and two pages. It takes a test payment on http://localhost:3000 with the public demo key, so it needs no account, key, money, domain or wallet.
What you need
- A store for your coin with at least one item for sale. A store needs a paid plan, any of them, on the wallet that opens it: Who can open a store. Then open the store and add an item.
- The Seller Terms, signed by the wallet that opened the store.
- A store key for your server and, to take live payments, a verified site.
Test mode works on localhost; live needs a verified site. To try the whole flow first with no money and no domain, start at Test mode.
A verified site
For a live payment, the two pages the buyer returns to must be on one of your coin's verified sites: a domain you proved you own for your coin page, with one DNS record. A verified domain covers its subdomains, so verifying example.com also covers shop.example.com, unless the owner set the site to This host only.
- In your coin manager, click your coin's logo and ticker, then the gear. Verified sites shows your record (
chaindaddy-verify=cd-verify-…): copy it. - Add it to your domain's DNS as a TXT record on the domain itself.
- Type the domain under Add a site and press Verify.
Your coin's verified sites has every step. The record is different on every chain your coin is on: verify the site for the coin page your store belongs to.
The same sites decide which pages may open the checkout in a popup and hear how it ended (The button).
A store key
Your server opens and reads sessions with a store key (cd_iap_…). It works on one store and only for the scopes you give it:
| Scope | Needed to |
|---|---|
orders:write | Open a session |
orders:read | Read a session, its order and its receipt |
webhooks:write | Set your store's webhook with the key itself. Optional, and not given by default: the store's owner or a manager can set the webhook instead (A complete handler) |
The store's owner or a manager makes the key, and can hand it to whoever builds the site. In the Developer portal it is the Keys tab of your store: name the key, tick Read orders and Create orders for a user, and press Create key. From the command line:
npm install -g @chaindaddy/cli@beta # once; needs Node.js 20 or later
chaindaddy login # once: sign in through your browser
chaindaddy iap store list # your stores and their ids
chaindaddy iap key create 3f0c… --name site-checkout --scope orders:read orders:write
# prints the cd_iap_… secret ONCE
export CHAINDADDY_IAP_KEY=cd_iap_… # on your server, with its other secretsThe examples on this page read the key from CHAINDADDY_IAP_KEY, the variable the CLI reads a store key from.
Over HTTP it is POST /api/v2/iap/stores/{storeId}/keys with {"name": "site-checkout", "scopes": ["orders:read", "orders:write"]} and your account credentials. Store keys lists every scope and the rate limits.
The key stays on your server. Never put it in a web page, a mobile app or a repository.
The fee is the same
A sale through a checkout session costs what the same item costs on chaindaddy.io: 2.5% of the sale, or 0% when your coin launched in a Chain Daddy launchpad pool. See Fees.
1. Open a session
One call from your server:
curl -X POST https://api.chaindaddy.io/api/v2/iap/checkout/sessions \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY" \
-H "Idempotency-Key: cart-8842-attempt-1" \
-H "Content-Type: application/json" \
-d '{
"lineItems": [{ "sku": "credits.100", "quantity": 1 }],
"successUrl": "https://example.com/thanks",
"cancelUrl": "https://example.com/cart",
"clientReferenceId": "cart-8842"
}'// open-session.mjs run: CHAINDADDY_IAP_KEY=cd_iap_… node open-session.mjs
// Node 20 or later. Server only: the key never goes to a browser.
const cart = { id: '8842', attempt: 1, sku: 'credits.100', quantity: 1 }; // from your own records
const res = await fetch('https://api.chaindaddy.io/api/v2/iap/checkout/sessions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHAINDADDY_IAP_KEY}`,
'Idempotency-Key': `cart-${cart.id}-attempt-${cart.attempt}`, // the same key when you retry this attempt
'Content-Type': 'application/json',
},
body: JSON.stringify({
lineItems: [{ sku: cart.sku, quantity: cart.quantity }],
successUrl: 'https://example.com/thanks',
cancelUrl: 'https://example.com/cart',
clientReferenceId: `cart-${cart.id}`,
}),
});
const session = await res.json();
if (!res.ok) {
// { error, code }: match on code. See Errors below.
throw new Error(`${res.status} ${session.code ?? ''} ${session.error}`);
}
// Save session.id with the cart before the buyer leaves: the webhook names it.
console.log(session.id, session.status, session.expiresAt);
console.log(session.url); // send the buyer here{
"id": "cs_0f3a9c1e5b7d2a4c6e8f0b1d3a5c7e9f1b3d5a7c9e0f2a4c",
"url": "https://chaindaddy.io/_pay/cs_0f3a9c1e5b7d2a4c6e8f0b1d3a5c7e9f1b3d5a7c9e0f2a4c",
"status": "open",
"livemode": true,
"expiresAt": "2026-10-10T19:00:00Z"
}A new session answers 201. The answer also repeats what you sent and carries storeId, createdAt, completedAt, order and receipt; the last three are null until somebody pays and you read the session.
credits.100 in these examples stands for one of your own items: find an item's sku.
What you send:
| Field | |
|---|---|
lineItems | Required. Exactly one item: its sku and a quantity from 1 to 10,000 (1 when left out). An item a wallet owns once (non_consumable) is sold one at a time. The price is the item's own |
successUrl | Required. Where the buyer returns after paying. An https page on one of your coin's verified sites or a subdomain of one (its www. only, for a site set to This host only), on the default port, with no user:password@ in it, up to 2,048 characters, with no space, control character or invisible character anywhere in it (percent-encode what is not plain text). With a test store's key it may also be http://localhost or http://127.0.0.1, on any port |
cancelUrl | Required. Where the buyer returns if they leave without paying. Same rule |
clientReferenceId | Optional. Your own id for this checkout, up to 128 characters, with no control characters. It comes back as appAccountToken on the order, its events and its receipt. The buyer can read their own order and receipt, so use a reference, not a secret |
metadata | Optional. Your own JSON object, up to 20 keys and 4,096 bytes, with no NUL character (\u0000) in a key or a text value. Returned when you read the session; the buyer does not see it. {} when left out |
wallet | Optional. An address on your store's chain. When set, only this wallet can pay the session |
expiresInSeconds | Optional. How long the session can be paid: 900 (15 minutes) to 86400 (24 hours). 3600 (one hour) when left out |
A field the API does not know is refused (400 INVALID_REQUEST).
The Idempotency-Key header is required, up to 255 characters. Use one key per checkout attempt on your side:
| You send | You get |
|---|---|
| The same key with the same request | The session that key first opened, with status 200 and the header Idempotent-Replayed: true |
| The same key with a different request | 422 IDEMPOTENCY_KEY_REUSED. Use a new key for a new session |
| No key | 400 IDEMPOTENCY_KEY_REQUIRED |
Only your store key can open a session. A signed-in session answers 403 STORE_KEY_REQUIRED.
Find an item's sku
A store key lists the items of its own store, whatever its scopes. First the store the key belongs to, then that store's items:
curl https://api.chaindaddy.io/api/v2/iap/stores \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY"
# → {"entries":[{"id":"3f0c…","symbol":"FLUXGP","chainKey":"base","mode":"live",…}]}
curl https://api.chaindaddy.io/api/v2/iap/stores/3f0c…/skus \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY"
# → {"entries":[{"sku":"credits.100","type":"consumable","name":"100 credits","status":"active","price":"50000000000000000000",…}]}A session can sell an item whose status is active and that has a price or a priceUsdMicros (What a session cannot sell). The list also carries drafts and archived items.
- A test store has its own catalog, a copy of your live one made when the test store was created. List it with the test key: the first call then answers
"mode":"test". - From the command line it is
chaindaddy iap sku list 3f0c…, and in the Developer portal the store's Items tab. - With no key,
curl "https://api.chaindaddy.io/api/v2/iap/public/stores?chainKey=base&crownId=8"answers what your live store has on sale, underskus.crownIdis your coin's page number, from the public coin read.
2. Send the buyer to the link
url is the page the buyer pays on. A plain link is enough:
<a href="https://chaindaddy.io/_pay/cs_0f3a9c1e…">Pay with Chain Daddy</a>Or redirect to it from your server. The buyer signs in and confirms the payment on chaindaddy.io, and is then sent to your successUrl (or your cancelUrl if they leave).
Send the buyer by the link, by the button, which opens the same link in a popup, or by a popup you write yourself; they can be mixed.
What the buyer sees
The page is headed by your coin and its chain, for example "$FLUXGP on Base". Under the heading the page says:
- where the checkout was opened from: "Opened from example.com, a verified site of $FLUXGP." The site is the one your
successUrlis on, or the page that opened the popup once the button has shaken hands with it; - the app, when the item belongs to an installed app;
- your store's name, in smaller type, then the item and the quantity.
Then it opens the same purchase sheet your coin page uses: the buyer signs in with their wallet if they are not signed in already, sees the price, which is locked when they press Buy, confirms in their wallet, presses Done and comes back to your site.
A buyer who does not hold enough of what the item is priced in is told how much more they need, before any order is made. For your coin, Buy $COIN in a new tab opens your coin page's Buy, and the checkout stays open behind it: they come back and press Check again. For USDC, Get USDC tops up in place.
If they close the sheet without paying, they stay on the page, where they can pay after all or press Cancel and go back. A test store's session says "Test mode", and one opened from your own machine says "Opened from localhost:3000 on this computer, in test mode."
A session with wallet set. The page says which wallet can pay. A buyer connected or signed in with any other wallet is told "This checkout is for wallet 0x12…ab. Switch wallets to pay." and is offered no Pay until they switch.
A session that is already paid says so and offers the way back.
A session that has expired says "This checkout has expired. Nothing was charged. Start again from the site you came from." and offers the way back to the site of your cancelUrl. An order made before the expiry can still be paid until its own deadline (A payment that arrives after the session expired).
One buyer pays a session at a time.
Coming back by link
After paying, the buyer's browser goes to your successUrl with the session's id added. Whatever query and fragment your URL had are kept:
https://example.com/thanks?cart=8842&session_id=cs_0f3a9c1e…Leaving without paying goes to cancelUrl the same way. Use session_id to look the session up on your server; do not treat arriving there as payment.
The button
Add one script and one attribute, and the same link opens the checkout in a popup. The buyer stays on your page:
<script async src="https://js.chaindaddy.io/v1/cd.js"></script>
<a href="https://chaindaddy.io/_pay/cs_0f3a9c1e…" data-cd-checkout data-cd-success="/thanks">Pay with Chain Daddy</a>- It is still a link. With no script, or when the browser blocks the popup, the buyer follows it and comes back to your
successUrl. data-cd-successis the page to go to once the buyer has paid.session_idis added to it, exactly as on yoursuccessUrl. Leave it out and the page stays where it is.- The element fires
cd:checkoutwhen the visit ends.event.detail.statusiscompleted,cancelled,closed(the popup closed and said nothing) orredirected(the popup was blocked and the page is going by link). Oncompleted,event.detail.sessionholds the session'sid, itsorderIdand itsstatus. - Your page must be on one of your coin's verified sites, over https, for the checkout to answer it. A test store's session also answers a page on
http://localhostorhttp://127.0.0.1. Anywhere else the buyer still pays and is returned by link.
<script>
document.addEventListener('cd:checkout', (e) => {
if (e.detail.status === 'completed') showThanks(e.detail.session); // for display only
});
</script>If your page has no session until the buyer clicks, open it from your own code. Pass a function that fetches the link: the popup opens at once, inside the click, and goes to the session when it arrives.
payButton.addEventListener('click', async () => {
const result = await ChainDaddy.checkout({
url: () => fetch('/api/checkout', { method: 'POST' }).then((r) => r.json()).then((s) => s.url),
successUrl: '/thanks',
});
});/api/checkout is a route on your own server, on the same origin as the page. It opens the session with your key and answers the page the link:
// checkout-route.mjs run: CHAINDADDY_IAP_KEY=cd_iap_… node checkout-route.mjs
// Node 20 or later, no packages. Server only: the key never goes to a browser.
import { createServer } from 'node:http';
import { randomUUID } from 'node:crypto';
createServer(async (req, res) => {
if (req.method !== 'POST' || req.url !== '/api/checkout') {
res.writeHead(404).end();
return;
}
try {
const reference = `cart-${randomUUID()}`; // your own id for this checkout
const answer = await fetch('https://api.chaindaddy.io/api/v2/iap/checkout/sessions', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.CHAINDADDY_IAP_KEY}`,
'Idempotency-Key': reference, // the same key when you retry this attempt
'Content-Type': 'application/json',
},
body: JSON.stringify({
lineItems: [{ sku: 'credits.100', quantity: 1 }],
successUrl: 'https://example.com/thanks',
cancelUrl: 'https://example.com/cart',
clientReferenceId: reference,
}),
});
const session = await answer.json();
if (!answer.ok) throw new Error(`${answer.status} ${session.code ?? ''} ${session.error ?? ''}`);
// Save session.id with the cart here, before the buyer leaves: the return and the webhook name it.
res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({ url: session.url }));
} catch (err) {
console.error(err); // for you: the buyer gets your own words
res.writeHead(502, { 'Content-Type': 'application/json' }).end(JSON.stringify({ error: 'Could not open the checkout. Try again.' }));
}
}).listen(3000);The example is this route with the page and the return page around it, ready to run on http://localhost:3000.
What the script hears is not payment: confirm the payment on your server. Every option is in the JavaScript SDK reference.
In a popup, by hand
The button does this for you. If you would rather write it yourself, your page opens url in a popup and is told how it ended. The checkout only talks to the window that opened it, and only when that window's page is on one of your coin's verified sites. A test store's session also answers a page on http://localhost or http://127.0.0.1.
<button id="pay">Pay with Chain Daddy</button>
<script>
const CHECKOUT = 'https://chaindaddy.io';
document.getElementById('pay').addEventListener('click', () => {
const sessionId = new URL(sessionUrl).pathname.split('/').pop(); // cs_…
// Open inside the click, or the browser blocks the popup.
// A new window name every time, one nobody can guess.
const popup = window.open(sessionUrl, 'cd-checkout-' + crypto.randomUUID(), 'popup,width=480,height=820');
if (!popup) { location.assign(sessionUrl); return; } // blocked: use the link
// Keep saying hello while the popup is open, also after it answers:
// a checkout the buyer reloaded has to hear it again.
const hello = setInterval(() => {
if (popup.closed) clearInterval(hello);
else popup.postMessage({ type: 'cd:checkout.hello' }, CHECKOUT);
}, 1000);
window.addEventListener('message', (e) => {
if (e.source !== popup || e.origin !== CHECKOUT) return; // only our popup, only chaindaddy.io
if (!e.data || !e.data.session || e.data.session.id !== sessionId) return; // only the session we opened
if (e.data.type === 'cd:checkout.completed') showThanks(e.data.session); // { id, status, orderId, livemode }
if (e.data.type === 'cd:checkout.cancelled') showCart(e.data.session); // { id }
});
});
</script>The window's name must not be guessable: any frame on your page can reach a window whose name it knows. cd.js does all of this for you: the name, the checks and the hello.
| Message | Sent | session |
|---|---|---|
cd:checkout.hello | By your page, repeatedly, to the popup, for as long as it is open | |
cd:checkout.ready | By the checkout, each time it has checked your page's origin | |
cd:checkout.completed | By the checkout, when the buyer paid. The popup then closes | id, orderId, status (complete when the payment is confirmed, paid when it was sent and is still confirming) and livemode: false for a test store's session, where nothing was charged |
cd:checkout.cancelled | By the checkout, when the buyer canceled. The popup then closes | id |
Always check e.origin and e.source. A completed message is for your page's display only: deliver from your server, on the webhook or by reading the session. If the checkout never answers your hello (your page is not on a verified site, or the browser cut the popup off from your page), the buyer still pays and is returned by link, as above.
When a currency is paused
An item priced in dollars and paid in the coin (or the chain's coin) needs a market that can take the payment. Opening an order answers 409 CURRENCY_PAUSED while payments in that coin are paused, and 422 ORDER_OVER_CURRENCY_CAP when the order is larger than the coin's market can take right now. Both carry alternatives, the other currencies the item takes that would work now. The pay page shows the buyer why. Items priced in a fixed number of tokens, and prices paid in USDC, are not refused this way.
3. Confirm the payment
The buyer landing on successUrl does not prove they paid: anyone can open that address. Deliver when Chain Daddy tells your server.
By webhook. Your store's webhook gets iap.order.confirmed when the payment is confirmed. For an order paid through a session, the event's payload carries checkoutSessionId, and appAccountToken is your clientReferenceId:
{
"type": "iap.order.confirmed",
"data": {
"orderId": "0x9e1f…",
"payload": {
"checkoutSessionId": "cs_0f3a9c1e…",
"appAccountToken": "cart-8842",
"sku": "credits.100",
"quantity": 1,
"status": "confirmed",
"receipt": "eyJhbGciOiJFZERTQSIs…"
}
}
}order.created and order.paid carry checkoutSessionId too. Deliver on order.confirmed.
Match the event to your checkout by checkoutSessionId, which only an order made from your session carries. Do not rely on appAccountToken alone: a buyer can set it on an ordinary order in your store.
A complete handler
Give your store its webhook once, and keep the signing secret it prints with your server's other secrets:
chaindaddy iap webhook set 3f0c… --url https://example.com/hooks/chaindaddy
# prints the whsec_… signing secret ONCE
chaindaddy iap webhook test 3f0c… # sends a signed iap.test event to itwebhook set runs as the account that is logged in: the store's owner or a manager. In the Developer portal it is Settings, then Webhook, on your store. A server that holds only a store key sets the webhook over HTTP, and the key needs the webhooks:write scope for it:
curl -X PUT https://api.chaindaddy.io/api/v2/iap/stores/3f0c…/webhook \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com/hooks/chaindaddy"}'
# → 201 {"id":"…","url":"https://example.com/hooks/chaindaddy","active":true,"secret":"whsec_…",…} the secret is shown ONCESetting it again later answers 200 and keeps the secret. A key with events:read can read the webhook and send the test event. chaindaddy iap webhook test uses the key in CHAINDADDY_IAP_KEY when that variable is set, so with a key that lacks events:read (403 SCOPE_REQUIRED), unset the variable to send the test as yourself.
Then this is the whole receiver. It needs Node 20 or later and one package. It listens on port 4000, a port of its own, so it runs beside a site on port 3000; on your server you can give your site's own server the same route instead:
// webhook.mjs run: CHAINDADDY_WEBHOOK_SECRET=whsec_… node webhook.mjs
import { createServer } from 'node:http';
import { Webhook } from 'standardwebhooks'; // npm install standardwebhooks
// The whsec_… secret exactly as it was shown to you, from your server's secrets.
const wh = new Webhook(process.env.CHAINDADDY_WEBHOOK_SECRET);
// Events already handled, by webhook-id. Here a Set, so the sample runs as it is;
// on a real server use a unique column in your database, so a restart forgets nothing.
const handled = new Set();
// Your own delivery. Look the session up in YOUR records (you saved its id when you
// opened it), check it is the sale you expect, and deliver once per orderId.
async function deliver(sale) {
console.log('deliver', sale);
}
createServer(async (req, res) => {
if (req.method !== 'POST' || req.url !== '/hooks/chaindaddy') {
res.writeHead(404).end();
return;
}
// The body exactly as it was sent: the signature is over these bytes, not over JSON you parsed.
const chunks = [];
for await (const chunk of req) chunks.push(chunk);
const body = Buffer.concat(chunks).toString('utf8');
let event;
try {
// Checks webhook-signature, and refuses a webhook-timestamp more than 5 minutes off.
event = wh.verify(body, req.headers);
} catch {
res.writeHead(401).end();
return;
}
const id = req.headers['webhook-id']; // the event's id, the same on every retry
try {
if (event.type === 'iap.order.confirmed' && !handled.has(id)) {
const { orderId, livemode, payload } = event.data;
// Only an order made from one of your checkout sessions carries checkoutSessionId.
if (payload.checkoutSessionId) {
await deliver({
sessionId: payload.checkoutSessionId, // cs_…, the session you opened
reference: payload.appAccountToken, // your clientReferenceId
orderId,
sku: payload.sku,
quantity: payload.quantity,
livemode, // false for a test store's event
});
}
handled.add(id);
}
res.writeHead(200).end(); // within 5 seconds; queue anything slower
} catch (err) {
console.error(err);
res.writeHead(500).end(); // not handled: the delivery is retried
}
}).listen(process.env.WEBHOOK_PORT || 4000); // not your site's port- It checks the signature first, on the raw body. A request that fails gets
401. The signature is the Standard Webhooks one (webhook-id,webhook-timestamp,webhook-signature), so any Standard Webhooks library does the same check in your language: Webhooks: Check the signature has Python and Go. - It handles each event once. A delivery that failed is sent again with the same
webhook-id, so the same sale can arrive twice. The handler skips an id it has already handled, anddelivershould also refuse anorderIdit has already delivered. - It delivers only on
iap.order.confirmedthat carries acheckoutSessionId, and answers200to every other event so it is not sent again. - It answers
200only afterdeliverreturns. Ifdeliverthrows, the500gets the event sent again later. Answer within 5 seconds: if delivering takes longer, save the event, answer, and do the work from a queue. - On a live server, refuse
livemode: false. A test store's events go to the test store's own webhook, so a test event at your live endpoint is a misconfiguration.
By reading the session. With a key that has orders:read:
curl https://api.chaindaddy.io/api/v2/iap/checkout/sessions/cs_0f3a9c1e… \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY"status is open, complete once the payment is confirmed, or expired. order is the order that paid the session (while it is open, the buyer's latest attempt), and receipt is that order's signed receipt once the session is complete. Check the receipt the same way as any other: Verifying receipts on your server.
A session that expired unpaid is removed 30 days later; its id then answers 404 NOT_FOUND.
On chain. The order in the session read carries a verification block: the contract, the payees and the amounts. Verify a payment has the one-call check with @chaindaddy/js/verify and the same check by hand. Do this before you hand over something a buyer could resell or cannot give back.
If a webhook went missing, every event stays in your store's event feed, and chaindaddy iap webhook redeliver <store> --after <eventId> sends them to your endpoint again under their original ids.
A buyer can try more than once while a session is open. Each try is an order of its own, and the first one confirmed completes the session; no new try can start after that, or after expiresAt. If the same buyer pays two tries, each confirms and delivers like any order, so treat each order.confirmed as one purchase; the second order carries order.checkout_paid_again, and the session read lists it in extraOrderIds (One buyer at a time).
A payment that arrives after the session expired
expiresAt stops new tries. It does not cut off a try that is already under way.
- An order made before
expiresAtkeeps its own deadline. That is about 20 minutes from the moment the buyer pressed Buy, or 5 minutes for an item priced in dollars and paid in your coin or the chain's coin; theorderin the session read carries it as its ownexpiresAt. Paid by then, it confirms as usual even if the session has expired in the meantime: the session goes fromexpiredtocomplete, and your webhook getsiap.order.confirmedwith itscheckoutSessionId.expiredis final once that order's deadline has passed too. Keep handling the webhook until then. - A new try after
expiresAtis refused (409 CHECKOUT_SESSION_EXPIRED). Open a new session for the buyer. - A payment sent after the order's own deadline. On an EVM chain the checkout contract refuses it and no money moves. On Solana a transfer that lands up to 2 minutes after the deadline still counts. One that lands later grants nothing: it is recorded as
order.mismatchwith"reason": "late", and your share of it is in your payout wallet. Settle it with the payer, whose wallet and transaction the event names: send it back from your own wallet, or deliver what they paid for yourself.
Test mode
Take a first test payment on your own machine with nothing but a test store's key: no money, no domain and no wallet.
No key yet? Use the demo key
This key belongs to a demo test store, and it is public:
cd_iap_test_0f4825d155a0bca77bb737dd291f39f3bad9367633f2a4593d2175af52d41fd8The example uses it by itself when you give it no key, so you can start there right now.
- Test mode only. Nothing is sent on chain and no money moves.
- Your own machine only. Its checkout returns to
http://localhostorhttp://127.0.0.1, on any port, and to nowhere else (403 DEMO_KEY_LOCALHOST_ONLY). It opens, reads and completes a checkout, and reads an order by its id. Everything else answers403 DEMO_KEY_NOT_ALLOWED, and it sells at most 10 of an item that cannot run out (403 DEMO_KEY_ITEM). - It is shared. It allows 30 requests a minute and 300 a day from one address, and
429beyond that. Send it no real names, emails or order numbers: use made-up values. - What it makes is deleted after a day. A session you opened yesterday answers
404.
When it works, get your own test key for your own coin's test store: it has none of these limits, sells your own items and can return to your site.
Your store has a test store beside it, with its own catalog, keys and webhook. A session opened with a test store's key is a test session: it says "livemode": false and no fee is taken.
Get your own test key
The store's owner or a manager makes the test store and its key once, and can hand the key to whoever builds the site.
With buttons, in the Developer portal:
- Open chaindaddy.io/_developer/store and choose your store.
- Beside the store's name, switch Live to Test. The first time, that creates the test store with a copy of your items. A banner says "TEST MODE".
- On the Keys tab, under New test key, name the key, tick Read orders and Create orders for a user, and press Create key.
- Copy the
cd_iap_test_…secret. It is shown once.
From the command line:
npm install -g @chaindaddy/cli@beta # once; needs Node.js 20 or later
chaindaddy login # once: sign in through your browser
chaindaddy iap store test 3f0c… # your live store's id, or your coin's ticker; prints the test store's id
chaindaddy iap key create 7a21… --name test-checkout --scope orders:read orders:write
# prints the cd_iap_test_… secret ONCEWhoever builds the site then needs only the key:
export CHAINDADDY_IAP_KEY=cd_iap_test_…Send this to the coin's owner
Building the site for someone else? The key is the one thing you need from them. Send them this:
To build the checkout on your site I need a test key for your coin's store.
It works on your test store only: no money moves and nothing is sent on chain.
1. Open https://chaindaddy.io/_developer/store and choose your store.
2. Beside the store's name, switch Live to Test.
3. On the Keys tab, under New test key: name the key, tick "Read orders"
and "Create orders for a user", and press Create key.
4. Send me the cd_iap_test_… secret. It is shown once.With those two scopes the key opens, reads and completes test sessions, and lists the test store's items, which start as a copy of the live catalog. Setting the test store's webhook needs more: The test store's webhook.
Run the example
Three files make a whole site for your own machine:
| File | What it is |
|---|---|
server.mjs | The server, in plain JavaScript: Node.js 20 or later, no packages to install. It holds the key |
index.html | The page with the button |
thanks.html | The page the buyer returns to |
mkdir checkout-example && cd checkout-example
curl -sSfO https://docs.chaindaddy.io/examples/checkout/server.mjs
curl -sSfO https://docs.chaindaddy.io/examples/checkout/index.html
curl -sSfO https://docs.chaindaddy.io/examples/checkout/thanks.html
node server.mjs # with the demo key
# Using the demo key: a shared test store, test mode only. …
# Store: FLUX GP (test) on base, test mode
# This site sells: nitro (…). To sell another: CHECKOUT_SKU=<sku>
# Open http://localhost:3000
CHAINDADDY_IAP_KEY=cd_iap_test_… node server.mjs # or with your own test store's keyThe server reads the key from CHAINDADDY_IAP_KEY, lists your test store's items and picks one a session can sell. To sell a different one, start it with CHECKOUT_SKU=<sku> as well. A key Chain Daddy does not know stops it at once with 401 INVALID_STORE_KEY. If something else is on port 3000, start it with PORT=3001 node server.mjs and use that port in the addresses below.
Open
http://localhost:3000and press Pay with Chain Daddy. A pay window opens on chaindaddy.io. It says "Test mode. No money moves and nothing is sent on chain." and "Opened from localhost:3000 on this computer, in test mode." It may show Sign in to buy over the page: leave it as it is. You do not have to sign in, and the next step completes the payment without it.In a second terminal, complete the payment with the test key the server holds:
bashcurl -X POST http://localhost:3000/api/test-pay # → {"id":"cs_…","status":"complete","livemode":false,"orderId":"0x…"}You should see the pay window close and your page go to
/thanks?session_id=cs_…, which says Paid and "Test mode: nothing was charged." The server's terminal prints oneDELIVERline.
To read the session back yourself, as your server will, copy the cs_… id that curl just printed (it is also in the /thanks address). With your own key, use it in place of the demo key:
curl https://api.chaindaddy.io/api/v2/iap/checkout/sessions/cs_… \
-H "Authorization: Bearer cd_iap_test_0f4825d155a0bca77bb737dd291f39f3bad9367633f2a4593d2175af52d41fd8"
# → one long line of JSON: look for "status":"complete" and "livemode":false. The order is in "order".The pay window looks for the payment every few seconds while it is showing. If it is behind another window or in a background tab, bring it to the front and it looks at once.
What the server does, route by route:
| Route | What it does |
|---|---|
POST /api/checkout | Opens a session with the key, with http://localhost:3000/thanks and /cart as its return URLs, and answers the page its link |
GET /api/checkout/status?session_id=cs_… | Reads the session with the key and delivers, once, when it is complete. The return page shows Paid only on this answer, so no webhook is needed on your own machine |
POST /api/test-pay | Test only: completes the session with the test key: the test-pay call of The same by hand |
The example takes a test store's key only and stops with any other. When you build your own server from it, verify your site, give the session https return URLs on it, use the live store's key, and leave out the /api/test-pay route.
The same by hand
1. Hold a test key in CHAINDADDY_IAP_KEY: your own, or the demo key, which sells the item nitro. The example sets nothing in your shell, so export it first:
export CHAINDADDY_IAP_KEY=cd_iap_test_0f4825d155a0bca77bb737dd291f39f3bad9367633f2a4593d2175af52d41fd8 # the demo key, or your own2. Open a session that returns to localhost. The same call as live, with http://localhost (or http://127.0.0.1) return URLs, on whatever port your site runs on. Use the sku of one of your own items:
curl -X POST https://api.chaindaddy.io/api/v2/iap/checkout/sessions \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{
"lineItems": [{ "sku": "credits.100", "quantity": 1 }],
"successUrl": "http://localhost:3000/thanks",
"cancelUrl": "http://localhost:3000/cart",
"clientReferenceId": "test-cart-1"
}'
# → {"id":"cs_…","url":"https://chaindaddy.io/_pay/cs_…","status":"open","livemode":false,…}Idempotency-Key is a fresh value for each new checkout (uuidgen prints one); send the same value again only to retry the same request.
3. Open the link. Open the session's url in your browser, or put it behind the button on your http://localhost page. The page says "Test mode" and "Opened from localhost:3000 on this computer, in test mode." You do not have to sign in: leave the page open and in view.
4. Complete it with one call. Name the wallet the test items go to: any address on your store's chain. The example works for a store on an EVM chain; for a Solana store send any Solana address. If the session names a wallet, leave the body out.
curl -X POST https://api.chaindaddy.io/api/v2/iap/checkout/sessions/cs_…/test-pay \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"wallet": "0x00000000000000000000000000000000000000d4"}'
# → {"id":"cs_…","status":"complete","livemode":false,"order":{"status":"confirmed",…},"receipt":"eyJ…"}Within a few seconds the open page notices: it goes to http://localhost:3000/thanks?session_id=cs_…, or tells your page completed if it was opened in a popup.
5. Read the session. It reads complete, with the order and its receipt. This is the confirmation that needs nothing but the key, and it works on your own machine:
curl https://api.chaindaddy.io/api/v2/iap/checkout/sessions/cs_… \
-H "Authorization: Bearer $CHAINDADDY_IAP_KEY"What is, and is not, relaxed for a test store:
- Return URLs and the popup's page may be
http://localhostorhttp://127.0.0.1, on any port. Anything else must behttpson a verified site. A live store's key given a localhost URL answers400 RETURN_URL_NOT_VERIFIED. test-paycompletes a test store's own sessions, with that store's key (orders:write). A live store's key answers409 LIVE_ORDER.- The rest is the live rule. The Seller Terms must be signed by the wallet that opened the store, and its plan must be current.
Paying on the page instead. You can also press Buy on the test session's page, as a buyer would. Sign in as a wallet with the Owner or Manager role on your coin page: a test store is shown only to the people who manage the coin page (another wallet's order answers 404 NOT_FOUND). Buy completes the purchase at once.
test-pay cannot buy an item that belongs to an installed app (403 SESSION_REQUIRED): pay that session on its page.
A test order has no verification block.
The test store's webhook
The test store has a webhook of its own. It gets iap.order.confirmed with "livemode": false and your session's checkoutSessionId. You do not need it to take a test payment. To try your handler too, two things are needed that the test key alone does not give you:
A public
httpsaddress. A webhook URL cannot belocalhost, so point a tunnel at the port your handler listens on and use the tunnel's address. The handler listens on port 4000, not on your site's port 3000: withcloudflared, which needs no account, that iscloudflared tunnel --url http://localhost:4000.Someone allowed to set it. The store's owner or a manager sets it:
chaindaddy iap webhook set 7a21… --url https://…/hooks/chaindaddyruns as the account that is logged in, and in the Developer portal it is Test, then Settings, then Webhook. A store key can set it only over HTTP, and only with thewebhooks:writescope, which is not given by default. Ask for it when the key is made (--scope orders:read orders:write webhooks:write, or tick Set the store webhook), then:bashcurl -X PUT https://api.chaindaddy.io/api/v2/iap/stores/7a21…/webhook \ -H "Authorization: Bearer $CHAINDADDY_IAP_KEY" \ -H "Content-Type: application/json" \ -d '{"url": "https://YOUR-TUNNEL.example/hooks/chaindaddy"}' # → 201 {"url":"https://YOUR-TUNNEL.example/hooks/chaindaddy","secret":"whsec_…",…} the secret is shown ONCE7a21…is the test store's id:GET /api/v2/iap/storeswith the key answers it.
One buyer at a time
A session is one checkout for one buyer. While one wallet has a purchase of it under way (an order that can still be paid, or one that is paid and confirming), any other wallet that tries to pay the same link is told someone else is paying (409 CHECKOUT_SESSION_IN_USE). The link frees itself a few minutes after that purchase's deadline passes unpaid, and any wallet with the link can then take it over, so anyone with the link can keep it busy until the session expires.
- Open one session per buyer, and keep its link private to that buyer. Do not put one session's link on a public page or share it between people.
- Set
walletwhen you know the buyer's wallet. Then only that wallet can order: any other wallet gets403 CHECKOUT_SESSION_WALLET. - The same wallet can try again at once after a payment that failed. A retry pays the same order, and on an EVM chain the checkout takes an order's payment once, so a buyer who taps Pay twice, reloads the page or opens the link in another tab is charged once.
- If one checkout is paid twice, both orders deliver, and your store is told: the second order carries
order.checkout_paid_again(webhookiap.order.checkout_paid_again), which names the first order infirstOrderId, and its page in the Developer portal says who paid and how much to send back if the buyer did not mean to. You and the buyer each get a notice. You send it from your own wallet and record the refund there; Chain Daddy then returns its own fee on that second payment to the buyer on request.
What a session cannot sell
- An item that belongs to an app installed on your page, unless the app's developer allows it: see Items of an app you installed.
- An unlock, an item with no price, or an archived item.
- More than one of an item a wallet owns once (
non_consumable). - Shipping or tax (see Physical goods).
Physical goods
Physical items are sold only by Chain Daddy's own store. A coin's store can't create one, and an order or session for one is refused with 409 PHYSICAL_ITEM.
Items of an app you installed
An app you installed on your coin page can bring items of its own, with a share of each sale going to its developer (Items from apps you installed). Their sku starts with app.. Your site can sell one through a session when the app's developer has allowed that item to be sold outside the app.
- Open the session the same way, with the item's
skuas the one line item. You set no price: the item's price and the developer's share are the ones you accepted when you installed the app. - The money goes where it goes inside the app: your payout wallet, the fee, and the developer's share, in the buyer's one transaction. So the order's
payoutAmountis less than itsamount; when you verify the payment on chain, passpayoutAmountasexpect.amount. - The buyer agrees that the sale is final on the checkout page. A sale of an app's item cannot be refunded on the order.
- The app's limits apply. A session takes at most the app's quantity per order (
maxQuantityunderpaidAppsinGET /api/v2/iap/config), and the buyer's wallet stays within what it may pay that app in a day. - If it is refused, the answer is
409 APP_ITEM_NOT_SOLD_HEREwith areason:
reason | What to do |
|---|---|
not_allowed_outside_app | The developer has not allowed this item outside the app. Ask them to turn it on. It still sells inside the app on your coin page |
app_not_installed | The app is not installed on your coin page. Install it again |
terms_changed | The developer changed the item's price or terms. The coin's owner accepts them under Apps in the page manager, and it sells again |
item_not_for_sale | The app no longer sells this item |
| anything else | The app is not selling right now (for example developer_paused). Nothing for you to change; try later |
The same is checked again when the buyer pays. If the developer turns the item off, pauses or changes its terms after you opened a session, the buyer is told the item is not sold on your site right now and is charged nothing. Open a new session once it sells again.
Errors
Errors are {"error": "...", "code": "..."}. The error text says what to fix; match on code.
Opening a session (POST /api/v2/iap/checkout/sessions) and reading one (GET /api/v2/iap/checkout/sessions/{id}):
| Status | code | What happened, and what to do |
|---|---|---|
| 400 | IDEMPOTENCY_KEY_REQUIRED | No Idempotency-Key header on the call that opens a session. Send one |
| 400 | IDEMPOTENCY_KEY_INVALID | The Idempotency-Key is longer than 255 characters |
| 400 | INVALID_REQUEST | A field is missing, misspelt, out of range or holds a character it may not, sku is not shaped like an item's key, lineItems does not hold exactly one item, or quantity is above 1 for an item a wallet owns once (non_consumable). The message says which |
| 400 | RETURN_URL_NOT_VERIFIED | successUrl or cancelUrl is not an https page on one of your coin's verified sites. The message lists the sites that pass, or says there are none yet. Verify the site first. http://localhost and http://127.0.0.1 pass with a test store's key only: a live key is refused them |
| 401 | INVALID_STORE_KEY | The store key is unknown or revoked. Create a new one |
| 401 | AUTHENTICATION_REQUIRED | No credential at all. Send the store key as Authorization: Bearer cd_iap_… |
| 403 | STORE_KEY_REQUIRED | Called with a signed-in session or an account key instead of a store key |
| 403 | SCOPE_REQUIRED | The key lacks orders:write (to open) or orders:read (to read). Create a key with both |
| 403 | STORE_NOT_LIVE | The store is paused, or the plan of the wallet that opened it has lapsed: resume the store or renew the plan. With reason owner_changed, the page has a new owner who has not opened the store yet: it sells again once they open it |
| 403 | SELLER_TERMS_REQUIRED | The wallet that opened the store has not signed the Seller Terms |
| 404 | SKU_NOT_FOR_SALE | No such item in your store. Check the sku (a test store has its own catalog) |
| 404 | NOT_FOUND | No such session, or it belongs to another store |
| 409 | SKU_NOT_FOR_SALE | The item cannot be sold through a session. See What a session cannot sell |
| 409 | APP_ITEM_NOT_SOLD_HERE | The item belongs to an app installed on your page and cannot be sold from your site now. reason says why: see Items of an app you installed |
| 409 | PHYSICAL_ITEM | A physical item: coin stores don't sell them |
| 422 | IDEMPOTENCY_KEY_REUSED | This Idempotency-Key already opened a different session. Use a new key |
| 429 | rate_limit_exceeded | Too many calls: the store key rate limits. Wait for Retry-After seconds and send the same request with the same Idempotency-Key |
| 500 | INTERNAL_ERROR | Something failed on our side. Retry with the same Idempotency-Key |
| 503 | IAP_DISABLED | The store is switched off. Retry later with the same key |
The buyer's payment. The checkout page answers these to the buyer; they are here so you can recognize what a buyer describes:
| Status | code | What happened, and what to do |
|---|---|---|
| 400 | FINAL_SALE_ACK_REQUIRED | The session's item belongs to an app and the buyer has not ticked that the sale is final. The checkout page asks for it |
| 401 | AUTHENTICATION_REQUIRED | The buyer is not signed in. The checkout page signs them in before it asks |
| 403 | CHECKOUT_SESSION_WALLET | The session names another wallet. The buyer signs in with the wallet you set |
| 403 | SESSION_REQUIRED | A store key tried to pay a session. Only the buyer, signed in on chaindaddy.io, pays one. (A test store's key completes its own test session with test-pay, a different call) |
| 404 | NOT_FOUND | No such session; or it is a test session and the wallet does not manage your coin page |
| 409 | CHECKOUT_SESSION_IN_USE | Another wallet is paying this session right now. It frees itself a few minutes after that purchase's deadline passes unpaid. See One buyer at a time |
| 409 | CHECKOUT_SESSION_EXPIRED | The session is past expiresAt. Open a new one |
| 409 | CHECKOUT_SESSION_COMPLETE | The session was already paid. Open a new one for another purchase |
| 409 | APP_ITEM_NOT_SOLD_HERE | The session's item belongs to an app, and it stopped being sold on your site after you opened the session. The buyer is charged nothing. See Items of an app you installed |
| 409 | WALLET_LIMIT | The wallet already holds the most of this item one wallet may: the item's maxPerWallet, which is always 1 for an item a wallet owns once (non_consumable). An unpaid order that can still be paid counts. The buyer is charged nothing. Nothing to change on your server; to sell one wallet more of an item that can be bought again, raise its maxPerWallet |
Completing a test session (POST /api/v2/iap/checkout/sessions/{id}/test-pay, Test mode). The codes of opening a session apply (the key, its scope, Idempotency-Key), and:
| Status | code | What happened, and what to do |
|---|---|---|
| 400 | INVALID_REQUEST | No wallet, and the session names none; or wallet is not an address on your store's chain |
| 403 | CHECKOUT_SESSION_WALLET | The session names another wallet. Leave wallet out, or send that one |
| 403 | IAP_PLAN_REQUIRED | The plan of the wallet that opened the store has lapsed |
| 403 | SESSION_REQUIRED | The session's item belongs to an installed app. Pay it on its page |
| 404 | NOT_FOUND | No such session, or it belongs to another store |
| 409 | LIVE_ORDER | The session is a live store's. A live session is paid by the buyer, on chaindaddy.io |
| 409 | CHECKOUT_SESSION_COMPLETE | Already paid. Open a new session |
| 409 | CHECKOUT_SESSION_EXPIRED | Past expiresAt. Open a new session |
| 409 | CHECKOUT_SESSION_IN_USE | Another wallet has an unpaid order for it (someone pressed Buy on its page). Send that wallet, or wait a few minutes past that order's deadline |
| 409 | ORDER_EXPIRED | The order this Idempotency-Key made was never paid and has lapsed. Use a new key |
| 409 | WALLET_LIMIT | The wallet already holds the most of this item one wallet may (the item's maxPerWallet; always 1 for a non_consumable item). Test orders count. Send another wallet. The example pays every test to the same wallet, so with an item a wallet owns once its second payment answers this: start it with CHECKOUT_SKU=<sku> of an item that can be bought again |
| 422 | IDEMPOTENCY_KEY_REUSED | This Idempotency-Key already made an order for another session or wallet. Use a new key |
Everything else a purchase can answer (an item that sold out, a per-wallet limit, which answers 409 WALLET_LIMIT, a rule the wallet does not meet, a dollar price with no rate right now) is the same as for any order in your store.
Related docs
- Store and Rewards: items, store keys, events, webhooks and receipts
- Your coin's verified sites: prove a domain is yours
- JavaScript SDK: every option of the button and of
checkout() - Verify a Payment: check on chain that an order was paid
- Test checkout on your site: a test store, test keys and a test session, with no money
- Webhooks: signatures, retries and every event type