# TypeScript SDK

> Gate any HTTP route for stablecoin payments with @solana/pay-kit — one config object, web-standard Request/Response, and Express, Hono, or Fetch handlers.

`@solana/pay-kit` is protocol-agnostic payment gating for HTTP services on Solana. Pick a currency, give it your wallet address, and gate a route — the SDK runs the `402 Payment Required` handshake (over MPP or x402), verifies the on-chain payment, and settles it. You do not need to know anything about Solana to use it.

The whole server is one `createPayKit` call plus your handlers. The runtime is web-standard `Request`/`Response`, so Express, Hono, and plain `node:http` all sit on the same dispatcher.

## Install

<Tabs items={['npm', 'pnpm', 'bun']}>

<Tab value="npm">

```bash
npm install @solana/pay-kit
```

</Tab>

<Tab value="pnpm">

```bash
pnpm add @solana/pay-kit
```

</Tab>

<Tab value="bun">

```bash
bun add @solana/pay-kit
```

</Tab>

</Tabs>

`@solana/pay-kit` declares the protocol layer (`@solana/mpp`), `@solana/kit`, and `mppx` as peer dependencies — npm, pnpm, and bun install them automatically.

## Quick start

<Tabs items={['Server', 'Client', 'CLI']}>

<Tab value="Server">

<Steps>

<Step>

### Create the server

`createPayKit` takes a single config object: the network, your operator wallet, the protocols you `accept`, and an inline `pricing` catalogue. Gate names are inferred from `pricing`, so `pay.express('quote')` autocompletes and a typo is a compile error.

```ts
import express from 'express';
import { createPayKit, usd } from '@solana/pay-kit';
```

<Snippet name="charge.server" path="/api/v1/quote/:symbol" />

</Step>

<Step>

### Gate your routes

`pay.express(gate)` settles the 402 (MPP or x402, the client's choice) before your handler runs. If no valid payment was sent it halts with a 402 challenge; when one was, it verifies and settles it, sets the settlement headers on the response, and hands control to your handler.

The same instance also exposes `pay.hono(gate)` and `pay.fetch(gate, handler)` for other runtimes — see [Schemes](/docs/sdk/typescript/schemes) and [Client](/docs/sdk/typescript/client).

</Step>

<Step>

### Run it

```bash
npx tsx server.ts
```

</Step>

<Step>

### Make a paid call

Hit the route with the [`pay`](/docs/toolchain) CLI — it walks the user through approval and pays in USDC:

```bash
pay curl http://localhost:3000/api/v1/quote/AAPL
```

</Step>

</Steps>

</Tab>

<Tab value="Client">

`@solana/pay-kit/client` ships a payment-aware `fetch`. On a 402 it reads the challenge, pays with the matching protocol, and retries the request with the `Authorization: Payment` credential — transparently.

```ts
import { createPayKitClient } from '@solana/pay-kit/client';
import { createKeyPairSignerFromBytes, getBase58Encoder } from '@solana/kit';
```

<Snippet name="charge.client" url="https://api.example.com/api/v1/quote/AAPL" />

See [Client](/docs/sdk/typescript/client) for forcing a rail and consuming streamed sessions.

</Tab>

<Tab value="CLI">

No code at all — the `pay` CLI is a client for any 402-gated route, handling wallet, signing, and the payment retry for you:

```bash
brew install pay     # or: npm install -g @solana/pay
pay --sandbox curl https://debugger.pay.sh/mpp/quote/AAPL
```

</Tab>

</Tabs>

## Next steps

- [Payment schemes](/docs/sdk/typescript/schemes) — fixed charge, metered usage, subscription, and session.
- [Pricing & gates](/docs/sdk/typescript/pricing-and-gates) — currencies, fees, splits, and dynamic pricing.
- [Client](/docs/sdk/typescript/client) — the paying side.
- [Signers](/docs/sdk/typescript/signers) — local keys and remote signing backends.
- [Errors](/docs/sdk/typescript/errors) — the error types and the boot-time safety rails.
