Skip to main content
Glama
Zetrix-Chain

Zetrix MCP Server

Official
by Zetrix-Chain

zetrix_sdk_invoke_contract

Execute smart contract functions on the Zetrix blockchain by submitting transactions that modify contract state, requiring authentication with a private key.

Instructions

Invoke a smart contract function with state change (requires private key)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sourceAddressYesThe account address initiating the transaction
privateKeyYesPrivate key for signing the transaction
contractAddressYesThe smart contract address to invoke
amountYesAmount of ZTX to send with invocation (in micro-ZTX)
inputYesJSON string with method and params
metadataNoOptional transaction description

Implementation Reference

  • MCP server handler for the tool: parses arguments and delegates to ZetrixSDK.invokeContract
    case "zetrix_sdk_invoke_contract": {
      if (!args) {
        throw new Error("Missing arguments");
      }
      const result = await zetrixSDK.invokeContract({
        sourceAddress: args.sourceAddress as string,
        privateKey: args.privateKey as string,
        contractAddress: args.contractAddress as string,
        amount: args.amount as string,
        input: args.input as string,
        metadata: args.metadata as string | undefined,
      });
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Input schema definition for the tool validation
    {
      name: "zetrix_sdk_invoke_contract",
      description: "Invoke a smart contract function with state change (requires private key)",
      inputSchema: {
        type: "object",
        properties: {
          sourceAddress: {
            type: "string",
            description: "The account address initiating the transaction",
          },
          privateKey: {
            type: "string",
            description: "Private key for signing the transaction",
          },
          contractAddress: {
            type: "string",
            description: "The smart contract address to invoke",
          },
          amount: {
            type: "string",
            description: "Amount of ZTX to send with invocation (in micro-ZTX)",
          },
          input: {
            type: "string",
            description: "JSON string with method and params",
          },
          metadata: {
            type: "string",
            description: "Optional transaction description",
          },
        },
        required: ["sourceAddress", "privateKey", "contractAddress", "amount", "input"],
      },
    },
  • src/index.ts:492-525 (registration)
    Tool object registration in the tools array used by ListToolsRequestHandler
    {
      name: "zetrix_sdk_invoke_contract",
      description: "Invoke a smart contract function with state change (requires private key)",
      inputSchema: {
        type: "object",
        properties: {
          sourceAddress: {
            type: "string",
            description: "The account address initiating the transaction",
          },
          privateKey: {
            type: "string",
            description: "Private key for signing the transaction",
          },
          contractAddress: {
            type: "string",
            description: "The smart contract address to invoke",
          },
          amount: {
            type: "string",
            description: "Amount of ZTX to send with invocation (in micro-ZTX)",
          },
          input: {
            type: "string",
            description: "JSON string with method and params",
          },
          metadata: {
            type: "string",
            description: "Optional transaction description",
          },
        },
        required: ["sourceAddress", "privateKey", "contractAddress", "amount", "input"],
      },
    },
  • Main helper function implementing the contract invocation logic using official Zetrix SDK: creates operation, evaluates fees, builds/signs/submits transaction.
    /**
     * Invoke a smart contract (with state change and gas payment)
     */
    async invokeContract(params: ZetrixContractInvokeParams): Promise<any> {
      await this.initSDK();
    
      try {
        // Create contract invoke operation
        const operation = this.sdk.operation.contractInvokeByGasOperation({
          contractAddress: params.contractAddress,
          amount: params.amount,
          input: params.input,
          metadata: params.metadata,
        });
    
        if (operation.errorCode !== 0) {
          throw new Error(
            operation.errorDesc || `SDK Error: ${operation.errorCode}`
          );
        }
    
        // Build and sign transaction
        const feeData = await this.sdk.transaction.evaluateFee({
          sourceAddress: params.sourceAddress,
          nonce: "auto", // SDK will fetch nonce automatically
          operations: [operation.result.operation],
          signtureNumber: "1",
          metadata: params.metadata,
        });
    
        if (feeData.errorCode !== 0) {
          throw new Error(
            feeData.errorDesc || `SDK Error: ${feeData.errorCode}`
          );
        }
    
        // Submit transaction
        const txParams = {
          sourceAddress: params.sourceAddress,
          nonce: feeData.result.nonce,
          operations: [operation.result.operation],
          gasPrice: feeData.result.gasPrice,
          feeLimit: feeData.result.feeLimit,
          metadata: params.metadata,
        };
    
        const blob = await this.sdk.transaction.buildBlob(txParams);
    
        if (blob.errorCode !== 0) {
          throw new Error(blob.errorDesc || `SDK Error: ${blob.errorCode}`);
        }
    
        // Sign the transaction
        const signature = this.sdk.transaction.sign({
          privateKeys: [params.privateKey],
          blob: blob.result.transactionBlob,
        });
    
        if (signature.errorCode !== 0) {
          throw new Error(
            signature.errorDesc || `SDK Error: ${signature.errorCode}`
          );
        }
    
        // Submit to blockchain
        const submitResult = await this.sdk.transaction.submit({
          blob: blob.result.transactionBlob,
          signature: signature.result.signatures,
        });
    
        if (submitResult.errorCode !== 0) {
          throw new Error(
            submitResult.errorDesc || `SDK Error: ${submitResult.errorCode}`
          );
        }
    
        return submitResult.result;
      } catch (error) {
        throw new Error(
          `Failed to invoke contract: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'state change' (indicating mutation) and 'requires private key' (implying authentication), but fails to detail critical aspects like transaction costs, irreversible effects, rate limits, error handling, or response format. For a mutation tool with zero annotation coverage, this is insufficient.

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 a single, efficient sentence that front-loads key information ('invoke a smart contract function with state change') and adds necessary constraint ('requires private key'). There is no wasted verbiage, making it appropriately concise and well-structured.

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

Completeness2/5

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

Given the tool's complexity (state-changing contract invocation), lack of annotations, and absence of an output schema, the description is incomplete. It omits details on transaction outcomes, error scenarios, security implications, and how results are returned. For a high-stakes mutation tool, this leaves significant gaps in understanding.

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?

Schema description coverage is 100%, providing clear documentation for all 6 parameters. The description adds minimal value beyond the schema, only implying that 'privateKey' is required for signing. No additional syntax, format details, or contextual meaning are provided, so the baseline score of 3 is appropriate.

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

Purpose4/5

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

The description clearly states the action ('invoke a smart contract function with state change') and resource ('smart contract'), making the purpose evident. It distinguishes from sibling 'zetrix_call_contract' by specifying 'state change', but could be more explicit about the difference. The description is not tautological and provides meaningful context.

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

Usage Guidelines3/5

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

The description implies usage context by mentioning 'requires private key', which suggests authentication needs. However, it lacks explicit guidance on when to use this tool versus alternatives like 'zetrix_sdk_call_contract' or 'zetrix_call_contract', nor does it specify prerequisites or exclusions beyond the private key requirement.

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/Zetrix-Chain/zetrix-mcp-server'

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