本页目录
JSON-RPC 参考
OneKey 常用 Ethereum JSON-RPC 和钱包方法参考。
所有方法均通过 window.$onekey.ethereum.request({ method, params }) 调用。
账户方法
| 方法 | 说明 |
|---|---|
| eth_requestAccounts | 请求访问用户账户,可触发连接弹窗 |
| eth_accounts | 获取已连接账户,不弹窗 |
| wallet_requestPermissions | 请求指定权限 |
| wallet_getPermissions | 获取当前权限 |
交易方法
| 方法 | 说明 |
|---|---|
| eth_sendTransaction | 发送交易 |
| eth_call | 执行调用,不创建交易 |
| eth_estimateGas | 估算交易 gas |
| eth_getTransactionByHash | 按哈希获取交易 |
| eth_getTransactionReceipt | 获取交易回执 |
签名方法
| 方法 | 说明 |
|---|---|
| personal_sign | 签署消息(EIP-191) |
| eth_signTypedData_v4 | 签署结构化数据(EIP-712) |
网络方法
| 方法 | 说明 |
|---|---|
| eth_chainId | 获取当前 Chain ID |
| wallet_switchEthereumChain | 切换链 |
| wallet_addEthereumChain | 添加链 |
| wallet_watchAsset | 将代币添加到钱包 |
标准 Ethereum 方法
其他 Ethereum JSON-RPC 方法是否可用,取决于连接的网络和钱包实现。完整列表见 Ethereum JSON-RPC 规范 。
常用方法包括:
eth_blockNumber— 获取当前区块号。eth_getBalance— 获取账户余额。eth_getCode— 获取合约代码。eth_getLogs— 获取事件日志。
最后更新于