# Go SDK

> Gate any HTTP route for stablecoin payments with the pay-kit Go module — one paykit umbrella, net/http middleware that advertises both MPP and x402.

The pay-kit Go module (`github.com/solana-foundation/pay-kit/go`) is stablecoin payment gating for HTTP services. Pick a currency, give it your wallet address, and gate a `net/http` route — an unpaid request gets a `402 Payment Required` advertising **both** x402 and MPP, and the client settles with either. You do not need to know anything about Solana to use it.

## Install

```bash
go get github.com/solana-foundation/pay-kit/go
```

The `paykit` umbrella is the surface; blank-importing the two protocol adapters (and a signer) registers them, so one gate advertises both protocols at once.

## Quick start

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

<Tab value="Server">

<Steps>

<Step>

### Create the client

`paykit.New` takes a `Config`: the network, the protocols you `Accept`, and an MPP realm + challenge-binding secret. With no `Operator.Signer` it boots on the in-memory demo signer and the Surfpool sandbox — enough to run locally.

```go
import (
    "fmt"
    "net/http"

    "github.com/solana-foundation/pay-kit/go/paykit"
    _ "github.com/solana-foundation/pay-kit/go/paycore/signer"
    _ "github.com/solana-foundation/pay-kit/go/paykit/adapters/mpp"
    _ "github.com/solana-foundation/pay-kit/go/paykit/adapters/x402"
)
```

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

</Step>

<Step>

### Gate your routes

`client.Require(gate)` is a plain `func(http.Handler) http.Handler`, so it composes with chi, gorilla, or the stdlib mux. It settles the 402 before your handler runs; inside the handler, `paykit.PaymentFrom(r.Context())` returns the verified payment.

</Step>

<Step>

### Run it

```bash
go run .
```

</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">

Go also ships the **paying side**. `x402client.NewClient` returns an `*http.Client` whose transport settles a 402 in one retry, then replays the request with the credential — so any `*http.Client` call pays transparently:

```go
import x402client "github.com/solana-foundation/pay-kit/go/protocols/x402/client"
```

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

The sibling `protocols/mpp/client` does the same for MPP. See [Client](/docs/sdk/go/client).

</Tab>

<Tab value="CLI">

No Go 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/go/schemes) — fixed charge and metered usage (`upto`).
- [Pricing](/docs/sdk/go/pricing) — amounts, settlement assets, fees, and splits.
- [Client](/docs/sdk/go/client) — the paying side.
- [Signers](/docs/sdk/go/signers) — local keys and fee sponsorship.
- [Errors](/docs/sdk/go/errors) — the error values and the boot-time safety rails.
