Prerequisites
- x402 feature flag enabled on your Pinata account
- Authentication with appropriate permissions (
OrgFilesReadorOrgFilesWrite) - Private files uploaded to Pinata IPFS
Understanding Payment Instructions
A Payment Instruction is a reusable configuration that defines:- Payment requirements - The amount, token, and recipient for payments
- Network configuration - Which blockchain network to use
- Metadata - Name and description for organization
The
payment_requirements field is an array for future extensibility. Currently, only the first payment requirement in the array is processed by the gateway.Payment Instruction Structure
The
version field is automatically managed by Pinata and increments with each update. You don’t need to set this field when creating or updating payment instructions.Networks and Tokens
Currently supported configurations:Base Mainnet (Production)
- Network:
base - USDC Token Address:
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 - Use for: Production monetization
Base Sepolia (Testing)
- Network:
base-sepolia - USDC Token Address:
0x036CbD53842c5426634e7929541eC2318f3dCF7e - Use for: Testing payment flows
Complete Workflow
Step 1: Upload Private Content
First, upload your file as private to Pinata:private network to be monetized with x402.
Step 2: Create Payment Instruction
Create a payment instruction with your desired requirements:Step 3: Attach CID to Payment Instruction
Link your private file to the payment instruction:Step 4: Share x402 Gateway URL
Your content is now monetized and accessible at:Managing Payment Instructions
Listing Instructions
View all your payment instructions with pagination:?cid=bafkreih...- Find instruction for a specific CID?name=Premium- Filter by name?id=019a2b6a...- Get specific instruction
Updating Instructions
Modify payment requirements for all attached CIDs:Deleting Instructions
Before deleting, remove all CID attachments:CID Management
One-to-Many Relationship
- One Payment Instruction can be attached to multiple CIDs
- Each CID can only have one Payment Instruction at a time
- Updating the instruction affects all attached CIDs
Managing CID Attachments
Gateway Behavior
When a requester accesses your x402 gateway URL without payment, the gateway returns payment requirements:Without Payment (402 Response)
With Valid Payment
The gateway:- Validates the
X-Paymentheader - Verifies the payment proof
- Checks amount, recipient, and network match requirements
- Serves the private content
Best Practices
Payment Amounts
Themax_amount_required uses USDC’s smallest unit. USDC has 6 decimals, so to convert USD to the token amount, multiply by 1,000,000:
| USD Amount | max_amount_required | 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 |
| $5.00 | "5000000" | $5.00 × 1,000,000 |
| $10.00 | "10000000" | $10.00 × 1,000,000 |
- Consider transaction costs when setting minimum amounts
- Test on Base Sepolia before deploying to mainnet
Instruction Organization
- Use descriptive names for easy management
- Group similar content under one instruction
- Document your payment requirements clearly
Security Considerations
- Only private files can be monetized
- Ensure your
pay_toaddress is correct. You receive payments directly to this address. - Test payment flows on testnet first
- Monitor your gateway analytics
Troubleshooting
Common Issues
409 Conflict when deleting instruction- Solution: Remove all CID attachments first
- Check
assetandpay_toaddresses start with0x - Verify
networkis eitherbaseorbase-sepolia - Ensure
max_amount_requiredis provided
- Verify the CID exists and is private
- Check the CID is attached to a payment instruction
- Ensure the gateway URL format is correct