Prerequisites
- Paid Pinata account
- Pinata SDK installed
- 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, allowing you to define multiple payment options. Each payment instruction can have multiple requirements, giving requesters flexibility in how they pay.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. USDC is the only supported token at this time.Base Mainnet (Production)
- Network:
base(oreip155:8453) - USDC Token Address:
0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 - Use for: Production monetization
Base Sepolia (Testing)
- Network:
base-sepolia(oreip155:84532) - 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:Getting a Single Instruction
Updating Instructions
Modify payment requirements for all attached CIDs:Deleting Instructions
Before deleting, remove all CID attachments:CID Management
CID and Payment Instruction Relationship
- One Payment Instruction → Multiple CIDs: A single payment instruction can be attached to multiple CIDs
- One CID → One Payment Instruction: Each CID can only have one payment instruction at a time
- Multiple Requirements: A payment instruction can have multiple payment requirements in its
payment_requirementsarray - 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
Theamount uses USDC’s smallest unit. USDC has 6 decimals, so to convert USD to the token amount, multiply by 1,000,000:
| USD Amount | amount | 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
networkisbase,base-sepolia,eip155:8453, oreip155:84532 - Ensure
amountis provided
- Verify the CID exists and is private
- Check the CID is attached to a payment instruction
- Ensure the gateway URL format is correct
SDK Reference
- List Payment Instructions
- Create Payment Instruction
- Get Payment Instruction
- Update Payment Instruction
- Delete Payment Instruction
- List CIDs
- Add CID
- Remove CID