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);
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While it mentions the creation action and technical constraints, it doesn't address important behavioral aspects like authentication requirements, rate limits, error conditions, what happens on duplicate creation, or whether the operation is idempotent. For a creation tool with zero annotation coverage, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with just two sentences that each earn their place. The first sentence states the core purpose, and the second provides critical technical constraints. There's zero wasted text, and the information is front-loaded appropriately.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a creation tool with no annotations and no output schema, the description provides adequate basic context about purpose and technical constraints. However, it lacks important completeness elements like what the tool returns (payment instruction ID? confirmation?), error scenarios, or prerequisites. The 100% schema coverage helps, but behavioral aspects remain underspecified.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. It mentions USDC and networks generally, but doesn't provide additional semantic context about the parameters themselves. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Create a new x402 payment instruction') and resource ('for content monetization'), distinguishing it from sibling tools like 'updatePaymentInstruction' or 'deletePaymentInstruction'. It provides concrete technical scope ('USDC on Base/Base Sepolia only') that differentiates it from other payment-related tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context about when to use this tool ('for content monetization') and technical constraints ('Currently supports USDC on Base/Base Sepolia only'), which helps differentiate from alternatives. However, it doesn't explicitly state when NOT to use it or name specific alternative tools for different scenarios.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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