RPC Methods

Ethereum RPCs implemented in the imToken application.

Introduction

Here is the list of all Ethereum RPCs currently supported by the imToken App, for more information you can also refer to the Ethereum RPCs.

imToken's DApp browser no longer injects web3 into the DApp, we only inject the Provider.(you can get it using window.ethereum) For more information on how to start connecting to your wallet using Provider, please refer to:

// Modern application
window.web3 = new Web3(ethereum)

// Or with ethers
await window.ethereum.enable()
const provider = new ethers.providers.Web3Provider(window.ethereum)

Implemented RPCs

eth_requestAccounts

This method is specified by EIP-1102.

Requests that the user provides an Ethereum address to be identified by.

Returns

string[] - An array of a single, hexadecimal Ethereum address string.

eth_accounts

This method is specified by the Ethereum RPCs#eth_accounts.

eth_sendTransaction

This method is specified by the Ethereum RPCs#eth_sendtransaction.

personal_sign

alias: personal_sign , eth_signTypedData , eth_signTypedData_v3 eth_signTypedData_v4

Please refer to the metamask docs (a-brief-history) for the differences between the signature methods.

This method (personal_sign) is similar to eth_sign, but has better security, see Technical Reference for details.

This method is specified by the Ethereum RPCs#eth_sign.

net_version

This method is specified by the Ethereum RPCs#net_version.

eth_chainId

This method is specified by EIP-695

wallet_addEthereumChain

This method is specified by EIP-3085.

An API for adding Ethereum chains to wallet applications.

API wallet_addEthereumChain only works on versions higher than 2.8.4.

Returns

null - The method returns null if the request was successful, and an error otherwise.

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

This method is specified by EIP-3326.

An RPC method for switching the wallet’s active Ethereum chain.

API wallet_switchEthereumChain only works on versions higher than 2.10.0.

Returns

null - The method returns null if the request was successful, and an error otherwise.

Params

type EthereumChain = {
  chainId: string
}

Example

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

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

DEPRECATED

enable (DEPRECATED)

Use ethereum.request({ method: 'eth_requestAccounts' }) instead.

sendAsync (DEPRECATED)

Use ethereum.request() instead.

send (DEPRECATED)

Use ethereum.request() instead.

eth_sign

Use personal_sign instead.

Unimplemented

eth_subscribe

This RPC interface is not currently implemented in imToken.

Feedback and help

If you need to leave feedback or request help from the developers, please create a topic in the GitHub Discussion.

Last updated