TON AI Agent Hackathon — Agent Infrastructure Track
First x402 implementation on TON

AI agents can browse the web.
Now they can pay for it.

The x402 protocol brings HTTP 402 Payment Required to life on TON — enabling autonomous machine-to-machine payments for the 1B+ Telegram user ecosystem.

1B+
Telegram Users
~5s
Finality
~$0.01
Per Transaction
34
Tests Passing
5
NPM Packages
0
Core Deps

API monetization is broken for the AI era

AI agents need to access hundreds of APIs autonomously. Today's authentication model was designed for humans, not machines.

Today

  • Sign up on a website, verify email, add credit card
  • Manage API keys, handle rate limits, track quotas
  • Monthly subscriptions for services used once
  • AI agents cannot autonomously discover and pay for new APIs

With x402

  • No signup. No API keys. Just HTTP requests.
  • Pay-per-request. Only pay for what you actually use.
  • Micropayments as low as $0.01 per request via TON
  • AI agents discover, negotiate, and pay automatically

Watch an AI Agent Pay for Data

A Claude agent receives a task, discovers a paid API, sends TON automatically via x402, and retrieves premium data — zero human intervention.

claude-code — x402 agent (MCP: ton-x402)

What can you build with x402 on TON?

From AI research agents to Telegram bot economies — x402 enables entirely new business models where machines transact autonomously.

AI Research Agents

$50B+ AI agent market by 2028

Agents autonomously access premium data sources — financial feeds, scientific databases, proprietary datasets — paying per-request without pre-registration.

agent.fetch("https://api.example.com/research") // auto-pays 0.05 TON

API Monetization

$6B+ API economy

Monetize any API endpoint with a single middleware line. No Stripe, no billing dashboard, no invoices. Revenue flows directly to your TON wallet in real-time.

app.use("/api/*", x402({ amount: "0.01", recipient: wallet }))

Agent-to-Agent Commerce

Multi-agent orchestration

Agents compose services from other agents. An orchestrator agent pays specialist agents for translation, summarization, image generation — all via x402.

orchestrator -> [translator, summarizer, renderer] // each 402

Telegram Bot Economy

1B+ users with built-in wallets

Build Telegram bots that offer premium features with instant TON payments. 1B+ users already have TON wallets in Telegram — zero friction to pay.

bot.command("/premium", () => x402Gate(0.01)) // 1B+ potential users

The ideal chain for machine payments

TON combines the speed, cost, and reach needed for autonomous agent infrastructure at global scale.

1B+
Built-in User Base
Every Telegram user has a TON wallet. No onboarding, no wallet install, no seed phrase friction.
~$0.01
Per Transaction
True micropayments are viable. Pay $0.01 per API call without the fee eating the payment.
~5s
Finality
Fast enough for synchronous HTTP flows. Pay, verify, and receive data in a single user-perceived request.
Feature TON (this project) Base Solana Aptos Ethereum
x402 Protocol Yes Yes Yes Yes Yes
Tx Finality ~5s ~2s ~0.4s ~1s ~12s
Tx Fee ~$0.01 ~$0.01 ~$0.001 ~$0.005 $1-10
Micropayments Excellent Good Excellent Good Poor
Built-in User Base 1B+ (Telegram) Growing Growing Growing Large
MCP Server for AI Included No No No No
Composable Packages 5 npm packages 1 SDK 1 SDK 1 SDK 1 SDK
Test Coverage 34 tests N/A N/A N/A N/A

How x402 Works

Standard HTTP semantics. No new protocols to learn. If your agent can make HTTP requests, it can pay for APIs.

1

HTTP Request

Agent sends a standard GET/POST to any API endpoint.

GET /api/data
2

402 Response

Server responds with payment details: recipient wallet, amount, and network.

402 + payload
3

TON Payment

Client auto-sends TON to the specified recipient. ~5s confirmation.

transfer()
4

Retry + Proof

Request is retried with the payment proof in headers (base64 BOC).

X-Payment-Proof
5

200 OK

Server verifies the transaction on-chain and returns premium data.

200 + data

Built for production, not just demos

Every design decision optimizes for real-world deployment. Zero dependencies in the core, comprehensive tests, and safety-first architecture.

On-Chain Verification

Every payment is verified directly against the TON blockchain. Not trusted headers — cryptographic proof via BOC deserialization.

5 verification checks

Safety Limits

Configurable maxAutoPayAmount prevents accidental overspending. Agents can estimate costs before paying via x402_estimate.

maxAutoPayAmount guard

Idempotency

Unique paymentId per 402 response prevents double payments. Clients and servers can safely retry without duplicate charges.

paymentId per request

Zero-Dep Core

@ton-x402/core has zero external dependencies. Shared types and utilities with no supply-chain risk. Tree-shakeable ESM + CJS builds.

0 dependencies

5 composable packages, zero lock-in

Production-ready, fully typed TypeScript packages. Use the full stack or pick individual layers. Each package has a single responsibility.

5
@ton-x402/mcp
MCP server giving AI agents (Claude, GPT) 4 tools: fetch, balance, estimate, history
223 LoC 3 tests
4
@ton-x402/client
Auto-paying HTTP client. Detects 402, sends TON, retries with proof
218 LoC 8 tests
3
@ton-x402/server
Hono middleware that payment-gates any endpoint with a single line
89 LoC 4 tests
2
@ton-x402/verify
On-chain payment verification via TON API. Confirms tx matches expected params
124 LoC 5 tests
1
@ton-x402/core
Shared types, header constants, utility functions. Zero external dependencies
125 LoC 14 tests

Interactive API Explorer

Hit the live endpoints below. Free endpoints return 200 OK. Premium endpoints return 402 with TON payment details — exactly what an x402 client would see.

Endpoints
Response
Select an endpoint to see the live response...

Production-ready in 5 minutes

Protect your API with payment gates, build auto-paying clients, or give your AI agent a TON wallet via MCP.

// npm install @ton-x402/server hono

import { Hono } from "hono";
import { x402 } from "@ton-x402/server";

const app = new Hono();

// One line to payment-gate any endpoint
app.use("/api/premium/*", x402({
  recipient: "UQB...your-wallet",
  amount:    "0.05",     // 0.05 TON per request
  network:   "testnet",
}));

app.get("/api/premium/data", (c) => {
  return c.json({ data: "premium content" });
});
// npm install @ton-x402/client

import { X402Client } from "@ton-x402/client";

const client = new X402Client({
  mnemonic:         process.env.TON_MNEMONIC.split(" "),
  network:          "testnet",
  maxAutoPayAmount: "0.1",  // Safety cap
});

// Fetch like normal - payment is invisible
const res  = await client.fetch("https://api.example.com/premium/data");
const data = await res.json();
// That's it. 402 -> pay -> retry happened automatically.
// Add to your AI agent's MCP config (Claude, GPT, etc.)
// npm install @ton-x402/mcp

{
  "mcpServers": {
    "ton-x402": {
      "command": "npx",
      "args":    ["ton-x402-mcp"],
      "env": {
        "TON_MNEMONIC": "word1 word2 ... word24",
        "TON_NETWORK": "testnet"
      }
    }
  }
}

// Your AI agent now has these tools:
//
//   x402_fetch    - Fetch any URL, auto-pay if 402
//   x402_balance  - Check TON wallet balance
//   x402_estimate - Preview cost without paying
//   x402_history  - View recent payments
# 1. Free endpoint - returns 200 OK
curl /api/info

# 2. Premium endpoint - returns 402 Payment Required
curl -i /api/premium/joke

# Response headers:
#   HTTP/2 402
#   X-Payment-Protocol: x402-ton
#
# Response body:
#   { "recipient": "UQDr...EPz4",
#     "amount": "10000000",
#     "token": "TON",
#     "network": "testnet" }

# 3. After paying on TON, retry with proof:
curl -H "X-Payment-Proof: <base64-boc>" \
     -H "X-Payment-Id: <payment-id>" \
     -H "X-Payment-Sender: <your-wallet>" \
     /api/premium/joke

From hackathon to production

ton-x402 is shipping today with a clear path to production deployment. Each milestone is scoped and achievable.

v0.1 Foundation
Core protocol + 5 packages + MCP server
Full x402 implementation: core types (0 deps), payment verification, Hono middleware, auto-paying client, and MCP server with 4 tools. 34 tests passing across all packages.
Shipped
v0.2 Demo & Docs
Live demo, landing page, hackathon submission
Interactive Cloudflare Worker demo with live 402 endpoints. Comprehensive documentation, getting-started guides, and this landing page.
Current
v0.3 Token Support
Jetton payments (USDT, NOT, custom tokens)
Extend x402 to support Jetton (TRC-20) payments. Stablecoin support enables predictable pricing for API providers. Protocol version negotiation.
Planned
v0.4 Mainnet
Production deployment + Express/Fastify adapters
Mainnet-ready verification with hardened security. Additional server framework adapters beyond Hono. Rate limiting, analytics, and monitoring hooks.
Planned
v0.5 Ecosystem
Payment channels, marketplace, Telegram Mini App SDK
State channels for high-frequency micropayments. API marketplace where agents discover and pay for services. Telegram Mini App integration for consumer-facing x402 flows.
Planned

Start building the
agent economy on TON

5 packages. 34 tests. Full TypeScript. Zero-dep core. Whether you're monetizing APIs or building autonomous agents, ton-x402 gets you there in minutes.

Install now: npm install @ton-x402/client @ton-x402/server