imToken For Developers
中文
中文
  • 介绍
  • 产品
    • WebView
      • imToken DApp 开发指引
      • RPC Methods
      • Bitcoin
      • SDK APIs
      • 预加载配置
      • 兼容性说明
      • 版本说明
    • Universal Links
    • Deep Linking
  • 参考
    • dapp-sdk
    • tokenlon-onboarding
    • tokenlon-mmsk
    • tokenlon-mmproxy
    • tokenlon-jssdk
    • tokenlon-open-api
Powered by GitBook
On this page
  • 介绍
  • 已实现的 RPC
  • 已废弃
  • 未实现
  • 反馈与帮助

Was this helpful?

  1. 产品
  2. WebView

RPC Methods

imToken 应用内的 Ethereum RPCs 实现说明。

PreviousimToken DApp 开发指引NextBitcoin

Last updated 3 years ago

Was this helpful?

介绍

这是 imToken 应用当前支持的所有 Ethereum RPC 列表,你也可以在 内查看更多信息。

imToken 应用的 WebView (DApp 浏览器) ,我们只提供基础的 Provider 以供连接。关于如何使用 Provider 将应用连接到 imToken,请参考如下:

  • imToken 的

  • MetaMask 官方文档:

  • 或是参考下述的简单示例代码:

// 现代应用推荐方式
window.web3 = new Web3(ethereum)

// 或是使用 ethers
await window.ethereum.enable()
const provider = new ethers.providers.Web3Provider(window.ethereum)

已实现的 RPC

eth_requestAccounts

此方法来源于 。

请求用户提供一个以太坊地址。

Returns

string[] - 一个单一的、十六进制的以太坊地址字符串的数组。

eth_accounts

eth_sendTransaction

personal_sign

别名: personal_sign , eth_signTypedData , eth_signTypedData_v3 eth_signTypedData_v4

net_version

eth_chainId

wallet_addEthereumChain

用于将以太坊链添加到钱包应用程序的 API。

API wallet_addEthereumChain 仅在高于 2.8.4 版本的 imToken 应用内工作。

Returns

null - 如果请求成功,该方法返回 null,否则返回错误。

Params

type EthereumChain = {
  chainId: string
  chainName: string
  nativeCurrency: {
    name: string
    symbol: string // 2-6 characters long
    decimals: number // 18
  };
  rpcUrls: string[]
  blockExplorerUrls?: string[]
}

Example

const chain = {
  chainId: "0x64",
  chainName: "xDAI Chain",
  rpcUrls: ["https://dai.poa.network"],
  iconUrls: [
    "https://xdaichain.com/fake/example/url/xdai.svg",
    "https://xdaichain.com/fake/example/url/xdai.png",
  ],
  nativeCurrency: {
    name: "xDAI",
    symbol: "xDAI",
    decimals: 18,
  },
}

window.ethereum.request({
  method: "wallet_addEthereumChain",
  params: [chain],
})

wallet_switchEthereumChain

用于切换当前以太坊网络的 API。

API wallet_switchEthereumChain 仅在高于 2.9.10 版本的 imToken 应用内工作。

Returns

null - 如果请求成功,该方法返回 null,否则返回错误。

Params

type EthereumChain = {
  chainId: string
}

Example

const chain = {
  chainId: "0x64",
}

window.ethereum.request({
  method: "wallet_switchEthereumChain",
  params: [chain],
})

已废弃

enable (废弃的)

使用 ethereum.request({ method: 'eth_requestAccounts' }) 代替。

sendAsync (废弃的)

使用 ethereum.request() 代替。

send (废弃的)

使用 ethereum.request() 代替。

eth_sign (废弃的)

使用 personal_sign 代替。

未实现

eth_subscribe

此 RPC 接口当前未在 imToken 应用内实现。

反馈与帮助

此方法来源于 。

此方法来源于 。

对于多种不同的鉴权方式之间的区别和历史原因,请参考 文档的解释说明。

此方法 (personal_sign) 近似于 eth_sign,但更安全,可以在 中查看详细信息。

此方法来源于 。

此方法来源于 。

此方法来源 。

此方法来源于 。

此方法来源于 。

如果你需要请求开发者帮助或反馈问题,请在 中创建一个主题。

the Ethereum RPCs#eth_accounts
the Ethereum RPCs#eth_sendtransaction
metamask docs (a-brief-history)
技术参考
the Ethereum RPCs#eth_sign
the Ethereum RPCs#net_version
EIP-695
EIP-3085
EIP-3326
GitHub Discussion
Ethereum RPC 官方文档
新手指引文档
Ethereum Provider
EIP-1193 定义的 API 说明
EIP-1102
不会注入 web3.js