# Accept crypto payments in Node.js (paygate-to)

> A tested Node.js and Express example: create a payment address with amount and QR code, or a hosted checkout, then verify the signed callback with paygate-to.

Source: https://withoutkyc.to/knowledge-base/developers/accept-crypto-nodejs/
Updated: 2026-11-15

The official **paygate-to** package for Node.js 18+ (ESM, CommonJS and TypeScript types included) covers the whole crypto flow: payment addresses, conversion, QR codes, hosted checkout and callback verification. Full reference: [Node.js SDK docs](https://withoutkyc.to/docs/sdk/node/).

## Install

```bash
npm install paygate-to
```

## Option A: payment address and QR code on your page

```js
import { PayGate, CallbackToken } from 'paygate-to';

const paygate = new PayGate();
const tokens = new CallbackToken(process.env.PAYGATE_CALLBACK_SECRET);   // 64 random hex chars

const callback = tokens.callbackUrl('https://shop.example8585859.com/paygate/callback', { order: '1001' });

const wallet = await paygate.crypto.createWallet('polygon_usdc', '0xYourEvmWallet', callback);
const quote = await paygate.crypto.convert('polygon_usdc', '49.90', 'USD');
const qr = await paygate.crypto.qrCode('polygon_usdc', wallet.addressIn, quote.value);

// Render wallet.addressIn, quote.value and qr.dataUri on your checkout page (escape them)
```

## Option B: hosted multi-coin checkout

```js
const hosted = await paygate.crypto.createHostedWallet({
  evm: '0xYourEvmWallet',
  btc: 'bc1qYourBitcoinWallet',
  solana: 'YourSolanaWallet',
  xrp: 'rYourXrpAddress?dt=777',
}, '49.90', 'USD', callback);

res.redirect(paygate.crypto.hostedPaymentUrl(hosted, { addFees: true }));
```

## The callback route (Express)

```js
import express from 'express';
import { PayGate, CallbackToken, CallbackData } from 'paygate-to';

const app = express();
const paygate = new PayGate();
const tokens = new CallbackToken(process.env.PAYGATE_CALLBACK_SECRET);
const CALLBACK_URL = 'https://shop.example8585859.com/paygate/callback';   // as registered

app.get('/paygate/callback', async (req, res) => {
  const result = await paygate.callbacks.verifyRequest(CALLBACK_URL, req);
  if (!result.valid) return res.sendStatus(403);              // result.reason, e.g. signature_mismatch

  const data = CallbackData.fromRequest(req);
  if (!tokens.verify(data.get('order'), data.get('token'))) return res.sendStatus(403);
  if (data.pending) return res.send('ok');                    // seen, not confirmed: don't ship

  const order = await findOrder(data.get('order'));
  if (await order.hasTransaction(data.txidIn)) return res.send('ok');   // credit once
  await order.addPayment(data.txidIn, data.coin, data.valueCoin);

  const toMe = data.payoutFor('0xYourEvmWallet');            // undefined if nothing reached your wallet
  const paid = toMe !== undefined && order.receivedTotal() >= 0.98 * Number(order.expectedCoin);
  await order.setStatus(paid ? 'paid' : 'underpaid');
  res.send('ok');
});
```

`verifyRequest()` reads the raw query from `req.originalUrl` and never rebuilds it. With another framework, call `paygate.callbacks.verify(CALLBACK_URL, rawQueryString, signatureHeader, keyIdHeader)`. Never rebuild the query from `req.query` or `URLSearchParams`.

## XRP helpers

```js
import { xrpPayoutForm, decodeXrpXAddress } from 'paygate-to';

xrpPayoutForm('X7qvLs7gSnNoKvZzNWUT2e8st17QPY84SkdtoNKGbhoPHEW');
// 'rf1BiGeXwwQoi8Z2ueFYTEXSwuJYfV2Jpn?dt=777'
```

See [XRP payment API](https://withoutkyc.to/knowledge-base/developers/xrp-payment-api/) for destination tags and X-addresses.

We tested these examples with the published `paygate-to@1.2.0` package: wallet, conversion, QR code and hosted checkout against the live API, and the callback route with signed, repeated, unsigned and tampered requests.

> **No API key, no account: install, create a wallet, verify callbacks. All endpoints: [crypto API reference](https://withoutkyc.to/docs/crypto-payment-api/).**

## Frequently asked questions

### Does it work in serverless functions?

Yes, as long as the raw query string reaches `verify()` unchanged. Some platforms expose the original URL under a different property; take the part after `?` from it and pass it as received.

### Which Node.js versions are supported?

Node.js 18 or newer.

### How do I store amounts safely?

Keep amounts as strings or decimals, not floating-point numbers, when you store them; compare with a small tolerance.
