📚 DOCUMENTATION

Everything you need to know about S402 Scan and the S402 payment protocol

🔍 WHAT IS S402 SCAN?

S402 Scan is a comprehensive ecosystem explorer for the S402 payment protocol on BNB Chain. It provides real-time analytics, transaction monitoring, and a marketplace for AI agents that use micropayments to access external APIs and services.

📊

Dashboard

View overall statistics, transaction volume, and ecosystem activity

💳

Transactions

Browse all S402 payments with detailed information about sender, receiver, and amount

🛒

Marketplace

Discover available data sources and API services with usage statistics

🤖

Composer

Build and interact with AI agents that autonomously use S402 payments

🚀 GETTING STARTED

1

Connect Your Wallet

Click "Connect Wallet" in the top right corner and connect your MetaMask wallet to BNB Chain (Chain ID: 56)

2

Get USD1 Tokens

S402 payments use USD1 stablecoin. You can swap BNB for USD1 using the integrated 1inch widget in the Composer

3

Create a Session (Optional)

For seamless AI agent interactions, create a session wallet that handles payments automatically without requiring signatures for each transaction

4

Build or Use AI Agents

Visit the Composer to create custom AI agents with tool access, or browse existing public agents created by the community

💰 AGENTIC FEE BUYBACKS TO $SORA

The S402 ecosystem features a unique tokenomics model that creates value for $SORA token holders:

📈 Platform Fees

Every S402 payment includes a small platform fee (typically 1-2% of the payment amount). These fees accumulate in the platform treasury as USD1 stablecoin.

🔄 Automatic Buybacks

Platform fees are periodically used to buy $SORA tokens from the open market. This creates consistent buying pressure and supports the token price as the ecosystem grows.

🔥 Value Distribution

Bought-back $SORA tokens may be burned (reducing supply) or redistributed to ecosystem participants, creating long-term value for token holders as AI agent activity increases.

Example: If 1,000 AI agents each make $1 worth of API calls per day, that generates $10-$20 in platform fees daily. Over a year, this could result in $3,650-$7,300 in $SORA buybacks, creating sustained demand for the token.

🌐 OPEN SOURCE & PERMISSIONLESS

S402 is an open source payment protocol that anyone can use, modify, and implement:

No Licensing Fees

Developers can implement S402 in their applications without paying any fees to use the protocol. It's completely free and permissionless.

Flexible Implementation

You can implement S402 however you'd like - use the reference implementation, modify it, or build your own from scratch following the protocol specification.

Optional Platform Fees

Platform fees only apply when using the official S402 Facilitator contract. If you deploy your own payment infrastructure, you can set your own fee structure or charge no fees at all.

Community-Driven

The protocol is designed to be community-driven. Developers can contribute improvements, build extensions, and create new use cases without permission.

💡 For Developers

The S402 protocol enables HTTP 402 (Payment Required) micropayments on BNB Chain using EIP-712 signatures and USD1 stablecoin.

  • Smart contracts are verified and open source on BscScan
  • TypeScript SDK available for easy integration
  • No central authority - fully decentralized payment verification
  • Session wallets enable gasless user experiences

🛠️ TECHNICAL GUIDE: BUILD YOUR OWN S402 SERVER

Anyone can create S402-enabled services that accept micropayments for API access. This guide shows you how to implement the S402 protocol in your own applications.

📋 Protocol Overview

S402 uses EIP-712 typed signatures to authorize USD1 token transfers. Users sign a payment message off-chain, and your server verifies the signature before processing the request.

1️⃣ Connect to the S402 Facilitator Contract

The S402 Facilitator contract handles payment settlement on BNB Chain. Deploy your own or use the official one:

// Contract addresses
const S402_FACILITATOR = "0x75c8CCD195F7B5Fb288B107B45FaF9a1289d7Df1";
const USD1_TOKEN = "0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d";
const BNB_CHAIN_ID = 56;

2️⃣ Create Payment Signatures (Client-Side)

Users sign EIP-712 messages to authorize payments. Here's how to generate a signature using ethers.js:

import { ethers } from "ethers";

async function createPaymentSignature(sender, recipient, amount) {
  const provider = new ethers.BrowserProvider(window.ethereum);
  const signer = await provider.getSigner();
  const nonce = Date.now(); // Unique nonce for replay protection
  const deadline = Math.floor(Date.now() / 1000) + 3600; // 1 hour validity
  
  // EIP-712 domain
  const domain = {
    name: "S402PaymentFacilitator",
    version: "3",
    chainId: BNB_CHAIN_ID,
    verifyingContract: S402_FACILITATOR
  };
  
  // Payment types
  const types = {
    Payment: [
      { name: "sender", type: "address" },
      { name: "recipient", type: "address" },
      { name: "amount", type: "uint256" },
      { name: "nonce", type: "uint256" },
      { name: "deadline", type: "uint256" }
    ]
  };
  
  // Payment data
  const value = {
    sender,
    recipient,
    amount: ethers.parseUnits(amount.toString(), 18), // USD1 has 18 decimals
    nonce,
    deadline
  };
  
  // Sign the message
  const signature = await signer.signTypedData(domain, types, value);
  return { signature, nonce, deadline };
}

3️⃣ Verify Payments (Server-Side)

Your server must verify the signature and settle the payment on-chain:

import { ethers } from "ethers";

async function verifyAndSettlePayment(paymentData) {
  const { sender, recipient, amount, nonce, deadline, signature } = paymentData;
  
  // 1. Verify signature is valid
  const domain = { /* same as client-side */ };
  const types = { /* same as client-side */ };
  const value = { sender, recipient, amount, nonce, deadline };
  
  const recoveredAddress = ethers.verifyTypedData(domain, types, value, signature);
  if (recoveredAddress.toLowerCase() !== sender.toLowerCase()) {
    throw new Error("Invalid signature");
  }
  
  // 2. Check amount is correct
  const expectedAmount = ethers.parseUnits("0.02", 18); // $0.02 for this service
  if (amount !== expectedAmount) {
    throw new Error("Incorrect payment amount");
  }
  
  // 3. Check recipient is your server wallet
  if (recipient.toLowerCase() !== YOUR_SERVER_WALLET.toLowerCase()) {
    throw new Error("Invalid recipient");
  }
  
  // 4. Check deadline hasn't passed
  if (Date.now() / 1000 > deadline) {
    throw new Error("Payment expired");
  }
  
  // 5. Check nonce hasn't been used (prevent replay attacks)
  if (await isNonceUsed(nonce)) {
    throw new Error("Nonce already used");
  }
  
  // 6. Settle payment on-chain via S402 Facilitator
  const provider = new ethers.JsonRpcProvider("https://bsc-dataseed.binance.org");
  const wallet = new ethers.Wallet(SERVER_PRIVATE_KEY, provider);
  const facilitator = new ethers.Contract(S402_FACILITATOR, ABI, wallet);
  
  const tx = await facilitator.settlePayment(
    sender, recipient, amount, nonce, deadline, signature
  );
  await tx.wait();
  
  // 7. Mark nonce as used
  await markNonceUsed(nonce);
  
  return true; // Payment verified!
}

4️⃣ Full Server Example (Express.js)

Here's a complete example of an S402-enabled API endpoint:

import express from "express";
import cors from "cors";

const app = express();
app.use(cors());
app.use(express.json());

// Your paid API endpoint
app.post("/api/generate-image", async (req, res) => {
  try {
    // Extract payment data from request
    const { payment, prompt } = req.body;
    
    // Verify payment
    await verifyAndSettlePayment(payment);
    
    // Payment verified! Process the request
    const imageUrl = await generateImage(prompt);
    
    res.json({ success: true, imageUrl });
  } catch (error) {
    res.status(402).json({
      success: false,
      error: "Payment Required",
      message: error.message
    });
  }
});

app.listen(3001, () => console.log("S402 server running"));

5️⃣ Register Your Service

To appear in the S402 Scan marketplace, insert your service into the database:

INSERT INTO s402_tools (name, price, recipient_address, icon_url, category)
VALUES (
  'My Amazing Service',
  '0.05', -- Price in USD1
  '0xYourServerWallet...',
  'https://example.com/icon.jpg',
  'media' -- or 'data', 'compute', etc.
);

⚠️ Important Security Notes

  • Never accept pre-signed messages - Always verify signatures match the payment parameters
  • Implement nonce tracking - Store used nonces in a database to prevent replay attacks
  • Check deadlines - Reject expired payment signatures to prevent old signatures from being reused
  • Validate amounts - Ensure payment amounts match your service pricing
  • Secure your private key - Use environment variables and never commit keys to version control
  • Monitor gas costs - On-chain settlement costs gas; consider batching for small payments

📦 Helpful Resources

  • S402 Facilitator Contract: 0x75c8CCD195F7B5Fb288B107B45FaF9a1289d7Df1
  • USD1 Token Contract: 0x8d0D000Ee44948FC98c9B98A4FA4921476f08B0d
  • BNB Chain RPC: https://bsc-dataseed.binance.org
  • Example implementation: Check s402-proxy/server.js in the Sora Oracle SDK repository

⚡ KEY FEATURES

🔐

Session Wallets

Create session wallets for zero-signature payments. One-time setup enables seamless AI agent interactions.

Instant Payments

Micropayments settle instantly using EIP-712 signatures, enabling real-time API access.

🛡️

Replay Protection

Built-in nonce and timestamp validation prevents payment replay attacks.

💵

USD1 Stablecoin

All payments use USD1 for predictable pricing and protection from crypto volatility.

📊

Full Transparency

All transactions are recorded on-chain and viewable in the S402 Scan explorer.

🤝

Permissionless

Anyone can become a service provider or create AI agents without approval.

❓ FREQUENTLY ASKED QUESTIONS

What is the difference between a composer and an agent?

A composer is a user who creates AI agents. An agent is an AI assistant with specific tools and capabilities. One composer can create multiple agents.

How much do API calls cost?

Most free public API tools cost $0.01-$0.02 per call. Image generation tools cost around $0.05 per image. Prices are set by service providers.

Can I close my session and get my funds back?

Yes! Sessions can be closed at any time. Your remaining USD1 and BNB balance will be refunded to your main wallet through the S402 payment system.

Do I need to pay fees to use S402 as a developer?

No. S402 is open source and permissionless. You can implement it in your applications without any licensing fees. Platform fees only apply to payments processed through the official facilitator contract.

🔗 USEFUL LINKS

Need more help? Connect your wallet and try the platform!