import { PinataSDK } from "pinata";
const pinata = new PinataSDK({
pinataJwt: process.env.PINATA_JWT!,
pinataGateway: "your-gateway.mypinata.cloud",
});
// 1. Upload a private file
const file = new File(["premium content"], "content.pdf", { type: "application/pdf" });
const upload = await pinata.upload.private.file(file);
// 2. Create a payment instruction
const instruction = await pinata.x402.createPaymentInstruction({
name: "Premium Content Access",
payment_requirements: [
{
asset: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", // USDC on Base
pay_to: "0xYourWalletAddress", // YOU receive payments here
network: "base",
amount: "10000", // $0.01 in USDC
},
],
});
// 3. Attach CID to payment instruction
await pinata.x402.addCid(instruction.data.id, upload.cid);
// 4. Share the x402 gateway URL
// https://your-gateway.mypinata.cloud/x402/cid/{cid}