Blog

Build your own crypto checkout UI with quotes

CoinStack12 min read
Integrations

To build your own crypto checkout UI with CoinStack, your server creates a checkout, lists tokens and drops any whose minimum is above the checkout's value, then creates a quote for the token and network the customer picks. The quote gives you the deposit address, the remaining amount in the token's smallest unit and a uri for the QR code. Show a countdown to expires_at for volatile tokens, refresh when it ends, and follow the payment with webhooks.

When is a custom checkout worth building?

The hosted checkout page already does all of this: token choice, address, amount, QR code, price countdown and live status. You send the customer to its url and listen for one webhook. You can also build the same flow inside your own interface, for example inside a dashboard where customers top up a balance, in a mobile app, or in a single-page checkout where a redirect would interrupt the flow. Hosted checkout page or your own interface weighs the trade-offs; this post assumes you have decided to build.

The flow in the custom checkout guide has 4 parts, and every API call happens on your server because each one needs your secret API key:

StepAPI callWhat your page shows
1. Create a checkoutPOST /checkoutsNothing yet
2. Offer tokens and networksGET /tokensThe options this order can be paid with
3. Create a quotePOST /checkouts/{checkout_id}/quotesNetwork, amount, address, QR code, countdown
4. Track the paymentWebhooks and GET /checkouts/{checkout_id}Confirming, partly paid, paid or closed

The examples use Node.js 18 or later (for the built-in fetch), Express 5 and the qrcode package, in an ES module project. findOrder, saveCheckoutId and assertOwnsCheckout stand for your own database code; the last one must confirm that the checkout ID in the URL belongs to the signed-in customer, or anyone could read someone else's payment details.

Server setup and amount formatting

A small wrapper sends the Bearer key, adds Content-Type: application/json only when there is a body, and unwraps the {"success": ..., "response": ...} envelope. The second function turns token amounts into display text.

import express from "express";
import QRCode from "qrcode";

const API = "https://coinstack.net/api/v1";
const ACCEPTED = new Set(["base:USDC", "solana:USDC", "tron:USDT", "ethereum:USDT", "bitcoin:BTC"]);

async function coinstack(method, path, payload) {
  const response = await fetch(API + path, {
    method,
    headers: {
      Authorization: `Bearer ${process.env.COINSTACK_API_KEY}`,
      ...(payload && { "Content-Type": "application/json" }),
    },
    body: payload && JSON.stringify(payload),
  });
  const body = await response.json();

  if (!body.success) {
    throw Object.assign(new Error(body.response), { status: response.status });
  }

  return body.response;
}

function toDisplay(smallest, decimals) {
  if (decimals === 0) return smallest;
  const digits = smallest.padStart(decimals + 1, "0");
  const fraction = digits.slice(-decimals).replace(/0+$/, "");
  return fraction ? `${digits.slice(0, -decimals)}.${fraction}` : digits.slice(0, -decimals);
}

const app = express();

Quote amounts are strings in the token's smallest unit, and the API overview says to divide them by 10 raised to the token's decimals. toDisplay does that with string operations rather than floating point, because a JavaScript number stops being exact above 2^53, about 9 x 10^15, and 0.01 ETH is already 10^16 of its smallest unit. "25000000" with 6 decimals becomes 25, "1234" with 8 decimals becomes 0.00001234, and "1500000000000000000" with 18 decimals becomes 1.5. A customer who sends a rounded amount ends up short.

ACCEPTED mirrors what you enabled under Settings, then Payment methods, in the dashboard. The docs explain why you need it: tokens you turned off "still appear in this list", and quoting one returns Invalid token.

Steps 1 and 2: create the checkout and offer tokens

app.post("/api/orders/:orderId/pay", async (req, res) => {
  const order = await findOrder(req.params.orderId); // your own lookup
  const { checkout } = await coinstack("POST", "/checkouts", {
    amount: order.total, // a string such as "49.00"
    currency: order.currency,
    reference: `order-${order.id}`,
  });
  await saveCheckoutId(order.id, checkout.checkout_id);

  const { tokens } = await coinstack("GET", "/tokens");
  const options = tokens
    .filter((t) => t.active && ACCEPTED.has(`${t.network}:${t.token}`))
    .filter((t) => Number(t.minimum) <= Number(checkout.value))
    .map(({ network, token, decimals, stable }) => ({ network, token, decimals, stable }));

  res.json({ checkoutId: checkout.checkout_id, options });
});

The checkout needs no success_url or cancel_url, because the customer never sees the hosted page. Its value is the order converted to US dollars when it was created, and it never changes.

minimum is the smallest checkout value, in US dollars, that a token on a network can pay. It is 1 US dollar on most networks and higher where network cost is high, such as Bitcoin and TRON. Comparing it with value before you show an option avoids a button that fails with Amount below minimum. Read minimum from the live list instead of hard-coding it; the tokens reference calls that list "the list to build against". The same response includes cost, the current network cost estimate per token, if you want to show it.

Group the options by network in your interface. Customers who hold USDT need to choose between, say, TRON and Ethereum, and a list of bare token names hides that choice. Which networks should you enable covers the selection itself.

Step 3: create a quote and show it

When the customer picks an option, the server creates a quote and returns what the page needs:

async function tokenFor(network, token) {
  const { tokens } = await coinstack("GET", "/tokens");
  return tokens.find((t) => t.network === network && t.token === token);
}

async function sendQuote(res, quote) {
  const meta = await tokenFor(quote.network, quote.token);

  res.json({
    quoteId: quote.quote_id,
    network: quote.network,
    token: quote.token,
    address: quote.address,
    amount: toDisplay(quote.remaining, meta.decimals),
    qr: await QRCode.toDataURL(quote.uri),
    expiresAt: meta.stable ? null : quote.expires_at,
  });
}

app.post("/api/checkouts/:checkoutId/quote", express.json(), async (req, res) => {
  await assertOwnsCheckout(req, req.params.checkoutId); // your own check
  const { network, token } = req.body;

  if (!ACCEPTED.has(`${network}:${token}`)) return res.status(400).json({ error: "Not offered" });

  try {
    const { quote } = await coinstack("POST", `/checkouts/${req.params.checkoutId}/quotes`, { network, token });
    await sendQuote(res, quote);
  } catch (error) {
    res.status(error.status ?? 500).json({ error: error.message });
  }
});

Show 4 things: the network name, the amount from remaining with the token symbol, the address, and the QR code. Give the amount and the address each a copy button, and print the network as plainly as the amount ("Send on TRON only"). A transfer on the wrong network is the mistake a custom page is most likely to cause; what happens when a customer pays on the wrong network explains why.

For a token such as USDC on an Ethereum-style network, the uri is an EIP-681 payment link: ethereum:<token contract>@<chain id>/transfer?address=<deposit address>&uint256=<amount>, so a wallet that scans it fills in the token, recipient and amount. On TRON the uri is the plain address, so the customer enters the amount in their wallet: show the exact amount as text next to the QR code. Encode the uri as the API returns it rather than building your own. Crypto payment QR codes and URIs compares the formats and how wallets handle them.

Each quote has its own deposit address, used by one checkout only. That is what lets a payment be matched to an order without a memo, and the difference shows in completion rates. CoinGate reported on October 8, 2026 that after it stopped using a shared Solana address with a memo on July 21, 2026, completion of orders where SOL was chosen went from 46.0% in June to 77.8% in August.

Asking again for the same token and network returns the quote you already have, so a page reload does not create a new address. A checkout can have up to 10 quotes. The errors you can get, and what to show:

MessageCauseWhat to do
Invalid token or Invalid networkNot available, or turned off in your Payment methodsRemove the option and keep ACCEPTED in sync
Amount below minimumCheckout value is under this token's minimumHide the option (step 2 filters it)
Invalid checkoutThe checkout is not pending or partial, or is past expires_atShow the result, or create a new checkout
Too many quotesThe checkout already has 10 quotesLet the customer pick from the quotes they already opened

How should the countdown and refresh work?

For tokens that are not stablecoins, the quoted amount is based on the price when the quote was made, and expires_at is when that amount stops being held: 20 minutes for most tokens and 60 minutes for BTC. A stablecoin amount has no time limit, which is why sendQuote returns expiresAt: null for them and the page shows no timer.

When the countdown reaches zero, refresh the quote. The amount is recalculated at the current price and expires_at moves forward; the address stays the same. Refreshing before expires_at returns the quote unchanged, so a timer that fires a second early does no harm.

app.post("/api/checkouts/:checkoutId/quotes/:quoteId/refresh", async (req, res) => {
  await assertOwnsCheckout(req, req.params.checkoutId);
  const { checkoutId, quoteId } = req.params;
  const { quote } = await coinstack("POST", `/checkouts/${checkoutId}/quotes/${quoteId}/refresh`);
  await sendQuote(res, quote);
});

In the browser, the same function renders a quote and runs its timer:

const NETWORKS = {
  bitcoin: "Bitcoin", ethereum: "Ethereum", solana: "Solana", base: "Base",
  arbitrum: "Arbitrum", optimism: "Optimism", polygon: "Polygon", avalanche: "Avalanche",
  bnb: "BNB Smart Chain", hyperevm: "HyperEVM", tron: "TRON",
};
const $ = (id) => document.getElementById(id);
let countdown;
let current;

async function post(url, data) {
  const response = await fetch(url, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify(data ?? {}),
  });
  const body = await response.json();
  if (!response.ok) throw new Error(body.error);
  return body;
}

async function choose(checkoutId, option) {
  try {
    show(checkoutId, await post(`/api/checkouts/${checkoutId}/quote`, option));
  } catch (error) {
    $("error").textContent = `This option is not available: ${error.message}`;
  }
}

function show(checkoutId, quote) {
  current = quote;
  $("network").textContent = `Send on ${NETWORKS[quote.network] ?? quote.network} only`;
  $("amount").textContent = `${quote.amount} ${quote.token}`;
  $("address").textContent = quote.address;
  $("qr").src = quote.qr;

  clearInterval(countdown);
  $("timer").textContent = "";
  if (!quote.expiresAt) return; // stablecoins: the amount does not expire

  countdown = setInterval(async () => {
    const left = Math.round((Date.parse(quote.expiresAt) - Date.now()) / 1000);

    if (left > 0) {
      $("timer").textContent = `Amount held for ${Math.floor(left / 60)}:${String(left % 60).padStart(2, "0")}`;
      return;
    }

    clearInterval(countdown);
    show(checkoutId, await post(`/api/checkouts/${checkoutId}/quotes/${quote.quoteId}/refresh`));
  }, 1000);
}

Put the countdown on the amount, not on the order. The checkout itself stays open for 24 hours by default (you can set expires_at from 10 minutes to 365 days when you create it), and a customer who misses the price window only needs a new amount. A payment sent after the quote expired still counts, at the market price when it arrives, which can leave the checkout partly paid. Price locks and crypto volatility explains the mechanics.

Step 4: track the payment and handle partial payments

Your server follows the payment through webhooks, and the page asks your server for the current state. The webhook events map to what the customer sees:

EventWhat to show
payment.pending or checkout.confirmingPayment detected, confirming
checkout.partialPart of the amount arrived; show the new amount still to pay
checkout.completedPaid
checkout.expiredClosed

Get a checkout returns the checkout with every quote and its current remaining, so a status endpoint can serve both the status and the amount still owed:

app.get("/api/checkouts/:checkoutId/status", async (req, res) => {
  await assertOwnsCheckout(req, req.params.checkoutId);
  const { checkout, quotes } = await coinstack("GET", `/checkouts/${req.params.checkoutId}`);
  const quote = quotes.find((q) => q.quote_id === req.query.quote);
  const meta = quote && (await tokenFor(quote.network, quote.token));

  res.json({
    status: checkout.status,
    amount: quote ? toDisplay(quote.remaining, meta.decimals) : null,
  });
});
async function watch(checkoutId) {
  const query = current ? `?quote=${encodeURIComponent(current.quoteId)}` : "";
  const response = await fetch(`/api/checkouts/${checkoutId}/status${query}`);
  const { status, amount } = await response.json();

  if (status === "completed" || status === "resolved") return paid();
  if (status === "expired") return closed();
  if (status === "confirming") $("state").textContent = "Payment detected, confirming";
  if (status === "partial" && current) {
    $("state").textContent = "Part of the payment arrived. Send the rest to the same address.";
    $("amount").textContent = `${amount} ${current.token}`;
  }

  setTimeout(() => watch(checkoutId), 5000);
}

After a partial payment, remaining on every quote drops to what is still owed, and the customer sends the rest to the same address. They can also switch to another token for the rest: a new quote asks only for what is left. A payment that falls short by less than your underpayment allowance (0.5% of the total by default) completes the checkout without a partial step. Underpaid crypto payments covers what to do when a partly paid checkout expires.

Polling your own endpoint every 5 seconds is fine for a few open pages. With many, store the status in your database when a webhook arrives and serve it from there, calling Get a checkout only on page load. Whichever you choose, fulfil the order on the server from a verified checkout.completed event, never because the browser says it is paid. Verifying payment webhooks shows the signature check.

Frequently asked questions

Can the browser call the CoinStack API directly?

No. Every endpoint in this flow needs your API key, and a key in a web page or mobile app can be copied by anyone who opens it. The browser talks to your server, your server talks to CoinStack, and your server checks that the checkout belongs to the customer asking about it before it returns anything.

Why does the quoted amount change when I refresh it?

For tokens that are not stablecoins, the amount is worked out from the token's price when the quote was made, which the quote reports as rate. After expires_at the amount is no longer held, and refreshing recalculates the amount at the current price, so it moves with the market. The address stays the same. Stablecoin amounts are not tied to a time limit.

Does each customer get a new address?

Yes. Each quote has its own deposit address that belongs to one checkout, so two customers never share one, and a payment is matched to its order by the address it was sent to. Requesting the same token and network again for the same checkout returns the existing quote and address.

What happens if the customer sends the payment on the wrong network?

A quote is for one token on one network. A transfer sent on another network still goes through on that network, and if the checkout does not reach completed, the order stays unpaid. Email [email protected] with the transaction hash, the network used and the checkout ID so support can look into it. Printing the network name beside the amount and on the copy button prevents most of these mistakes.

Can I let the customer pay part in one token and the rest in another?

Yes. After a partial payment the checkout is partial and every quote's remaining drops to what is still owed. If the customer creates a quote for a different token or network, it asks only for the rest. A checkout can have up to 10 quotes, which is plenty for this.

More posts