@cryptonly/sdk

中文文档
1.9.2发布于 2026/10/30MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 2000

Official Cryptonly SDK.

原始使用文档
文档目录12 节
  1. Install
  2. Quick start
  3. Options
  4. Resources
  5. Create a deposit address
  6. Send a withdrawal
  7. List x402 payments
  8. Idempotency
  9. Verify webhooks
  10. Errors
  11. Contributing
  12. License
Cryptonly

Cryptonly — Merchant API SDK

Official JavaScript/TypeScript SDK for the Cryptonly merchant API.

Website · Documentation · Contact


Install

npm install @cryptonly/sdk

Requires Node.js 18 or later. TypeScript users need TypeScript 4.5 or later.

Quick start

import { Cryptonly } from '@cryptonly/sdk';

const client = new Cryptonly({ apiKey: process.env.CRYPTONLY_API_KEY! });

const invoice = await client.invoice.create({
  amount: 100,
  fiatCurrencyCode: 'USD',
  description: 'Order #123',
  orderId: 'order_123',
});

Options

OptionDefault
apiKeyrequiredYour Cryptonly API key. It selects the account.
sandboxfalseCall the sandbox API instead of production.
baseUrlhttps://api-merchant.cryptonly.netAnother API origin. Takes precedence over sandbox.
timeout60000Request timeout in milliseconds.
fetchglobalThis.fetchA custom fetch, for tests or older runtimes.

Resources

ClientMethodsGuide
client.invoicecreate, list, get, cancelInvoices
client.depositcreate, list, getDeposits
client.withdrawalquote, commit, list, getWithdrawals
client.currencieslist, listFiatSupported currencies
client.x402Settlementslist, getx402 payments

get and cancel take { id } or { orderId }. list methods return { data, total, page, limit, hasMore }. Request and response types are exported from the package.

Create a deposit address

const deposit = await client.deposit.create({
  cryptoCurrencyCode: 'USDT_TRC20',
  orderId: 'deposit_123',
});

console.log(deposit.address, deposit.qrCode);

Send a withdrawal

A withdrawal takes two calls. quote returns the fee and a short-lived quoteId, and commit sends it.

const quote = await client.withdrawal.quote({
  amount: '50',
  cryptoCurrencyCode: 'USDT_TRC20',
  address: 'TJn22ewJPN89yNtrnBkagsunbrLnPyQCgs',
  orderId: 'withdrawal_123',
});

const withdrawal = await client.withdrawal.commit({ quoteId: quote.quoteId });

Pass allowAutoConvert: true to the quote to cover a shortfall by converting another asset on your balance. quote.autoConvert then shows the conversion.

List x402 payments

const { data } = await client.x402Settlements.list({ status: 'confirmed' });

The API key needs the x402.list scope.

Idempotency

orderId makes invoice.create, deposit.create and withdrawal.quote safe to retry. A retry with the same orderId returns the original instead of creating a duplicate. See idempotency.

Verify webhooks

Cryptonly signs each webhook with your account's signing key. Pass the raw request body, the x-webhook-signature header and the key to the verifier for the event:

import express from 'express';
import { verifyInvoiceWebhook } from '@cryptonly/sdk';

app.post('/webhooks/cryptonly', express.raw({ type: 'application/json' }), (req, res) => {
  const result = verifyInvoiceWebhook(
    req.body, // the raw Buffer, not parsed JSON
    req.header('x-webhook-signature'),
    process.env.CRYPTONLY_WEBHOOK_SECRET!,
  );
  if (!result.ok) return res.sendStatus(401);

  console.log(result.envelope.data.status);
  res.sendStatus(200);
});
EventVerifier
invoice.statusChangedverifyInvoiceWebhook
deposit.statusChangedverifyDepositWebhook
withdrawal.statusChangedverifyWithdrawalWebhook

On failure, result.reason is missing_signature, invalid_signature, invalid_json or wrong_event. Get the signing key in the dashboard under Security. See webhooks for payloads and retries.

Errors

Every failed request throws a CryptonlyApiError:

Field
statusHTTP status, or 0 for network errors and timeouts.
codeStable error code, such as exceptions.withdrawal.insufficientBalance. Branch on this.
messageHuman-readable message.
extensionExtra data, such as { msBeforeNext } on rate limits.
requestIdInclude it when you contact support.
path, bodyThe request path and the parsed response body.
import { CryptonlyApiError, CRYPTONLY_EXCEPTION_WITHDRAWAL_INSUFFICIENT_BALANCE } from '@cryptonly/sdk';

try {
  await client.withdrawal.commit({ quoteId });
} catch (error) {
  if (error instanceof CryptonlyApiError && error.code === CRYPTONLY_EXCEPTION_WITHDRAWAL_INSUFFICIENT_BALANCE) {
    // top up, then retry
  }
  throw error;
}

Error codes are exported as CRYPTONLY_EXCEPTION_* constants.

Contributing

Bug reports and pull requests are welcome on GitHub. For larger changes, open an issue first. See CONTRIBUTING.md and, for vulnerabilities, SECURITY.md.

License

MIT

版本与发布记录

@cryptonly/sdk 共发布 30 个版本,首次发布于 2026/04/25;过去 12 个月发布了 30 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.9.2latest2026/10/3015 天前
1.9.12026/10/2421 天前
1.9.02026/10/2322 天前
1.8.12026/10/2025 天前
1.8.02026/10/1827 天前
1.7.02026/10/1728 天前

关于 @cryptonly/sdk 的常见问题

@cryptonly/sdk 是什么?

Official Cryptonly SDK.

如何安装 @cryptonly/sdk?

在项目目录运行 npm install @cryptonly/sdk,或使用 pnpm add / yarn add / bun add。

@cryptonly/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cryptonly/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cryptonly/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cryptonly/sdk 可以商用吗?

@cryptonly/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cryptonly/sdk 的下载量有多少?

根据 npm 官方下载统计,@cryptonly/sdk 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,000 次,日均约 67 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cryptonly/sdk 还在维护吗?

最新版本 1.9.2 发布于 2026/10/30(15 天前);至今共发布 30 个版本,其中过去 12 个月发布了 30 个;首次发布于 2026/04/25。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。