RPC Methods
Ethereum RPCs implemented in the imToken application.
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:- Or refer to the following simplified code:
// Modern application
window.web3 = new Web3(ethereum)
// Or with ethers
await window.ethereum.enable()
const provider = new ethers.providers.Web3Provider(window.ethereum)
Requests that the user provides an Ethereum address to be identified by.
Returns
string[]
- An array of a single, hexadecimal Ethereum address string.
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.
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],
})
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],
Use
ethereum.request({ method: 'eth_requestAccounts' })
instead.Use
ethereum.request()
instead.Use
ethereum.request()
instead.Use
personal_sign
instead.This RPC interface is not currently implemented in imToken.
If you need to leave feedback or request help from the developers, please create a topic in the GitHub Discussion.
Last modified 1yr ago