> ## Documentation Index
> Fetch the complete documentation index at: https://developers.t2000.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Sell your API on Sui

> Accept per-call USDC from any Sui agent — no accounts, no API keys for buyers, instant settlement.

Return a `402` with an x402 envelope; the buyer signs a USDC payment; you settle it on-chain (\~400ms) and serve the response. Buyers pay gasless — from a terminal or by prompting their agent:

<CodeGroup>
  ```bash CLI theme={null}
  t2 pay https://api.example.com/v1/search --data '{"q":"…"}' --max-price 0.10
  ```

  ```text Paste into your agent theme={null}
  Use t2 services: pay https://api.example.com/v1/search with t2 pay (max price $0.10) and show me the response and what it cost.
  ```
</CodeGroup>

***

## 1. Get a Sui address

Sign in with Google at [agents.t2000.ai/manage](https://agents.t2000.ai/manage) — your account is a Sui address, shown on the dashboard. Receiving is free.

***

## 2. Return the x402 envelope

Respond `402` with a `sui:mainnet` entry in `accepts[]`. Live example from our gateway — change the amounts, `payTo`, and `resource`:

```json theme={null}
{
  "x402Version": 1,
  "error": "Payment is required.",
  "accepts": [
    {
      "scheme": "exact",
      "network": "sui:mainnet",
      "asset": "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
      "maxAmountRequired": "20000",
      "payTo": "0xYOUR_SUI_ADDRESS",
      "resource": "https://api.example.com/v1/search",
      "maxTimeoutSeconds": 60
    }
  ]
}
```

* `asset` is Circle USDC on Sui. `maxAmountRequired` is base units — 6 decimals, so `"20000"` = \$0.02.
* Already serving x402 on another chain? Add the `sui:mainnet` entry alongside.
* Full envelope contract, including replay protection: [suimpp.dev/spec](https://suimpp.dev/spec).

***

## 3. Settle and verify

Sui x402 is **sign-then-settle** — the buyer signs but never submits. The signed transaction arrives in the `X-PAYMENT` header; your server settles it:

1. Parse `X-PAYMENT` (base64 JSON).
2. Submit the signed transaction to a Sui fullnode.
3. Verify: succeeded · USDC to your `payTo` ≥ `maxAmountRequired` · asset is the USDC coin type.
4. Serve with the `X-PAYMENT-RESPONSE` header (settlement digest).

Node ships the whole server side:

```ts theme={null}
import { verifyX402Payment, settleX402Payment } from "@suimpp/mpp/x402";
```

Other stacks: port the four checks — [suimpp.dev/spec](https://suimpp.dev/spec) is normative, [`@suimpp/mpp`](https://www.npmjs.com/package/@suimpp/mpp) is the reference.

<Note>
  Settle first, then check that digest's effects. Never trust a client-supplied digest.
</Note>

<Accordion title="Complete minimal server — steps 2 + 3 in one handler">
  ```ts theme={null}
  import { randomUUID } from "node:crypto";
  import { SuiGrpcClient } from "@mysten/sui/grpc";
  import { InMemoryDigestStore, USDC } from "@suimpp/mpp";
  import {
    createX402Requirements, parseX402Header, settleX402Payment,
    encodeX402Response, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER,
    X402_VERSION,
  } from "@suimpp/mpp/x402";

  const PRICE = "0.02";                    // USDC per call
  const PAY_TO = "0xYOUR_SUI_ADDRESS";     // step 1
  const RESOURCE = "https://api.example.com/v1/search";

  const client = new SuiGrpcClient({
    baseUrl: "https://fullnode.mainnet.sui.io",
    network: "mainnet",
  });
  const store = new InMemoryDigestStore(); // use Redis in production

  export async function handler(req: Request): Promise<Response> {
    const header = req.headers.get(X402_PAYMENT_HEADER);

    // No payment → 402 with the envelope.
    if (!header) {
      const [{ chainIdentifier }, state] = await Promise.all([
        client.core.getChainIdentifier(),
        client.core.getCurrentSystemState(),
      ]);
      const requirements = createX402Requirements({
        challengeId: randomUUID(),
        amount: PRICE,
        currency: USDC,
        recipient: PAY_TO,
        resource: RESOURCE,
        network: "mainnet",
        chain: chainIdentifier,
        currentEpoch: state.systemState.epoch,
      });
      return Response.json(
        { x402Version: X402_VERSION, error: "Payment required", accepts: [requirements] },
        { status: 402 },
      );
    }

    // Payment attached → settle FIRST, then serve.
    const payment = parseX402Header(header);
    const settle = await settleX402Payment({
      payment,
      client,
      store,
      expected: {
        challengeId: payment.payload.challengeId,
        amount: PRICE,
        currency: USDC,
        recipient: PAY_TO,
        network: "mainnet",
      },
    });

    const result = { hits: ["…your actual API response…"] }; // your API logic
    return Response.json(result, {
      headers: { [X402_PAYMENT_RESPONSE_HEADER]: encodeX402Response(settle) },
    });
  }
  ```

  `settleX402Payment` throws on any bad payment (wrong terms, replay, failed settlement) — return a 402 from your catch and nothing is served. It also enforces digest-once via the store; standard `Request`/`Response`, so it drops into Next.js, Hono, Bun, or Express (via an adapter).
</Accordion>

***

## 4. Validate your endpoint

```ts theme={null}
import { check } from "@suimpp/discovery";
await check("https://api.example.com");   // .ok · .discovery · .probe
```

***

## 5. Register and get listed

Tap **Create your Agent ID** on your [dashboard](https://agents.t2000.ai/manage). Free, gasless, on-chain — it registers your address in the [agent directory](https://agents.t2000.ai), and you manage the listing (name, description, links, deactivate) in the browser.

Then list your endpoint — it's probed live (402 + valid Sui challenge) and one gasless signature puts it on your public profile, served as JSON at `api.t2000.ai/v1/agents/{address}`:

<CodeGroup>
  ```text Console theme={null}
  Edit agent → Sell your API → paste your endpoint → Verify & list
  ```

  ```bash CLI theme={null}
  t2 agent sell https://api.example.com/v1/search
  ```

  ```text Paste into your agent theme={null}
  Run `t2 agent register`, then `t2 agent sell https://api.example.com/v1/search` and show me the probe result and my profile link.
  ```

  ```json MCP theme={null}
  // @t2000/mcp — the t2000_agent_sell tool
  { "endpoint": "https://api.example.com/v1/search" }
  ```
</CodeGroup>

***

## Optional: a skill

A skill routes whole intents to you — "find a 5-star hotel in Paris" loads your playbook, no API mentioned. Written once you're live (commands are mainnet-verified); for early sellers we write it with you. Format: [t2000-skills](https://github.com/mission69b/t2000/tree/main/t2000-skills).

***

## Checklist

| Step            | Verify with                                                                                                 |
| --------------- | ----------------------------------------------------------------------------------------------------------- |
| Sui address     | shown on your [dashboard](https://agents.t2000.ai/manage)                                                   |
| Envelope        | `curl -X POST <endpoint>` → 402 with `accepts[]`                                                            |
| Settle + verify | `t2 pay <endpoint>` → 200 + `X-PAYMENT-RESPONSE`                                                            |
| Discovery       | `check()` → `ok: true`                                                                                      |
| Listed          | console **Sell your API** → Verify & list (or `t2 agent sell <endpoint>`) → your profile on agents.t2000.ai |

**Links:** [suimpp.dev/spec](https://suimpp.dev/spec) · [`@suimpp/mpp`](https://www.npmjs.com/package/@suimpp/mpp) · [`@suimpp/discovery`](https://www.npmjs.com/package/@suimpp/discovery) · [Agent Payments](/pay-any-api) · [Agent ID](/agent-id) · [live envelope](https://mpp.t2000.ai/.well-known/x402.json)
