Skip to main content
Glama

generate_fungible_post_condition

Create mandatory SIP-010 fungible token transfer post-conditions for Stacks blockchain transactions, ensuring secure token operations by specifying conditions like amount equality or comparison.

Instructions

Generate a fungible token post-condition for SIP-010 tokens. Post-conditions are MANDATORY for all token transfers.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe token amount in base units
assetNameYesThe token asset name (usually same as contract name)
conditionCodeYesThe condition type (usually 'equal' for exact transfers)
contractAddressYesThe token contract address
contractNameYesThe token contract name
principalYesThe Stacks address for the post-condition

Implementation Reference

  • The main handler for the 'generate_fungible_post_condition' tool. This is the execute function that generates TypeScript code, Clarity requirements, and security notes for fungible token post-conditions based on input parameters.
    export const generateFungiblePostConditionTool: Tool<undefined, typeof FungiblePostConditionScheme> = { name: "generate_fungible_post_condition", description: "Generate a fungible token post-condition for SIP-010 tokens. Post-conditions are MANDATORY for all token transfers.", parameters: FungiblePostConditionScheme, execute: async (args, context) => { try { await recordTelemetry({ action: "generate_fungible_post_condition" }, context); return `# Fungible Token Post-Condition ## Configuration - **Principal**: ${args.principal} - **Condition**: ${args.conditionCode} - **Amount**: ${args.amount} base units - **Asset**: ${args.contractAddress}.${args.contractName}.${args.assetName} ## TypeScript Implementation \`\`\`typescript import { makeStandardFungiblePostCondition, FungibleConditionCode, createAssetInfo } from '@stacks/transactions'; const postCondition = makeStandardFungiblePostCondition( '${args.principal}', FungibleConditionCode.${args.conditionCode.charAt(0).toUpperCase() + args.conditionCode.slice(1).replace('_', '')}, ${args.amount}, createAssetInfo( '${args.contractAddress}', '${args.contractName}', '${args.assetName}' ) ); // Use in transaction const postConditions = [postCondition]; await openContractCall({ // ... other parameters postConditions, postConditionMode: PostConditionMode.Deny, // REQUIRED for security }); \`\`\` ## Clarity Contract Requirements For this post-condition to work, the contract must use native asset functions: \`\`\`clarity ;; REQUIRED: Native fungible token definition (define-fungible-token ${args.assetName}) ;; REQUIRED: Use ft-transfer? for transfers (define-public (transfer (amount uint) (sender principal) (recipient principal) (memo (optional (buff 34)))) (begin ;; ... validation logic ... (try! (ft-transfer? ${args.assetName} amount sender recipient)) ;; ... rest of function ... ) ) \`\`\` ## Security Notes - ✅ This post-condition guarantees ${args.conditionCode === 'equal' ? 'exactly' : args.conditionCode} ${args.amount} tokens will be involved - ✅ Transaction will fail if condition is not met - ✅ Protects against unexpected token movements - ⚠️ Always use PostConditionMode.Deny for maximum security`; } catch (error) { return `❌ Failed to generate fungible post-condition: ${error}`; } }, };
  • Zod schema defining the input parameters for the generate_fungible_post_condition tool: principal, conditionCode, amount, contractAddress, contractName, assetName.
    const FungiblePostConditionScheme = z.object({ principal: z.string().describe("The Stacks address for the post-condition"), conditionCode: FungibleConditionCodeScheme.describe("The condition type (usually 'equal' for exact transfers)"), amount: z.number().describe("The token amount in base units"), contractAddress: z.string().describe("The token contract address"), contractName: z.string().describe("The token contract name"), assetName: z.string().describe("The token asset name (usually same as contract name)"), });
  • Registration of the generateFungiblePostConditionTool in the MCP server via server.addTool call.
    server.addTool(generateFungiblePostConditionTool);
  • Import of the generateFungiblePostConditionTool from its implementation file.
    generateFungiblePostConditionTool, generateNonFungiblePostConditionTool, generateSTXPostConditionTool, analyzeTransactionPostConditionsTool, generatePostConditionTemplateTool } from "./stacks_blockchain/security/post_conditions.js";

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/exponentlabshq/stacks-clarity-mcp'

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