# crypt.pe Node.js SDK

> **crypt.pe** — the non-custodial crypto payment gateway with **0% transaction fees**. Payments settle wallet-to-wallet on-chain, directly to a wallet you control. The hosted alternative to running BTCPay Server. Accept BTC, ETH, SOL, USDT, USDC and 24 coins across 13 chains with a Stripe-style API.

- Website: https://crypt.pe · Docs: https://crypt.pe/docs · Plain-text spec: https://crypt.pe/docs.md
- Free API key (no KYC): https://crypt.pe/signup

## Install

Single file, zero dependencies (Node 18+ preferred; falls back to `https` on Node 16):

```bash
curl https://crypt.pe/api/sdk/node -o cryptpe.js
```

## Quick start — accept a crypto payment

```js
const Cryptpe = require("./cryptpe");
const cryptpe = new Cryptpe(process.env.CRYPTPE_SECRET_KEY); // sk_live_...

// 1. Create an order and redirect the customer to checkout
const order = await cryptpe.payments.create({
  amount_usd: 25.0,
  accepted_coins: ["btc", "usdt-trc20"], // optional — defaults to all wallets on your account
  return_url: "https://your-site.com/thanks",
  webhook_url: "https://your-site.com/hooks/cryptpe",
  metadata: { order_ref: "1234" },
});
console.log(order.checkout_url); // send the payer here

// 2. Verify signed webhooks (HMAC-SHA256, X-Cryptpe-Signature: t=..,v1=..)
app.post("/hooks/cryptpe", express.raw({ type: "*/*" }), (req, res) => {
  try {
    const event = cryptpe.webhooks.verify(
      req.body, // raw Buffer — do NOT JSON.parse first
      req.headers["x-cryptpe-signature"],
      process.env.CRYPTPE_WEBHOOK_SECRET, // whsec_..., shown once at key creation
    );
    if (event.type === "payment.confirmed") fulfill(event.data.order_id);
    res.status(200).end();
  } catch (e) {
    res.status(400).send(`signature: ${e.message}`);
  }
});
```

## Why non-custodial?

| | crypt.pe | custodial gateways (BitPay, Coinbase Commerce) |
|---|---|---|
| transaction fee | **0%** (flat plans, free tier) | 1–2% per sale |
| who holds funds | **you** — wallet-to-wallet | the platform, until payout |
| account freezes | structurally impossible | possible |
| settlement | instant on-chain | batch / withdrawal |

## API surface

SDK methods: `payments.create(params, { idempotencyKey })` · `payments.retrieve(orderId)` · `webhooks.verify(rawBody, sigHeader, secret)` (throws `CryptpeError` on tampering/replay, returns the parsed event).

Additional REST endpoints (call directly, same `Authorization: Bearer sk_live_...` header):

```
POST /api/v1/payments/{id}/verify-tx   # rescue: bind a payment by tx hash
POST /api/v1/payments/{id}/test-pay    # sandbox: simulate full lifecycle
POST /api/v1/payments/{id}/refund      # record an on-chain refund you sent
POST /api/v1/payments/{id}/cancel      # cancel a pending checkout
```

Full spec: https://crypt.pe/docs.md

Keywords: crypto payment gateway API, non-custodial payments, accept bitcoin node.js, USDT payment API, 0% fee crypto checkout, BTCPay Server alternative, Stripe crypto alternative.
