Agent hello world
A "hello world" tour: get authority, point the agent at the skill (or install the SDK), make one paid call, verify the receipt.
This build is Sui testnet.
1. Get authority (once)
You need an owner-funded spend account and a scoped grant that names this agent's public Sui address.
- Open the console (local:
http://localhost:3000). - Sign in with a Sui wallet (personal message). There is no Sui Agent Payments buyer account.
- Create and fund one spend account for the asset you will spend.
- Authorize this agent — MCP consent in the browser, or register the public address the agent already generated.
Neither path puts a delegate secret on the platform. Full owner steps: Authorize an agent (BYO) or Pay with MCP (hosted).
You also need a paid resource URL from discovery:
GET /v1/services
GET /v1/services/{id}Use resourceUrl from the catalog. Do not pay a raw seller upstream.
2. Fastest path — hand the agent the skill
Fetch https://suipay.dev/SKILL.md and follow it.The skill walks discovery, the HTTP 402, paying, and verifying the receipt. A capable agent needs nothing else for the first paid call.
Also useful:
GET /llms.txt
GET /.well-known/mcp.json3. Or install the SDK and pay in-process
pnpm add @cmdoss/suipay-buyerThe owner must already have registered this key's public address (step 1). Load the secret from your own store — never from this page.
// The whole agent path in one file: key, payer, paid call. Included by
// quickstart/agent-buyer.
import { } from '@mysten/sui/keypairs/ed25519'
import { } from '@cmdoss/suipay-buyer'
// In your process this comes from the agent secret store.
const = .(new (32))
const = await ({
: 'https://gateway.example',
,
})
if (!.) throw new (..)
const = await ..(
'https://gateway.example/v1/image/generate',
{
: 'POST',
: .({ : 'A blue ceramic robot' }),
: 'application/json',
: { : '0x...::usdc::USDC', : '50000' },
},
)
export { , , }createPayer discovers the deployment, resolves the grants naming this key,
and then reads the grant object itself with an unsigned getObject — refusing
unless the chain agrees the grant names this delegate. It never asks for the
gateway's HMAC secret.
intent is required. An offer outside it is refused before any ledger
claim, build, or sign.
Full guide: Pay with the SDK. Raw HTTP without the helper: Pay with REST.
4. Or connect remote MCP
- Resolve
GET /.well-known/mcp.json(local:http://localhost:4340/mcp). - Complete OAuth in the browser. The agent presents the public address of the key it already holds.
- Call
access_contextbefore spending. Match a discovered service by service ID, method, and path — not by a similar display name. - Call
paywith the same URL, method, headers, and body you intend to use. The tool mints a fresh challenge, settles, and fetches the resource. - Call
receiptsand confirm challenge, network, amount, asset, payer, and a non-empty Sui digest.
Full guide: Pay with MCP.
5. Inspect the 402, then the receipt
Any unpaid call to the public gateway resource URL must return HTTP 402.
Validate challenge ID, integer atomic amount, asset, recipient, sui:<network>,
expiry, HTTP method, path, body binding when present, and service revision.
Select only a dialect the response actually advertises. Spend-account resources
currently advertise MPP pay-then-prove.
After payment, require a successful receipt (Payment-Receipt for MPP) with
the expected challenge, network, amount, asset, payer, and a non-empty Sui
transaction digest. Verify on Suiscan.
If a timeout, disconnect, or 5xx happens after payment begins, the outcome is ambiguous. Reconcile the challenge, receipt, digest, and chain state before creating another payment.