@crossmint/rest-js

中文文档
0.2.0发布于 2026/10/09Apache-2.0TypeScriptESM + CJS零依赖近 30 天下载 2073

Crossmint REST SDK for JavaScript and TypeScript

原始使用文档
文档目录6 节
  1. Install
  2. Create a client
  3. Requests and responses
  4. Streaming
  5. React Query
  6. Compatibility

Crossmint REST SDK for JavaScript and TypeScript

A typed client for the Crossmint REST API. Supports Node.js 18+ and browsers with native Fetch, with ESM and CommonJS exports and no runtime dependencies.

Install

npm install @crossmint/rest-js

Create a client

import { createCrossmintSdk } from "@crossmint/rest-js";

const crossmint = createCrossmintSdk({
    environment: "staging",
    apiKey: process.env.CROSSMINT_API_KEY,
});

const { data: wallet } = await crossmint.wallets.create({
    body: { chainType: "evm", type: "mpc" },
    throwOnError: true,
});

The default environment is staging. Set environment: "production" to use the production API. The client routes each operation to its API host automatically, including Vault operations. Endpoints available only in staging reject requests in production.

To call through your own backend proxy or a local API, set baseUrl to an absolute URL. It replaces the API host and its /api path for every operation except Vault operations:

const crossmint = createCrossmintSdk({ baseUrl: "https://your-app.example/api/crossmint" });

Vault operations (payment method creation) send raw card and bank details, and only the Vault host tokenizes them. They stay on the Vault host when you set baseUrl. To move them too, set vaultBaseUrl. A server that receives these requests receives the raw card data, so it comes into your PCI DSS scope.

Keep server API keys on your server. In browsers, use a client API key with the appropriate scopes and supply userJwt when the endpoint requires user authentication. For order endpoints that accept an order client secret, use clientSecret. Each request uses a complete authentication alternative declared by the API; explicitly supplied request headers take precedence.

Requests and responses

Methods are grouped by resource, such as crossmint.wallets.create(...) and crossmint.orders.get(...). Request options keep body, path, query, and headers separate. Pass an AbortSignal through signal to cancel a request, or provide a custom Fetch implementation when creating the client.

const { data, error, response } = await crossmint.orders.get({
    path: { orderId: "your-order-id" },
});

if (error !== undefined) {
    console.error(response?.status, error);
} else {
    console.log(data);
}

HTTP failures return error by default. With throwOnError: true, the client throws the error instead. Network failures also return error unless throwOnError is enabled. Returned errors are not necessarily JavaScript Error instances.

Some APIs expose multiple versions explicitly, for example crossmint.paymentMethods.v20260916.create(...) and crossmint.paymentMethods.unstable.create(...). Use the version documented for your integration; unstable APIs may change.

Streaming

Streaming methods return an async iterator:

const abortController = new AbortController();
const { stream } = await crossmint.agentCheckouts.messages.stream({
    path: { id: "your-checkout-id" },
    signal: abortController.signal,
});

for await (const event of stream) {
    console.log(event);
}

React Query

Use SDK methods in query functions and mutations. Include the environment and project or user identity in your cache scope, so requests from different clients do not share cached results. Never put API keys or tokens in query keys.

import { useQuery } from "@tanstack/react-query";

const walletQuery = useQuery({
    queryKey: ["crossmint", cacheScope, "wallet", walletLocator],
    queryFn: async ({ signal }) => {
        const { data } = await crossmint.wallets.get({
            path: { walletLocator },
            signal,
            throwOnError: true,
        });
        return data;
    },
});

React Query is installed separately. The SDK does not depend on React.

Compatibility

The SDK is generated from Crossmint's public OpenAPI specification. Its endpoint coverage and request and response types follow that specification. TypeScript types do not perform runtime response validation.

The package supports bundlers that consume ESM and sideEffects: false. Completely unused imports can be removed; creating a resource client currently includes the full operation registry. Per-resource bundle splitting is not provided. React Native and other Fetch-compatible runtimes have not been validated.

See the API reference for endpoint behavior, permissions, and API limits.

Licensed under Apache 2.0. See THIRD_PARTY_NOTICES for the bundled Hey API transport's MIT license.

版本与发布记录

@crossmint/rest-js 共发布 2 个版本,首次发布于 2026/10/07;过去 12 个月发布了 2 个版本。

版本发布日期距今
0.2.0latest2026/10/091 个月前
0.1.02026/10/071 个月前

关于 @crossmint/rest-js 的常见问题

@crossmint/rest-js 是什么?

Crossmint REST SDK for JavaScript and TypeScript

如何安装 @crossmint/rest-js?

在项目目录运行 npm install @crossmint/rest-js,或使用 pnpm add / yarn add / bun add。

@crossmint/rest-js 支持 TypeScript 吗?

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

@crossmint/rest-js 支持 ESM 还是 CommonJS?

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

@crossmint/rest-js 需要什么版本的 Node.js?

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

@crossmint/rest-js 可以商用吗?

@crossmint/rest-js 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@crossmint/rest-js 的下载量有多少?

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

@crossmint/rest-js 还在维护吗?

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