Skip to main content
Glama

createPaymentInstruction

Generate payment instructions for content monetization using USDC on Base networks. Specify recipient address, price, and details to create x402 payment links.

Instructions

Create a new x402 payment instruction for content monetization. Currently supports USDC (6 decimals) on Base/Base Sepolia only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName for the payment instruction
pay_toYesWallet address (0x...) to receive USDC payments
amount_usdcYesPrice in USD as a string (e.g., '0.01' for 1 cent, '1.50' for $1.50). Will be converted to USDC's 6 decimal format.
networkNoBlockchain network (Base mainnet or Base Sepolia testnet)base
descriptionNoDescription of the payment instruction

Implementation Reference

  • Complete tool registration and handler for createPaymentInstruction. Creates x402 payment instructions for content monetization, supporting USDC on Base/Base Sepolia networks. Converts USD amounts to USDC's 6 decimal format and makes a POST request to Pinata's v3/x402/payment_instructions endpoint.
    server.tool(
      "createPaymentInstruction",
      "Create a new x402 payment instruction for content monetization. Currently supports USDC (6 decimals) on Base/Base Sepolia only.",
      {
        name: z.string().describe("Name for the payment instruction"),
        pay_to: z
          .string()
          .describe("Wallet address (0x...) to receive USDC payments"),
        amount_usdc: z
          .string()
          .describe("Price in USD as a string (e.g., '0.01' for 1 cent, '1.50' for $1.50). Will be converted to USDC's 6 decimal format."),
        network: z
          .enum(["base", "base-sepolia"])
          .default("base")
          .describe("Blockchain network (Base mainnet or Base Sepolia testnet)"),
        description: z
          .string()
          .optional()
          .describe("Description of the payment instruction"),
      },
      async ({ name, pay_to, amount_usdc, network, description }) => {
        try {
          const url = "https://api.pinata.cloud/v3/x402/payment_instructions";
    
          // USDC contract addresses
          const USDC_ADDRESSES: Record<string, string> = {
            "base": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
            "base-sepolia": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
          };
    
          // Convert USD amount to USDC smallest unit (6 decimals)
          // e.g., "0.01" -> "10000", "1.50" -> "1500000"
          const amountInSmallestUnit = Math.round(parseFloat(amount_usdc) * 1_000_000).toString();
    
          const payload: {
            name: string;
            payment_requirements: Array<{
              asset: string;
              pay_to: string;
              network: string;
              amount: string;
            }>;
            description?: string;
          } = {
            name,
            payment_requirements: [{
              asset: USDC_ADDRESSES[network],
              pay_to,
              network,
              amount: amountInSmallestUnit,
            }],
          };
    
          if (description) payload.description = description;
    
          const response = await fetch(url, {
            method: "POST",
            headers: getHeaders(),
            body: JSON.stringify(payload),
          });
    
          if (!response.ok) {
            const errorText = await response.text();
            throw new Error(
              `Failed to create payment instruction: ${response.status} ${response.statusText}\n${errorText}`
            );
          }
    
          const data = await response.json();
          return {
            content: [
              {
                type: "text",
                text: `✅ Payment instruction created successfully!\n\n${JSON.stringify(data, null, 2)}`,
              },
            ],
          };
        } catch (error) {
          return errorResponse(error);
        }
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/PinataCloud/pinata-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server