@@ -32,15 +32,6 @@ When a user makes a request to a paid API:
3232
3333## 402 Payment Protocol Fundamentals
3434
35- ### Payment Flow
36- The 402 payment protocol follows a simple request-retry pattern:
37-
38- 1 . ** Initial request** : Client makes normal API call
39- 2 . ** 402 response** : Server responds with payment requirements if payment needed
40- 3 . ** Payment authorization** : User signs payment message in their wallet
41- 4 . ** Retry with payment** : Request is retried with payment header
42- 5 . ** Content delivery** : Server validates payment and returns content
43-
4435### Payment Processors
4536A ** payment processor** is a service that handles payment verification and settlement for 402 payments. Think of it as the backend service that:
4637- Validates payment signatures from users
@@ -52,11 +43,6 @@ thirdweb's 402 payment implementation currently supports:
5243- ** "exact"** : Fixed price payments (e.g., exactly $0.01 USDC) - our first supported scheme
5344- Additional schemes (percentage-based, auction-style, variable pricing) are planned for future versions
5445
55- ### Security Model
56- - ** Signature-based** : Users sign payment authorizations, no direct token transfers from client
57- - ** Replay protection** : Each payment includes unique identifiers to prevent reuse
58- - ** Amount validation** : Clients can set maximum payment limits for protection
59-
6046## Supported Payment Networks & Tokens
6147
6248### Supported Networks
@@ -68,41 +54,41 @@ thirdweb's 402 payment processor currently supports payments on:
6854- ** IoTeX** (mainnet)
6955- ** Sei** (mainnet)
7056- ** Sei Testnet**
57+ - ** Solana (coming soon)**
58+ - ** Solana Devnet (coming soon)**
7159
7260### Payment Tokens
7361- ** Primary** : USDC on all supported networks
7462- ** Stablecoins** : Other USD-pegged tokens as available per network
7563- ** Network selection** : Client and server automatically negotiate the best payment network
7664
77- ### Chain Switching
78- If your wallet is connected to a different network than required for payment, the client will automatically:
79- 1 . Detect the payment network requirement
80- 2 . Prompt you to switch to the correct network
81- 3 . Proceed with payment once switched
65+ ## thirdweb 402 Payment Components
8266
83- ## thirdweb as 402 Payment Processor
67+ thirdweb provides a complete 402 payment system with components for both client and server sides, plus backend payment processing infrastructure.
8468
85- thirdweb provides a complete 402 payment processing service that handles all the payment infrastructure for your APIs.
69+ ### Client-Side Components
70+ ** For app developers integrating payment functionality:**
71+ - ** ` wrapFetchWithPayment ` ** : Automatically handles 402 responses and payment flows
72+ - ** Wallet integration** : Works with any thirdweb-supported wallet (inapp, MetaMask, WalletConnect, etc.)
73+ - ** Payment authorization** : Prompts users to sign payment messages when needed
74+ - ** Chain switching** : Automatically switches to the required payment network
75+ - ** Error handling** : Manages payment failures, insufficient funds, and user rejections
8676
87- ### What thirdweb Provides
77+ ### Server-Side Components
78+ ** For API providers implementing gated endpoints:**
79+ - ** Middleware libraries** : Integration with popular frameworks (` x402-next ` , ` x402-hono ` , ` x402-express ` )
8880- ** Payment verification** : Validates user payment signatures and wallet balances
89- - ** Multi-chain settlement** : Supports payments across multiple blockchain networks
90- - ** Server wallet integration** : Uses your configured server wallet to receive payments
91- - ** Gasless transactions** : Handles all gas costs for payment settlement
92- - ** Automatic execution** : Payments are settled without manual intervention
93-
94- ### Server Wallet Concept
95- Your ** server wallet** is the blockchain address where all API payments are collected. When users pay for API access:
96- 1 . They sign a payment authorization to your server wallet address
97- 2 . thirdweb validates the payment signature and user's token balance
98- 3 . thirdweb executes the token transfer to your server wallet
99- 4 . You receive the payment automatically without gas costs
100-
101- ### Integration Benefits
102- - ** Simple setup** : Just provide your server wallet address and thirdweb secret key
103- - ** No blockchain complexity** : thirdweb handles all on-chain interactions
104- - ** Reliable settlement** : Payments are automatically executed when valid
105- - ** Multi-chain support** : Accept payments on multiple networks simultaneously
81+ - ** Multi-chain support** : Accepts payments across multiple blockchain networks
82+ - ** Automatic settlement** : Executes token transfers to your server wallet
83+ - ** Gasless transactions** : thirdweb covers all gas costs for payment processing
84+
85+ ### Server Wallet
86+ Your ** Server Wallet** is the blockchain address where all API payments are collected:
87+ - ** Payment destination** : Users authorize payments to this specific wallet address
88+ - ** Multi-network** : Same wallet can receive payments across different supported chains
89+ - ** Automatic collection** : thirdweb handles the transfer execution without manual intervention
90+ - ** Gasless payments** : Payment transfers are performed in gasless fashion to reduce friction
91+ - ** Real-time settlement** : Payments arrive in your wallet immediately after validation
10692
10793## Client-Side Implementation
10894
@@ -286,20 +272,3 @@ export const config = {
286272 matcher: [" /api/basic-data" , " /api/premium-analytics" , " /api/ai-processing" ],
287273};
288274```
289-
290- ### Environment Variables
291-
292- Set up the required environment variables:
293-
294- ``` bash
295- # .env.local
296- THIRDWEB_SECRET_KEY=your_thirdweb_secret_key
297- SERVER_WALLET_ADDRESS=0x1234567890123456789012345678901234567890
298- ```
299-
300- ### Security Considerations
301-
302- - ** Never expose your secret key** : Keep ` THIRDWEB_SECRET_KEY ` in server environment only
303- - ** Server wallet security** : Use a dedicated wallet for collecting payments, separate from development wallets
304- - ** Network selection** : Use testnets for development, mainnets for production
305- - ** Price validation** : Set appropriate prices to prevent abuse while maintaining accessibility
0 commit comments