Examples
Examples use Arc testnet values (free faucet USDC). For production, swap in the mainnet column — see Networks.
Common ways creators can use Nibgate for paid content and agent-readable resources.
A good Nibgate example should always show three things: the protected resource, the public metadata sent to the hub, and the receipt emitted after unlock.
Paid article
Protect a premium article route, report article metadata, and stream unlock receipts into earnings.
import { createGate } from "@nibgate/sdk"
const launchNote = createGate({
id: "article_launch_note",
type: "article",
title: "Launch note for paid subscribers",
path: "/launch-note",
url: "https://creator.com/launch-note",
price: "1.50",
currency: "USDC",
access: {
humans: "paid",
agents: "paid"
},
unlock: {
mode: "one_time"
}
})
launchNote.content()
launchNote.view()Music drop
Publish public metadata for a track, gate the full audio, and show unlock/conversion analytics in the dashboard.
import { createGate } from "@nibgate/sdk"
import { createNibgateServer } from "@nibgate/sdk/server"
const track = createGate({
id: "track_drop_01",
type: "music",
title: "Midnight Session — Exclusives",
path: "/music/midnight-session",
url: "https://creator.com/music/midnight-session",
price: "0.10",
currency: "USDC",
access: { humans: "paid", agents: "paid" },
unlock: { mode: "one_time" }
})
track.content()
const server = createNibgateServer({
secret: process.env.NIBGATE_SECRET,
recipient: process.env.NIBGATE_SELLER_ADDRESS,
paymentMode: "circle-gateway",
network: "eip155:5042002"
})
export const GET = server.protect({
id: "track_drop_01", title: "Midnight Session", type: "music", price: "0.10", path: "/music/midnight-session"
}, () => streamAudioFileFromR2()) // handler runs only with allowed access
// Checkout route: verify payment and return the unlock proof.
export const POST = (request: Request) => server.accessResponse(request, track.resource)The protected GET checks an existing proof; it does not settle a payment itself. Complete checkout through the POST access route, then send the returned proof on the media request. Encryption/decryption in streamAudioFileFromR2 is application-owned. Hosted Subblogs use a proof-gated media proxy (/api/nibgate/media/:id/audio) — see Content encryption.
Video course
Index the public course page, then gate individual lessons, downloads, or bonus clips behind unlocks. Hosted Subblogs encrypt uploaded video at rest and serve it through a protected media proxy. A generic SDK integration must implement that storage and streaming layer itself.
import { createGate } from "@nibgate/sdk"
const lesson = createGate({
id: "course_lesson_02",
type: "video",
title: "Lesson 2 — Design tokens",
path: "/course/lesson-2",
url: "https://creator.com/course/lesson-2",
price: "0.50",
currency: "USDC",
access: { humans: "paid", agents: "blocked" },
unlock: { mode: "one_time" }
})
lesson.content()
lesson.view()
// Server route mirrors the access rule; an uploaded .mp4 streams from
// /api/nibgate/media/:id/video only after the x-nibgate-payment-proof header verifies.Agent route
Expose a paid API or data route that humans and AI agents can discover through verified metadata. Agents pay with an x402 wallet client — no browser needed.
import { createNibgateServer } from "@nibgate/sdk/server"
const server = createNibgateServer({
secret: process.env.NIBGATE_SECRET,
recipient: process.env.NIBGATE_SELLER_ADDRESS,
paymentMode: "circle-gateway",
network: "eip155:5042002"
})
const dataset = {
id: "dataset_market_scraper",
title: "Market scraper dataset",
type: "document",
price: "0.25",
path: "/api/datasets/market",
access: { humans: "paid", agents: "paid" }
}
export const GET = (request: Request) => server.accessResponse(
request, dataset, () => Response.json(buildDataset())
)On the payment retry, accessResponse returns an unlock proof. Replay that proof in x-nibgate-payment-proof on the GET to receive the dataset. Unlike accessResponse, protect only checks an existing token or free access and otherwise returns a challenge; it does not settle payments.
An agent pays via GatewayClient (see x402 gateway receipt) then replays the returned unlock proof to retrieve the JSON body.
Example checklist
Register the site
The origin must be verified before public discovery events are trusted.
Publish content metadata
Send a stable id, content type, public URL/path, price, tags, and human/agent access policy.
Gate the resource
The creator app should protect the actual paid file, post, route, or API.
Emit unlock receipt
After payment completes, send the receipt reference so earnings analytics can link back to proof.