X402 Protocol
RushChat implements the Coinbase X402 protocol for payment and resource access control.
X402 Protocol Overview
Protocol Overview
X402 is an open protocol for web payments, allowing clients to access protected resources through cryptocurrency payments.
Core Principles
According to the Coinbase X402 Protocol:
"Easy to use: x402 needs to be 10x better than existing ways to pay on the internet. This means abstracting as many details of crypto as possible away from the client and resource server, and into the facilitator."
Key point: Gas fees should be handled by the Facilitator, clients and resource servers don't need to consider Gas.
Protocol Flow
1. Client Requests Resource
2. Server Returns 402
HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: {
"amount": "1000000000000000000",
"currency": "ETH",
"chainId": 1,
"recipient": "0x..."
}
3. Client Provides Payment Proof
4. Server Verifies Payment
- Verify transaction hash
- Verify transaction amount
- Verify transaction recipient
- Verify on-chain status
5. Return Resource
Current Implementation
X402 Standards Compliant
- ✅ Uses HTTP 402 status code
- ✅ Uses PAYMENT-REQUIRED header
- ✅ Uses PAYMENT-SIGNATURE header
- ✅ Uses PAYMENT-RESPONSE header
- ✅ Data structure complies with standards
- ✅ Real on-chain transactions
- ✅ Transaction verification
Optional Optimizations
- ⚠️ Facilitator (Gas abstraction): Currently not implemented, but this is optional
- ⚠️ Batch payments: Planned
- ⚠️ Payment subscriptions: Planned
Gas Fees
Current Implementation
- User pays Gas (when sending red packet)
- Platform pays Gas (when claiming red packet)
Ideal State (Using Facilitator)
- Facilitator pays Gas
- User only needs to sign authorization
- Better user experience