Skip to main content
Glama

updatePaymentInstruction

Modify existing payment instructions for USDC transactions on Base networks by updating recipient addresses, amounts, descriptions, and network settings.

Instructions

Update an existing x402 payment instruction. Currently supports USDC (6 decimals) on Base/Base Sepolia only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesThe unique identifier of the payment instruction to update
nameNoUpdated name
pay_toNoUpdated wallet address (0x...) to receive USDC payments
amount_usdcNoUpdated price in USD as a string (e.g., '0.01' for 1 cent, '1.50' for $1.50)
networkNoUpdated blockchain network
descriptionNoUpdated description

Implementation Reference

  • The handler function that executes the updatePaymentInstruction tool logic. It constructs a PATCH request to the Pinata API to update payment instructions, converting USD amounts to USDC smallest units (6 decimals) and building the payload conditionally based on provided parameters.
    async ({ id, name, pay_to, amount_usdc, network, description }) => {
      try {
        const url = `https://api.pinata.cloud/v3/x402/payment_instructions/${id}`;
    
        // USDC contract addresses
        const USDC_ADDRESSES: Record<string, string> = {
          "base": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
          "base-sepolia": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
        };
    
        const payload: {
          name?: string;
          payment_requirements?: Array<{
            asset: string;
            pay_to: string;
            network: string;
            amount: string;
          }>;
          description?: string;
        } = {};
    
        if (name) payload.name = name;
        if (pay_to && amount_usdc && network) {
          // Convert USD amount to USDC smallest unit (6 decimals)
          const amountInSmallestUnit = Math.round(parseFloat(amount_usdc) * 1_000_000).toString();
          payload.payment_requirements = [{
            asset: USDC_ADDRESSES[network],
            pay_to,
            network,
            amount: amountInSmallestUnit,
          }];
        }
        if (description) payload.description = description;
    
        const response = await fetch(url, {
          method: "PATCH",
          headers: getHeaders(),
          body: JSON.stringify(payload),
        });
    
        if (!response.ok) {
          throw new Error(
            `Failed to update payment instruction: ${response.status} ${response.statusText}`
          );
        }
    
        const data = await response.json();
        return successResponse(data);
      } catch (error) {
        return errorResponse(error);
      }
    }
  • The zod schema defining the input parameters for updatePaymentInstruction tool. It includes optional fields for id (required), name, pay_to, amount_usdc, network (enum: 'base' | 'base-sepolia'), and description.
    {
      id: z
        .string()
        .describe("The unique identifier of the payment instruction to update"),
      name: z.string().optional().describe("Updated name"),
      pay_to: z
        .string()
        .optional()
        .describe("Updated wallet address (0x...) to receive USDC payments"),
      amount_usdc: z
        .string()
        .optional()
        .describe("Updated price in USD as a string (e.g., '0.01' for 1 cent, '1.50' for $1.50)"),
      network: z
        .enum(["base", "base-sepolia"])
        .optional()
        .describe("Updated blockchain network"),
      description: z.string().optional().describe("Updated description"),
  • src/index.ts:1119-1193 (registration)
    The complete tool registration using server.tool() which registers the updatePaymentInstruction tool with its name, description, schema, and handler function.
    server.tool(
      "updatePaymentInstruction",
      "Update an existing x402 payment instruction. Currently supports USDC (6 decimals) on Base/Base Sepolia only.",
      {
        id: z
          .string()
          .describe("The unique identifier of the payment instruction to update"),
        name: z.string().optional().describe("Updated name"),
        pay_to: z
          .string()
          .optional()
          .describe("Updated wallet address (0x...) to receive USDC payments"),
        amount_usdc: z
          .string()
          .optional()
          .describe("Updated price in USD as a string (e.g., '0.01' for 1 cent, '1.50' for $1.50)"),
        network: z
          .enum(["base", "base-sepolia"])
          .optional()
          .describe("Updated blockchain network"),
        description: z.string().optional().describe("Updated description"),
      },
      async ({ id, name, pay_to, amount_usdc, network, description }) => {
        try {
          const url = `https://api.pinata.cloud/v3/x402/payment_instructions/${id}`;
    
          // USDC contract addresses
          const USDC_ADDRESSES: Record<string, string> = {
            "base": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
            "base-sepolia": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
          };
    
          const payload: {
            name?: string;
            payment_requirements?: Array<{
              asset: string;
              pay_to: string;
              network: string;
              amount: string;
            }>;
            description?: string;
          } = {};
    
          if (name) payload.name = name;
          if (pay_to && amount_usdc && network) {
            // Convert USD amount to USDC smallest unit (6 decimals)
            const amountInSmallestUnit = Math.round(parseFloat(amount_usdc) * 1_000_000).toString();
            payload.payment_requirements = [{
              asset: USDC_ADDRESSES[network],
              pay_to,
              network,
              amount: amountInSmallestUnit,
            }];
          }
          if (description) payload.description = description;
    
          const response = await fetch(url, {
            method: "PATCH",
            headers: getHeaders(),
            body: JSON.stringify(payload),
          });
    
          if (!response.ok) {
            throw new Error(
              `Failed to update payment instruction: ${response.status} ${response.statusText}`
            );
          }
    
          const data = await response.json();
          return successResponse(data);
        } 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