运行时依赖
安装命令
点击复制技能文档
Ethereum JSON-RPC 技能 使用此技能通过 uxc + JSON-RPC 运行以太坊执行 JSON-RPC 操作。重用 uxc 技能以共享执行、身份验证和错误处理指南。
前提条件
- uxc 已安装并在 PATH 中可用。
- 兼容的以太坊执行 JSON-RPC 提供者的网络访问。
- 官方执行 OpenRPC 模式 URL 的访问权限:https://raw.githubusercontent.com/ethereum/execution-apis/assembled-spec/refs-openrpc.json
范围 此技能涵盖安全的只读以太坊执行表面:
- 链标识和公共状态读取
- 块、余额、日志和基于调用状态的读取
- eth_subscribe 的 pubsub 订阅,用于新头、日志和待处理事务
- eth_sendRawTransaction
- personal_、admin_、debug_、engine_、txpool_*
- 钱包签名流程
- 具有自定义身份验证模型的私人/身份验证 RPC 提供者
端点和模式 此技能默认为公共读取提供者: HTTPS RPC:https://ethereum-rpc.publicnode.com 操作表面来自官方以太坊执行 OpenRPC 模式:https://raw.githubusercontent.com/ethereum/execution-apis/assembled-spec/refs-openrpc.json uxc JSON-RPC 发现通常依赖于 OpenRPC 或 rpc.discover。以太坊 RPC 提供者通常不直接公开发现,因此此技能使用固定 --schema-url 链接和请求流程。 官方执行 OpenRPC 文档对于正常的请求/响应方法足够强大,但它目前不公开 pubsub 方法,例如 eth_subscribe。使用基于模式的链接进行读取,并直接使用 uxc subscribe start 进行订阅。 对于订阅,请使用已验证实际接受 eth_subscribe 的 WebSocket 以太坊 RPC 提供者。不要假设公共 HTTPS 主机自动保证相同的 wss:// 主机对于 pubsub 是稳定的。
身份验证 此技能使用的默认公共读取提供者不需要身份验证。如果用户稍后将同一工作流指向私有以太坊 RPC 提供者,请在未经修改地重用此技能之前先验证其身份验证模型。
核心工作流 使用固定链接命令默认: command -v ethereum-jsonrpc-cli 如果缺失,请创建: uxc link ethereum-jsonrpc-cli https://ethereum-rpc.publicnode.com --schema-url https://raw.githubusercontent.com/ethereum/execution-apis/assembled-spec/refs-openrpc.json ethereum-jsonrpc-cli -h 首先检查操作模式: ethereum-jsonrpc-cli eth_blockNumber -h ethereum-jsonrpc-cli eth_getBlockByNumber -h ethereum-jsonrpc-cli eth_getBalance -h 更喜欢链和余额/块读取,而不是更深的状态查询: ethereum-jsonrpc-cli eth_chainId ethereum-jsonrpc-cli eth_blockNumber ethereum-jsonrpc-cli eth_getBalance Address=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 Block=latest 使用键值或位置 JSON 执行: 键值:ethereum-jsonrpc-cli eth_getBalance Address=0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045 Block=latest 位置 JSON:ethereum-jsonrpc-cli eth_getBlockByNumber '["latest", false]' 嵌套位置 JSON:ethereum-jsonrpc-cli eth_call '[{"to":"0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","data":"0x313ce567"},"latest"]' 直接使用 uxc subscribe start 进行 pubsub 流: uxc subscribe start wss:// eth_subscribe '{"params":["newHeads"]}' --sink file:$HOME/.uxc/subscriptions/eth-new-heads.ndjson uxc subscribe start wss:// eth_subscribe '{"params":["logs",{"address":"0xA0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"}]}' --sink file:$HOME/.uxc/subscriptions/eth-logs.ndjson uxc subscribe status uxc subscribe stop
推荐的读取操作 net_version eth_chainId eth_blockNumber eth_getBlockByNumber eth_getBalance eth_getLogs eth_call
推荐的订阅操作 eth_subscribe 订阅参数[0] 模式通常最有用: newHeads logs newPendingTransactions
防护栏 将自动化保持在 JSON 输出封套上;不要使用 --text。 首先解析稳定字段:ok、kind、protocol、data、error。 默认情况下保持只读方法和 eth_subscribe。 官方执行 OpenRPC 模式驱动读取帮助和请求执行,但它不涵盖 eth_subscribe;将订阅视为运行时流程,而不是模式发现的操作。 不要在未经明确后续设计和审查的情况下通过此技能调用写入/管理/调试/引擎方法。 对于 pubsub 方法,请使用 uxc subscribe start;固定 ethereum-jsonrpc-cli 链接用于正常的请求/响应方法。 订阅作业应始终写入 sink 文件,以便可以安全地检查和重放事件。 在记录或自动化公共以太坊 pubsub 主机之前,请确认特定的提供者实际上公开了 WebSocket JSON-RPC 订阅;公共 HTTPS 端点不保证匹配的 wss:// 端点。
ethereum-jsonrpc-cli ... 等同于 uxc https://ethereum-rpc.publicnode.com --schema-url ...。