Skip to Content
dApp 接入
本页目录

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 — 获取事件日志。
最后更新于