Skip to main content
Learn how to access x402-protected content on Pinata.

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:
Key Fields:
  • 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 the X-Payment header in the request:
The gateway will:
  1. Validate the X-Payment header
  2. Verify the payment proof
  3. Check that amount, recipient, and network match
  4. Serve the private content
Successful Response:

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: Formula: USD Amount × 1,000,000 = token amount

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.

Best Practices

  1. Handle 402 responses gracefully: Display payment requirements clearly
  2. Use the x402 libraries: They handle the complex payment flow automatically
  3. Test on Base Sepolia first: Verify integration before using mainnet
  4. Store payment proofs: If accessing content multiple times (check expiry)
  5. Monitor USDC balance: Ensure sufficient funds for payments

Example: Complete Integration

Resources

Support

Need help accessing paid content? Contact the content creator or reach out to team@pinata.cloud.