# RPC Methods

## 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](https://eth.wiki/json-rpc/API#json-rpc-methods).

imToken's DApp browser [no longer injects `web3` into the DApp](/developers/products/webview/release-changes.md#no-longer-injecting-web-3-js), 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:

* Our [Guide documentation](/developers/products/webview/development-guide-for-imtoken-dapp.md)
* MetaMask documentation: [Ethereum Provider](https://docs.metamask.io/guide/ethereum-provider.html)
* [EIP-1193: Ethereum Provider JavaScript API](https://eips.ethereum.org/EIPS/eip-1193)
* Or refer to the following  simplified code:&#x20;

```javascript
// 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](https://eips.ethereum.org/EIPS/eip-1102).&#x20;

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](https://eth.wiki/json-rpc/API#eth_accounts).

#### eth\_sendTransaction

> This method is specified by [the Ethereum RPCs#eth\_sendtransaction](https://eth.wiki/json-rpc/API#eth_sendtransaction).

#### personal\_sign

**alias:** `personal_sign` , `eth_signTypedData` , `eth_signTypedData_v3` `eth_signTypedData_v4`

Please refer to the [metamask docs (a-brief-history)](https://docs.metamask.io/guide/signing-data.html#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](https://github.com/ethereum/go-ethereum/pull/2940) for details.

> This method is specified by [the Ethereum RPCs#eth\_sign](https://eth.wiki/json-rpc/API#eth_sign).

#### net\_version

> This method is specified by [the Ethereum RPCs#net\_version](https://eth.wiki/json-rpc/API#net_version).

#### eth\_chainId

> This method is specified by [EIP-695](https://eips.ethereum.org/EIPS/eip-695)

#### wallet\_addEthereumChain

> This method is specified by [EIP-3085](https://eips.ethereum.org/EIPS/eip-3085).

An API for adding Ethereum chains to wallet applications.

{% hint style="warning" %}
API `wallet_addEthereumChain` only works on versions higher than `2.8.4`.
{% endhint %}

**Returns**

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

**Params**

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

**Example**

```typescript
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](https://eips.ethereum.org/EIPS/eip-3326).

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

{% hint style="warning" %}
API `wallet_switchEthereumChain` only works on versions higher than `2.10.0`.
{% endhint %}

**Returns**

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

**Params**

```typescript
type EthereumChain = {
  chainId: string
}
```

**Example**

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

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

```

### DEPRECATED

#### enable (DEPRECATED) <a href="#ethereum-enable-deprecated" id="ethereum-enable-deprecated"></a>

{% hint style="warning" %}
Use `ethereum.request({ method: 'eth_requestAccounts' })` instead.
{% endhint %}

#### sendAsync (DEPRECATED) <a href="#ethereum-sendasync-deprecated" id="ethereum-sendasync-deprecated"></a>

{% hint style="warning" %}
Use `ethereum.request()` instead.
{% endhint %}

#### send (DEPRECATED) <a href="#ethereum-sendasync-deprecated" id="ethereum-sendasync-deprecated"></a>

{% hint style="warning" %}
Use `ethereum.request()` instead.
{% endhint %}

#### eth\_sign

{% hint style="warning" %}
Use `personal_sign` instead.
{% endhint %}

### Unimplemented

#### eth\_subscribe

This RPC interface is not currently implemented in imToken.&#x20;

## Feedback and help

If you need to leave feedback or request help from the developers, please create a topic in the [GitHub Discussion](https://github.com/consenlabs/webview/discussions/new).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://imtoken.gitbook.io/developers/products/webview/rpcs.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
