x402 Protocol brings HTTP micro payments to Sei, enabling you to monetize APIs, premium content, and digital services with instant, low-cost payments. Whether you’re building AI APIs, data feeds, or premium content platforms, x402 makes it simple to add payment gates to any HTTP endpoint. Works with Sei’s advantages: Sei’s fast finality, low gas fees, and EVM compatibility make it perfect for micro payments. x402 leverages these features to enable seamless payment flows that complete in milliseconds.Documentation Index
Fetch the complete documentation index at: https://seilabs.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Why x402 on Sei?
- Fast & Cheap Payments: Sei’s 400ms finality and low gas fees make micropayments practical. Perfect for pay-per-request APIs and streaming content.
- EVM Compatible: Use familiar tools like Viem, Ethers.js, and Hardhat. All existing Ethereum tooling works seamlessly on Sei.
- Built-in Wallet Support: Integrates with Sei wallets, MetaMask, and any EIP-6963 compatible wallet for smooth user experiences.
Use Cases on Sei
The x402 protocol enables a wide range of monetization strategies for web services and APIs:- AI & Machine Learning Services: Per-inference pricing for LLM APIs, image generation, and data processing.
- Premium Content & Media: Pay-per-view articles, videos, and subscription gates.
- Real-Time Data & APIs: Market data feeds, weather and IoT data monetization.
- Infrastructure & CDN Services: Bandwidth metering and storage payments.
sei-js Integration
Thesei-js library provides a suite of packages to simplify working with x402 on Sei. You can find more details in the sei-js x402 documentation.
Core Concepts
- Protocol Overview: Learn about the architecture of x402.
- Quickstart Guide: Build your first paid API.
- Facilitators: Understanding payment facilitators.
- Client Integration: How to integrate x402 in your frontend.
Available Packages
- x402: The core protocol implementation.
- x402-fetch: A fetch wrapper for making x402-compliant requests.
- x402-axios: Axios interceptors for x402 payments.
- x402-express: Express middleware for serving paid content.
- x402-hono: Middleware for Hono applications.
- x402-next: Components and utilities for Next.js applications.
Axiom Kit Integration
While you can build x402 integrations using standard tools and the libraries mentioned above, you can also optionally use Axiom Kit for a more agent-centric approach. This guide demonstrates an end-to-end x402 (HTTP 402 Payment Required) micropayment flow on the Sei testnet using AxiomKit.What is x402?
x402 is an open standard protocol for internet-native payments that enables users to send and receive payments globally in a simple, secure, and interoperable manner. The protocol leverages the HTTP 402 status code (“Payment Required”) to facilitate blockchain-based micropayments directly through HTTP requests.Key Features of x402:
- HTTP-Native: Uses standard HTTP status codes and headers
- Blockchain Integration: Supports multiple blockchain networks
- Real-time Settlement: Enables instant payment verification
- Interoperable: Works across different payment schemes and networks
- Micropayment Support: Designed for small, frequent transactions
Protocol Overview
The x402 protocol follows a specific flow:- Initial Request: Client makes a request to a protected resource
- 402 Response: Server responds with HTTP 402 and payment requirements
- Payment Execution: Client executes blockchain payment
- Payment Proof: Client includes payment proof in subsequent request
- Resource Access: Server verifies payment and grants access
Axiom Integration
Axiom is a blockchain interaction framework that provides tools and libraries for building decentralized applications. In this implementation, Axiom integrates with x402 to enable seamless blockchain payments within Sei network applications.Axiom Components Used:
- @axiomkit/core: Core framework for building blockchain agents
- @axiomkit/sei: Sei blockchain integration
- AxiomSeiWallet: Wallet management for Sei transactions
- Context and Actions: Framework for building interactive blockchain agents
Sei Blockchain Implementation
This implementation uses the Sei testnet for x402 payments with the following configuration:Network Configuration
Technical Architecture
The x402 implementation consists of several key components:1. Payment Challenge Generation
2. Payment Verification
3. Axiom Agent Integration
The Axiom agent handles the complete x402 flow:Payment Flow
1. Initial Request
2. Payment Challenge Response
3. Payment Execution
The Axiom agent executes a USDC transfer on Sei testnet:4. Payment Proof Submission
Code Examples
Complete Weather API Implementation
Axiom Agent Weather Action
Security Considerations
Payment Verification
- On-chain Verification: All payments are verified against the Sei blockchain.
- Transaction Receipt Validation: Ensures transaction success and proper recipient.
- Payment Caching: Prevents double-spending by caching verified payments.
- Reference Validation: Unique payment references prevent replay attacks.
Network Security
- HTTPS Required: All API communications use secure connections.
- Base64 Encoding: Payment proofs are base64 encoded for safe transmission.
- Timeout Handling: Payment challenges include timeout mechanisms.
- Error Handling: Comprehensive error handling prevents information leakage.
Wallet Security
- Private Key Management: Private keys are stored securely in environment variables.
- Transaction Signing: All transactions are properly signed before submission.
- Balance Validation: Sufficient balance checks before payment execution.
Tutorials & Resources
- Sei-js X402 Documentation: Comprehensive guide on using the x402 protocol with the sei-js library, including package details and examples.
- AxiomKit X402 Demo Repository: The complete source code for the Axiom integration demo used in this guide, including installation and configuration instructions.