Web3 链上操作技能
该技能允许 OpenClaw AI 代理直接使用本地 Node.js CLI 实用程序与 EVM 区块链(Ethereum、Arbitrum、Base、Optimism、Polygon、BNB Chain、Sonic、Sepolia 等)交互。
全局选项
这些标志可以追加到任何命令:
--json:静默人类日志并输出严格的 JSON 到 stdout(强烈推荐用于 AI 代理解析)。
--rpc :用自定义 RPC 端点覆盖默认节点 RPC(对于测试网或私有节点很有用)。
--simulate:模拟事务(干跑)使用气体估算和调用模拟。防止发送失败的事务并计算气体费用。
CLI 命令和参数
所有命令都在技能目录中使用 Node.js 运行:
node skills/web3-ops/index.js [arguments]
获取您的配置钱包地址。
使用方法:node skills/web3-ops/index.js address [--json]
检查本土币(ETH、MATIC、BNB、S)或特定 ERC-20 代币余额,使用符号或合约地址。
本土币:node skills/web3-ops/index.js balance --chain [--json]
ERC-20 代币:node skills/web3-ops/index.js balance --chain --token [--json]
示例:node skills/web3-ops/index.js balance --chain base --token AERO
扫描和列出您钱包中所有具有正余额的代币。如果未指定链,则将扫描所有支持的网络。
自动检测“degen/micin”代币,使用区块浏览器事务历史。
使用方法(所有链):node skills/web3-ops/index.js portfolio [--json]
使用方法(单链):node skills/web3-ops/index.js portfolio --chain [--json]
发送本土币或 ERC-20 代币到另一个地址。
本土币:node skills/web3-ops/index.js transfer --chain --to --amount [--json] [--simulate]
ERC-20 代币:node skills/web3-ops/index.js transfer --chain --to --amount --token [--json] [--simulate]
在同一区块链网络上互换代币。支持自动路由和手动路由器。
自动模式(Li.Fi 聚合器):node skills/web3-ops/index.js swap --chain --fromToken --toToken --amount --mode auto [--json] [--simulate]
手动模式(Uniswap/PancakeSwap/Relay/Li.Fi):node skills/web3-ops/index.js swap --chain --fromToken --toToken --amount --mode manual --provider [--json] [--simulate]
滑点容忍度:添加 --slippage (默认为 0.5)
桥接和互换资产从一个区块链到另一个区块链。
自动模式(Li.Fi 聚合器):node skills/web3-ops/index.js bridge --fromChain --toChain --fromToken --toToken --amount --mode auto [--json] [--simulate]
手动模式(Relay/Li.Fi):node skills/web3-ops/index.js bridge --fromChain --toChain --fromToken --toToken --amount --mode manual --provider [--json] [--simulate]
铸造或认领 NFT 在智能合约上。
使用方法:node skills/web3-ops/index.js mint --chain --contract --function --args --value [--json] [--simulate]
示例:node skills/web3-ops/index.js mint --chain base --contract 0x123... --function "mint(uint256)" --args "[1]"
广播具有十六进制数据有效载荷的自定义原始事务。
使用方法:node skills/web3-ops/index.js custom --chain --to --data --value [--json] [--simulate]
代理行为和 Telegram 提示指南
与用户交互有关区块链事务:
将意图转换为 CLI:将用户的自然语言请求(例如“检查我的 Base 投资组合”、“在 Base 上将 10 USDC 交换为 ETH”、“将 0.01 Sepolia ETH 发送到 0x...”)转换为相应的 CLI 命令。始终追加 --json 以进行程序化解析。
使用模拟模式:如果用户不确定,询问“此事务是否有效?”或正在进行高价值转账,建议先使用 --simulate 模拟。
显示可复制地址(CAs):在打印代币余额、投资组合或事务确认时,将所有合约地址(CA)格式化为 Telegram 单字体代码块(例如
0x940181a94A35A4569E4529A3CDfB74e38FD98631),以便用户可以点击复制。
支持测试网和自定义 RPC:如果用户指定测试网(例如 Sepolia)或请求私有 RPC,请将 --rpc 标志追加到命令中。
浏览器链接:始终从输出 JSON 中提取浏览器链接并将其呈现给用户,以便他们可以跟踪区块确认状态。