MCP Ethers Wallet

MCP Ethers Wallet

site icon
2025.03.24 0
TypeScript以太坊钱包区块链服务金融服务
MCP Ethers Wallet 是一个基于 Model Context Protocol (MCP) 的服务,提供以太坊钱包功能,使用 ethers.js v6 实现。它主要为 LLM 应用程序提供以太坊相关的功能,包括网络信息管理、钱包创建与管理、交易创建与发送、合约交互、ENS 解析、单位转换、Gas 估算和交易历史等。该服务兼容任何 MCP 客户端,如 Claude Desktop。
View on GitHub

Overview

基本能力

产品定位

MCP Ethers Wallet 是一个以太坊钱包服务,为 LLM 应用程序提供以太坊区块链相关的功能。

核心功能

  • 网络信息和管理
  • 钱包创建和管理
  • 交易创建和发送
  • 合约交互(ERC20、ERC721、ERC1155)
  • ENS 解析
  • 单位转换
  • Gas 估算
  • 交易历史

适用场景

  • 在 LLM 应用程序中集成以太坊钱包功能
  • 开发需要区块链交互的自动化工具
  • 测试和调试以太坊相关功能

工具列表

Core Network Tools

  • getSupportedNetworks: 获取支持的网络列表及其配置
  • getBlockNumber: 获取当前区块号
  • getBlockDetails: 获取区块详情
  • getTransactionDetails: 获取交易详情
  • getGasPrice: 获取当前 Gas 价格
  • getFeeData: 获取当前网络费用数据

Wallet Tools

  • generateWallet: 生成新的以太坊钱包
  • loadWallet: 从私钥加载现有钱包
  • checkWalletExists: 检查钱包是否已配置
  • getWalletBalance: 获取钱包的 ETH 余额
  • getWalletTransactionCount: 获取地址发送的交易数量
  • signMessage: 用加载的钱包签名消息
  • ethSign: 使用 Ethereum eth_sign 方法签名数据(传统方法)

Contract Tools

  • getContractCode: 获取合约的字节码
  • callContractMethod: 调用合约的只读方法
  • estimateGas: 估算交易的 Gas

ENS Tools

  • lookupAddress: 获取地址的 ENS 名称
  • resolveName: 获取 ENS 名称的地址

Unit Conversion Tools

  • formatEther: 将 wei 值转换为 ether 的十进制字符串
  • parseEther: 将 ether 值转换为 wei
  • formatUnits: 将值转换为指定单位的十进制字符串

ERC20 Tools

  • erc20GetTokenInfo: 获取代币基本信息(名称、符号、小数位)
  • erc20GetBalance: 获取地址的代币余额
  • erc20Transfer: 在账户之间转移代币
  • erc20GetAllowance: 获取代币批准额度
  • erc20Approve: 批准代币供其他地址使用

ERC721 Tools

  • erc721GetTokenInfo: 获取 NFT 集合的基本信息
  • erc721GetBalance: 获取地址的 NFT 余额
  • erc721OwnerOf: 获取特定 NFT 的所有者
  • erc721GetTokenURI: 获取 NFT 的 token URI 元数据
  • erc721Transfer: 将 NFT 转移到另一个地址
  • erc721SafeTransfer: 安全地将 NFT 转移到另一个地址

ERC1155 Tools

  • erc1155GetTokenInfo: 获取多代币的基本信息
  • erc1155GetBalance: 获取地址和代币 ID 的代币余额
  • erc1155GetBatchBalance: 在单个调用中获取多个代币余额
  • erc1155GetURI: 获取代币的元数据 URI
  • erc1155SafeTransfer: 安全地将代币转移到另一个地址
  • erc1155SafeBatchTransfer: 在单个调用中安全地转移多个代币

常见问题解答

  • Private Keys: 服务器可以在内存中存储私钥。在使用钱包操作中的 saveToEnv 选项时要小心。
  • API Keys: Alchemy 和 Infura API 密钥用于连接以太坊网络。切勿暴露 .env 文件。
  • Eth Sign: ethSign 方法可以签名类似交易的数据,安全性不如 signMessage。使用时需谨慎。

使用教程

使用依赖

# Clone the repository
git clone https://github.com/yourusername/ethers-server.git
cd ethers-server

# Install dependencies
npm install

# Build the TypeScript code
npm run build

安装教程

# Using Node.js
npm start

# Using Bun (recommended for faster performance)
bun start

调试方式

# Install MCP Inspector globally
npm install -g @modelcontextprotocol/inspector

# Run it with your server
mcp-inspector --command "node build/src/mcpServer.js"

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。