A Cloudflare Workers API that enables pay-per-use IPFS file storage via Pinata using the x402 v2 protocol.
- x402 v2 Payment Protocol: Accept crypto payments on Base (mainnet) and Base Sepolia (testnet)
- Dynamic Pricing: Price scales with file size (0.1 USDC per GB for 12 months)
- Public & Private Storage: Upload files with different visibility levels
- Pay-to-Retrieve: Charge for accessing private files
npm installCopy .dev.vars.example to .dev.vars and fill in your credentials:
cp .dev.vars.example .dev.varsRequired variables:
CDP_API_KEY_ID- Your Coinbase Developer Platform API Key ID (for mainnet)CDP_API_KEY_SECRET- Your CDP API Key Secret (for mainnet)PINATA_JWT- Your Pinata API JWT tokenPINATA_GATEWAY_KEY- Your Pinata gateway access key
Set the network in wrangler.jsonc:
"base"- For mainnet (requires CDP credentials)"base-sepolia"- For testnet
npm run devThis starts a local development server at http://localhost:8787
Run tests:
npm test # All tests
npm run test:sepolia # Base Sepolia testnet
npm run test:mainnet # Base mainnetFor mainnet tests, set:
export TEST_API_URL=https://your-worker-url.workers.dev
export TEST_PRIVATE_KEY=0x... # Test wallet with USDC and ETHnpm run deploy # Deploy to default environment
npm run deploy:dev # Deploy to dev environment
npm run deploy:prod # Deploy to prod environmentMake sure to set secrets in Cloudflare Workers dashboard:
CDP_API_KEY_IDCDP_API_KEY_SECRETPINATA_JWTPINATA_GATEWAY_KEY
Upload a public file to Pinata. Returns a signed URL for upload.
Payment: Dynamic based on file size (query param fileSize)
Upload a private file to Pinata. Returns a signed URL for upload.
Payment: Dynamic based on file size (query param fileSize)
Retrieve a private file by CID. Returns a temporary access URL.
Payment: Fixed 0.0001 USDC
This server uses x402 v2 protocol with:
- Facilitators: CDP mainnet facilitator for production, x402.org for testnet
- Network IDs: CAIP-2 format (
eip155:8453for Base,eip155:84532for Base Sepolia) - Authentication: Automatic via
@coinbase/x402package when CDP env vars are set
For more info, see x402 v2 Migration Guide