Learn how to access x402-protected content on Pinata.Documentation Index
Fetch the complete documentation index at: https://docs.pinata.cloud/llms.txt
Use this file to discover all available pages before exploring further.
Overview
When attempting to access x402-protected content without a payment payload, the gateway returns payment requirements. After making a payment, requesters receive a payment proof that grants access to the content.The Payment Flow
The content creator provides their dedicated Pinata gateway URL. Replace
your-gateway.mypinata.cloud in examples with the actual gateway domain provided.Step 1: Request the Content
Make a GET request to the x402 gateway URL:Step 2: Receive Payment Requirements (402 Response)
The gateway returns HTTP 402 with payment details:network: Blockchain network (e.g.,base)asset: Token contract address (USDC on Base)payTo: Recipient wallet address (content creator receives payment here)maxAmountRequired: Payment amount in smallest unit (e.g.,10000= 0.01 USDC)
Step 3: Access Content with Payment Proof
After successful payment, include theX-Payment header in the request:
- Validate the
X-Paymentheader - Verify the payment proof
- Check that amount, recipient, and network match
- Serve the private content
Using x402 Libraries
The x402 protocol has client libraries that automate the payment flow. First, set up your wallet:Setting Up Your Wallet
The x402 libraries require a Viem account or Coinbase Developer Platform wallet:Option 1: Viem Local Account
Option 2: Coinbase CDP Wallet
Using the Libraries
Once you have your wallet set up, use the x402 libraries to access paid content:@x402/fetch
@x402/axios
Technical Details (Optional)
Pinata uses Coinbase Facilitator to process x402 payments, which provides access to Coinbase’s Discovery Bazaar network for broader content discovery.
Understanding Payment Amounts
USDC uses 6 decimals, so amounts use the token’s smallest unit:| USD Amount | maxAmountRequired | Calculation |
|---|---|---|
| $0.01 | 10000 | $0.01 × 1,000,000 |
| $0.10 | 100000 | $0.10 × 1,000,000 |
| $1.00 | 1000000 | $1.00 × 1,000,000 |
| $10.00 | 10000000 | $10.00 × 1,000,000 |
Error Handling
402 Payment Required
Payment has not been made yet. Follow the payment flow above.403 Forbidden
Payment proof is invalid or expired. Make a new payment.404 Not Found
The CID doesn’t exist or isn’t attached to a payment instruction.500 Internal Server Error
Gateway or facilitator error. Contact the content creator.Network Support
USDC is currently the only supported token.| Network | Status | Token | Use Case |
|---|---|---|---|
| Base (Mainnet) | ✅ Available | USDC (0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913) | Production |
| Base Sepolia (Testnet) | ✅ Available | USDC (0x036CbD53842c5426634e7929541eC2318f3dCF7e) | Testing |
Best Practices
- Handle 402 responses gracefully: Display payment requirements clearly
- Use the x402 libraries: They handle the complex payment flow automatically
- Test on Base Sepolia first: Verify integration before using mainnet
- Store payment proofs: If accessing content multiple times (check expiry)
- Monitor USDC balance: Ensure sufficient funds for payments