supra-x402
v0.1.0
Published
Official x402 v2 payment support for the Supra Network: the `exact` scheme (client + server + facilitator), DX helpers, and wallet signers.
Maintainers
Readme
supra-x402
Official x402 v2 payment support for the Supra Network.
Pay any HTTP API with signed, on-chain-settled payments on Supra — gasless or self-paid, from
agents, servers, or wallets. Built on @x402/core v2, so it interoperates with the standard x402
ecosystem.
npm i supra-x402 @x402/core @x402/fetchexactscheme for Supra's Move VM — Ed25519 signatures, BCS transfer authorizations, verified/settled against Supra RPC (no EIP-3009; that's EVM-only).- Coin and Fungible Asset assets; sponsored (gasless) and self-paid gas.
- Off-chain relay — no Move contract to deploy or audit. Replay-protected by sequence number, expiry by transaction timeout.
- DX: server helper for Next.js/Express/Hono middleware, a React hook, and raw-key + wallet signers.
Networks
| CAIP-2 | Network | Chain id |
| --------- | ------- | -------- |
| supra:6 | testnet | 6 |
| supra:8 | mainnet | 8 |
Accept payments (server)
createSupraResourceServer returns a server that plugs into the official framework middleware:
// Next.js middleware.ts
import { paymentMiddleware } from "@x402/next";
import { createSupraResourceServer } from "supra-x402/server";
export const middleware = paymentMiddleware(
{ "/api/report": { price: "0.10", network: "supra:6" } },
createSupraResourceServer({ facilitatorUrl: "https://supra-x402-facilitator.vercel.app" }),
);
export const config = { matcher: ["/api/report"] };@x402/express and @x402/hono work the same way — pass the same server to their paymentMiddleware.
Pay (client / agent)
import { x402Client } from "@x402/core/client";
import { wrapFetchWithPayment } from "@x402/fetch";
import { registerSupraExact, keySignerFromPrivateKey } from "supra-x402/client";
const client = registerSupraExact(new x402Client(), {
network: "supra:6",
signer: keySignerFromPrivateKey(process.env.SUPRA_PRIVATE_KEY!),
});
const res = await wrapFetchWithPayment(fetch, client)("https://api.example.com/api/report");React
"use client";
import { usePayWithX402 } from "supra-x402/react";
const { payJson } = usePayWithX402({ signer, network: "supra:6" });
const data = await payJson("/api/report");Run a facilitator
import { x402Facilitator } from "@x402/core/facilitator";
import { createSupraClient, SupraExactFacilitator, SupraFacilitatorSigner } from "supra-x402";
import { SupraAccount, HexString } from "supra-ts-sdk";
const signer = new SupraFacilitatorSigner({
accounts: [new SupraAccount(HexString.ensure(process.env.FEE_PAYER_KEY!).toUint8Array())],
clients: { "supra:6": createSupraClient("supra:6") },
});
const facilitator = new x402Facilitator().register(["supra:6"], new SupraExactFacilitator(signer));
// expose facilitator.verify / .settle / .getSupported over /verify /settle /supportedExports
| Import | Contents |
| ------ | -------- |
| supra-x402 | scheme classes, signer, createSupraClient, address/transfer/codec helpers, constants |
| supra-x402/client | registerSupraExact, SupraExactClient, key signer |
| supra-x402/server | createSupraResourceServer, createSupraFacilitatorClient, SupraExactServer |
| supra-x402/react | usePayWithX402 |
| supra-x402/wallets | keySignerFromPrivateKey, browserWalletSigner |
Security
The facilitator verifies the payer's Ed25519 signature over the exact Supra signing message and decodes the transfer entry function to confirm recipient, amount, and asset before broadcasting — it can never broadcast anything but the exact transfer the requirement demands. See the threat model.
License
MIT © Entropy Foundation
