intents.fi
TypeScript · Node.js · Edge runtimes

A TypeScript crypto payment SDK for invoices and webhooks

A crypto payment SDK for TypeScript: create invoices, verify webhooks and read payments with the SDK. Customers pay in any token; you get USDC, USDT or BTC.

This page explains what the SDK covers, how it behaves on each runtime, and how it compares with calling the API yourself. The full request and response reference lives in the API docs; this page links there rather than repeating it.

npm install @intents-fi/sdk
import { createClient } from "@intents-fi/sdk";

// Server only. The secret key never reaches a browser.
const intents = createClient({ apiKey: process.env.INTENTS_SECRET_KEY! });

const invoice = await intents.checkout.invoices.create({
  amount: "49.00",                 // USD, as a string
  reference: "order_1042",         // your order ID, and the idempotency key
  description: "Pro plan, 1 month",
  successUrl: "https://shop.example/thanks",
  metadata: { customerId: "cus_88" },
});

// Send the customer to the hosted checkout.
return Response.redirect(invoice.url, 303);
Short answerUpdated · Facts checked

A crypto payment SDK is a typed client that wraps a payment API, so your server can create payment requests and check their status without writing raw HTTP. @intents-fi/sdk does that for Intents Checkout: one call creates a USD invoice, one verifies the signed webhook, and USDC, USDT or BTC settles to your own wallet.

Our takeUse the SDK on your server for invoices and webhooks; reach for raw HTTP only on a runtime where you cannot install a package, because the API underneath is the same.

Code

Create an invoice · ts
import { createClient } from "@intents-fi/sdk";

// Server only. The secret key never reaches a browser.
const intents = createClient({ apiKey: process.env.INTENTS_SECRET_KEY! });

const invoice = await intents.checkout.invoices.create({
  amount: "49.00",                 // USD, as a string
  reference: "order_1042",         // your order ID, and the idempotency key
  description: "Pro plan, 1 month",
  successUrl: "https://shop.example/thanks",
  metadata: { customerId: "cus_88" },
});

// Send the customer to the hosted checkout.
return Response.redirect(invoice.url, 303);
Verify the webhook · ts
import { verifyAndParse } from "@intents-fi/sdk";

export async function POST(request: Request) {
  const body = await request.text(); // raw bytes: the signature covers them
  const event = await verifyAndParse(
    body,
    request.headers.get("x-intents-signature"),
    process.env.INTENTS_WEBHOOK_SECRET!,
  );
  if (!event) return new Response("bad signature", { status: 400 });

  // data.status is the truth; duplicates and out-of-order deliveries are normal.
  if (event.data.status === "paid") await fulfil(event.data.reference, event.late === true);
  return new Response(null, { status: 204 });
}
Handle errors · ts
import { IntentsError } from "@intents-fi/sdk";

try {
  await intents.checkout.invoices.cancel(invoiceId);
} catch (e) {
  if (e instanceof IntentsError && e.code === "INVOICE_NOT_OPEN") {
    // Already paid, expired or cancelled: read it instead of retrying.
    const current = await intents.checkout.invoices.get(invoiceId);
    return current.status;
  }
  throw e;
}

What the SDK covers

@intents-fi/sdk is the server-side half of an Intents Checkout integration. It does four jobs, and each maps to a small part of the API.

Job Calls API underneath
Take a payment checkout.invoices.create() POST /v0/invoices
Look a payment up checkout.invoices.get(), .list() GET /v0/invoices/{id}, GET /v0/invoices
Call one off checkout.invoices.cancel() POST /v0/invoices/{id}/cancel
Hear when it is paid webhooks.create(), verifyAndParse() POST /v0/webhooks, plus a local HMAC check

The invoice is priced in USD. The customer chooses what to pay with on the hosted page, and the exact amount of USDC, USDT or native BTC you chose settles to your own address. Intents never holds the money, so there is no balance to withdraw and no payout to wait for. The quickstart walks the same three steps over plain HTTP.

Two more parts ship in the same package. Most merchants never need either:

  • checkout.page.*: the public checkout endpoints, for teams that build their own payment screen. See headless.
  • Quotes, orders and swap(): the client for Intents Route, our cross-chain swap API.

Three rules the SDK enforces for you

Payments code fails in a few predictable places. The SDK is shaped so the safe path is the default one.

  1. One invoice per order. reference is required in practice and is the idempotency key. Send the same one twice and you get the invoice that already exists, with 200, so a timeout followed by a retry can never bill a customer twice.
  2. Signatures over raw bytes. verifyAndParse() takes the body as a string, checks the t=…,v1=… HMAC-SHA256 header, and rejects a delivery older than 300 seconds so a captured request cannot be replayed. It returns null instead of throwing, which keeps the route short.
  3. Integers, not floats. Amounts that come back in the settlement asset, such as amountExpected and amountNet, are integer strings in base units. 48804000 is $48.804 of a six-decimal stablecoin. Do the maths in BigInt.

Runtimes and installation

The package is plain ES modules with no runtime dependencies.

  • Node.js 18 or later. It uses the global fetch.
  • Edge functions. Webhook verification runs on WebCrypto, so the same code works in Vercel and Cloudflare edge runtimes. Because WebCrypto is asynchronous, verify() and verifyAndParse() return promises.
  • Your own fetch. Pass fetch to createClient() to add tracing or retries, or to run under a test interceptor.
  • A proxy. baseUrl defaults to https://api.intents.fi. Point it elsewhere if your infrastructure routes outbound calls through a gateway.

viem and @solana/web3.js are optional peer dependencies used only by the Intents Route swap helpers, which execute steps in a user’s wallet. An Intents Checkout integration installs neither.

SDK, raw HTTP, React or an agent

There are four ways to talk to the same API. They are not exclusive: most integrations use the SDK on the server and either the hosted page or the React package in front of it.

Side by side

Side by side
Compared on@intents-fi/sdkRaw HTTP@intents-fi/reactMCP server
Runs whereYour server or edge functionAnywhere that can send HTTPSThe customer's browserYour AI coding agent
Holds the secret keyYes, server-sideYes, server-sideNo, only a per-invoice clientSecretA test key while you build
Creates invoicesYesYesNo: it renders one your server madeYes, in test mode
Verifies webhooksYes, verifyAndParse() BetterYou write the HMAC checkNoNo
Typed responsesYes, generated from OpenAPI BetterOnly if you write the typesYesn/a
Best forMost server integrationsPHP, Python, Go or a no-install runtimeCheckout inside your own appScaffolding the integration

If your backend is not TypeScript, call the API directly. Every endpoint is described in the OpenAPI reference, and the webhooks page gives the signature scheme in enough detail to write the check in any language. The crypto checkout API page goes through the create request field by field.

Errors you will actually see

Every failed call throws an IntentsError with a stable code, the HTTP status and, where the API sends them, details. These are the ones an Intents Checkout integration meets most:

Code When What to do
INVALID_REQUEST A field failed validation, such as metadata with more than 20 keys Read details.field, fix the call
INVOICE_NOT_OPEN Cancelling an invoice that is paid, expired or already cancelled Read the invoice and act on its status
MERCHANT_RESTRICTED The account is not taking payments right now Check the dashboard, then write to support
LIVE_MODE_LOCKED A live key used before the account is cleared for live payments Keep building on a test key; see the go-live steps
SETTLEMENT_REQUIRED A live invoice with no payout wallet set Add the wallet in the dashboard
RATE_LIMITED Too many requests in a short window Back off and retry
NETWORK_ERROR The API could not be reached Retry with the same reference

The API codes are explained under errors, with a page for each one that needs a fix on your side. NETWORK_ERROR and the wallet codes are raised by the SDK itself. The safe retry rule is simple: retrying a create with the same reference is always safe, because it can only ever return one invoice.

Before you go live

0 of 6 done

Testing with the SDK

Test mode is a property of the key, not of the code. Create the client with an ik_test_ key and everything runs the same way, with one difference: a test invoice has no deposit address. The hosted page shows a Complete the test payment button that walks the invoice to paid and sends the real, signed invoice.paid webhook to your endpoint.

  • Register a test webhook endpoint with webhooks.create(). Endpoints belong to a mode, so live needs its own.
  • Keep the whsec_… secret it returns. It is shown once.
  • To receive webhooks on your laptop, point a tunnel at your route and register the tunnel URL.
  • When the tests pass, swap in an ik_live_ key on the server, register a live endpoint and pay a real $5 invoice from a phone.

The agent setup guide can wire a test-mode integration into an existing app for you, using this SDK. To add crypto beside an existing checkout by hand, add crypto to your existing checkout uses the SDK’s createInvoice and verifyWebhook helpers; PHP shops have the same two calls in intents-php.

Cost

The SDK is free and MIT-licensed. Each settled payment costs 0.4% with no fixed fee and no setup, monthly or payout fee; the customer’s network and routing costs sit inside the amount they are quoted. See pricing, the hosted checkout, and the framework guides for React and Next.js.

Spec sheet

Language
TypeScript, ES modules
Runtime
Node.js 18+, edge runtimes
Runtime dependencies
None
Types
Generated from the OpenAPI document
Licence
MIT
Package
@intents-fi/sdk

Questions

Short answers. The docs go deeper.

What is a crypto payment SDK?

A library that wraps a crypto payment API in typed functions, so your code calls something like invoices.create() instead of building HTTP requests and parsing responses by hand. A good one also verifies webhook signatures, maps errors to stable codes and stays in step with the API it wraps.

Is there a TypeScript SDK for accepting stablecoin payments?

Yes. @intents-fi/sdk is a TypeScript client for Intents Checkout. It creates USD-priced invoices, reads and cancels them, registers webhooks and verifies their signatures. Customers pay in the token they hold and USDC, USDT or native BTC settles to your own wallet.

Does the SDK work on edge runtimes?

Yes. Webhook verification uses WebCrypto rather than Node's crypto module, so the same verifyAndParse() call works in Node.js, Vercel and Cloudflare edge functions. HTTP calls use the global fetch, and you can pass your own fetch if your runtime needs one.

Can I use the SDK in the browser?

Not with your secret key. A browser should only ever hold an invoice's clientSecret. For an in-app checkout use @intents-fi/react, or proxy the API through your own backend and point the SDK's baseUrl at that route.

Do I need the SDK to accept crypto payments?

No. The API is plain HTTPS with JSON, so PHP, Python, Go or a shell script can call it directly. The SDK saves you the request code, the types and the webhook signature check, which is the part most often written wrong.

How does the SDK stay in sync with the API?

Its types are generated from the API's OpenAPI document, which is published at /v0/openapi.json. When the API adds a field or an error code, the SDK is regenerated from that document rather than edited by hand.

Can I test without moving money?

Yes. Create a client with an ik_test_ key and every call runs in test mode: invoices, the hosted page and real signed webhooks, with a Complete the test payment button instead of a deposit. Nothing moves on any chain.

Get paid in your own wallet.

Customers pay in what they hold. You receive USDC or USDT on the chain you choose, or native bitcoin. We never hold your funds.