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.**

79 lines (78 loc) 2.67 kB
import { http, publicActions, createWalletClient, createPublicClient, } from "viem"; import { privateKeyToAccount } from "viem/accounts"; import { getPassword } from "./util.js"; import { decryptPrivateKey } from "./PrivateAES.js"; import { supportedChain } from "./chains/index.js"; import chalk from "chalk"; import { setupAccountFromPk } from "./lib/coti.js"; import { CotiNetwork } from "@coti-io/coti-ethers"; import { getStorage } from "./lib/storage.js"; // COTI Blue Color export const blue = chalk.hex("#3d95ce"); let savedPassword = null; export const getAccount = async () => { const storage = await getStorage(); const WALLET_PRIVATE_KEY = storage.WALLET_PRIVATE_KEY; if (!WALLET_PRIVATE_KEY) { throw new Error("WALLET_PRIVATE_KEY is not defined"); } if (savedPassword) { return privateKeyToAccount(savedPassword); } const { agreed, value: password } = await getPassword(); if (!password) { throw new Error("You did not enter a password."); } const pk = await decryptPrivateKey(WALLET_PRIVATE_KEY, password); if (agreed) { savedPassword = pk; setTimeout(() => { savedPassword = null; }, 1000 * 60 * 60); } return privateKeyToAccount(pk); }; export const getCotiAccount = async () => { const storage = await getStorage(); const WALLET_PRIVATE_KEY = storage.WALLET_PRIVATE_KEY; if (!WALLET_PRIVATE_KEY) { throw new Error("WALLET_PRIVATE_KEY is not defined"); } if (savedPassword) { return await setupAccountFromPk(savedPassword, supportedChain.name === "Testnet" ? CotiNetwork.Testnet : CotiNetwork.Mainnet); } const { agreed, value: password } = await getPassword(); if (!password) { throw new Error("You did not enter a password."); } const pk = await decryptPrivateKey(WALLET_PRIVATE_KEY, password); if (agreed) { savedPassword = pk; setTimeout(() => { savedPassword = null; }, 1000 * 60 * 60); } return setupAccountFromPk(pk, supportedChain.name === "Testnet" ? CotiNetwork.Testnet : CotiNetwork.Mainnet); }; export const getClient = async () => { const account = await getAccount(); const client = createWalletClient({ account, chain: supportedChain, transport: http(), }).extend(publicActions); return client; }; export const publicClient = createPublicClient({ chain: supportedChain, transport: http(), }); export const walletClient = (account) => createWalletClient({ chain: supportedChain, transport: http(), account: account, });