# Rust SDK

> Gate any HTTP route for stablecoin payments with solana-pay-kit — one config, a dual-protocol axum gate that advertises both MPP and x402.

`solana-pay-kit` is stablecoin payment gating for HTTP services in Rust. Pick a currency, give it your wallet address, and gate an [axum](https://github.com/tokio-rs/axum) route — an unpaid request gets a `402 Payment Required` carrying **both** the MPP and x402 challenges, and the client pays with whichever protocol it supports. You do not need to know anything about Solana to use it.

## Install

```toml
[dependencies]
solana-pay-kit = { version = "0.1", features = ["axum"] }
axum = "0.8"
tokio = { version = "1", features = ["full"] }
```

The `axum` feature pulls in the `paid_get` / `paid_post` gate and implies server-side verification for both protocols. For a single protocol, use `default-features = false` with `features = ["mpp"]` (or `["x402"]`).

## Quick start

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

<Tab value="Server">

<Steps>

<Step>

### Create the gate

`PayKit::new` takes a `PayKitConfig`: the recipient wallet, the network, and an RPC URL. Beyond that it is zero-config — a published demo recipient and the hosted Surfpool sandbox let you run it immediately.

```rust
use axum::Router;
use solana_pay_kit::{paid_get, PayKit, PayKitConfig, Payment};

// The verified payment lands in the handler.
async fn quote(payment: Payment) -> String {
    format!("quote — paid {} via {}", payment.amount, payment.protocol)
}
```

<Snippet lang="rust" name="charge.server" path="/quote" />

</Step>

<Step>

### Gate your routes

`paid_get(handler, price, &pay)` (and `paid_post`) returns an axum `MethodRouter`. If no valid payment was sent it halts with a 402 carrying both challenges; when one was, it verifies and settles it, sets the settlement header, and runs your handler. The verified `Payment` is available as a handler extractor.

</Step>

<Step>

### Run it

```bash
cargo run --features axum
```

</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://127.0.0.1:4567/quote
```

</Step>

</Steps>

</Tab>

<Tab value="Client">

Rust also ships the paying side, via the protocol-layer crate re-exported at `solana_pay_kit::mpp`. Read the 402 challenge, sign a credential, and replay the request with it:

```rust
use solana_pay_kit::mpp::client::{build_credential_header, parse_challenge};
use solana_pay_kit::mpp::solana_keychain::memory::MemorySigner;
use solana_pay_kit::mpp::solana_rpc_client::rpc_client::RpcClient;
```

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

See [Client](/docs/sdk/rust/client) for the auto-pay guardrails (spending cap, network pin).

</Tab>

<Tab value="CLI">

No Rust 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/rust/schemes) — fixed charge, metered usage (`upto`), and batch-settlement.
- [Pricing](/docs/sdk/rust/pricing) — fixed and per-request prices.
- [Client](/docs/sdk/rust/client) — the paying side.
- [Signers](/docs/sdk/rust/signers) — local keys and fee sponsorship.
- [Errors](/docs/sdk/rust/errors) — error types and the boot-time safety rails.
