UNPKG

@sei-js/mcp-server

Version:

Model Context Protocol (MCP) server for interacting with EVM-compatible networks

121 lines (120 loc) 3.1 kB
import { formatUnits, getContract } from 'viem'; import { getPublicClient } from './clients.js'; // Standard ERC20 ABI (minimal for reading) const erc20Abi = [ { inputs: [], name: 'name', outputs: [{ type: 'string' }], stateMutability: 'view', type: 'function' }, { inputs: [], name: 'symbol', outputs: [{ type: 'string' }], stateMutability: 'view', type: 'function' }, { inputs: [], name: 'decimals', outputs: [{ type: 'uint8' }], stateMutability: 'view', type: 'function' }, { inputs: [], name: 'totalSupply', outputs: [{ type: 'uint256' }], stateMutability: 'view', type: 'function' } ]; // Standard ERC721 ABI (minimal for reading) const erc721Abi = [ { inputs: [], name: 'name', outputs: [{ type: 'string' }], stateMutability: 'view', type: 'function' }, { inputs: [], name: 'symbol', outputs: [{ type: 'string' }], stateMutability: 'view', type: 'function' }, { inputs: [{ type: 'uint256', name: 'tokenId' }], name: 'tokenURI', outputs: [{ type: 'string' }], stateMutability: 'view', type: 'function' } ]; // Standard ERC1155 ABI (minimal for reading) const erc1155Abi = [ { inputs: [{ type: 'uint256', name: 'id' }], name: 'uri', outputs: [{ type: 'string' }], stateMutability: 'view', type: 'function' } ]; /** * Get ERC20 token information */ export async function getERC20TokenInfo(tokenAddress, network = 'sei') { const publicClient = getPublicClient(network); const contract = getContract({ address: tokenAddress, abi: erc20Abi, client: publicClient }); const [name, symbol, decimals, totalSupply] = await Promise.all([ contract.read.name(), contract.read.symbol(), contract.read.decimals(), contract.read.totalSupply() ]); return { name, symbol, decimals, totalSupply, formattedTotalSupply: formatUnits(totalSupply, decimals) }; } /** * Get ERC721 token metadata */ export async function getERC721TokenMetadata(tokenAddress, tokenId, network = 'sei') { const publicClient = getPublicClient(network); const contract = getContract({ address: tokenAddress, abi: erc721Abi, client: publicClient }); const [name, symbol, tokenURI] = await Promise.all([contract.read.name(), contract.read.symbol(), contract.read.tokenURI([tokenId])]); return { name, symbol, tokenURI }; } /** * Get ERC1155 token URI */ export async function getERC1155TokenURI(tokenAddress, tokenId, network = 'sei') { const publicClient = getPublicClient(network); const contract = getContract({ address: tokenAddress, abi: erc1155Abi, client: publicClient }); return contract.read.uri([tokenId]); }