uniderp-mcp
Version:
> A plug-and-play MCP tool server to **send ETH**, **transfer ERC-20 tokens**, **deploy tokens**, and **interact with smart contracts** on the **UNICHAIN** — built for **Claude Desktop**, **AI agents**, and **developers.**
52 lines (51 loc) • 1.73 kB
JavaScript
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 { getStorage } from "./lib/storage.js";
// UNICHAIN Pink Color
export const pink = chalk.hex("#f60fb5");
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) {
const pk = await decryptPrivateKey(WALLET_PRIVATE_KEY, savedPassword);
return privateKeyToAccount(pk);
}
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 = password;
setTimeout(() => {
savedPassword = null;
}, 1000 * 60 * 60);
}
return privateKeyToAccount(pk);
};
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,
});