UNPKG

cotiv2-mcp

Version:

> A plug-and-play MCP tool server to **send COTI**, **transfer BEP-20 tokens**, **deploy tokens**, and **interact with smart contracts** on the **COTI v2 Network (COTI)** — built for **Claude Desktop**, **AI agents**, and **developers.**

55 lines (54 loc) 2.13 kB
import { z } from "zod"; import { parseUnits, getContract, publicActions } from "viem"; import { erc20abi } from "../lib/erc20Abi.js"; import { getAccount, walletClient } from "../config.js"; import { buildTxUrl, checkTransactionHash } from "../util.js"; export function registerTransferERC20Token(server) { server.tool("Send_ERC20_Token", "📤Send any ERC-20 token to another wallet (requires wallet check first)", { recipientAddress: z.string(), amount: z.string(), address: z.string(), }, async ({ recipientAddress, amount, address }) => { let txHash = undefined; try { // Get token details including address and decimals const account = await getAccount(); const client = walletClient(account).extend(publicActions); const contract = getContract({ address: address, abi: erc20abi, client, }); const decimals = await contract.read.decimals(); // Parse the amount based on token decimals const parsedAmount = parseUnits(amount, decimals); txHash = await contract.write.transfer([`0x${recipientAddress.replace("0x", "")}`, parsedAmount], { gas: BigInt(100000), }); const txUrl = await checkTransactionHash(txHash); return { content: [ { type: "text", text: `ERC-20 token transfer sent successfully. ${txUrl}`, url: txUrl, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); const txUrl = buildTxUrl(txHash); return { content: [ { type: "text", text: `transaction failed: ${errorMessage}`, url: txUrl, }, ], isError: true, }; } }); }