# JSON-RPC API

Pockie wraps the JSON-RPC API using the `window.pockie.request(args)` provider method.&#x20;

For detailed information on standard Ethereum RPC methods, refer to the [Ethereum Wiki](https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods). Every RPC method request can potentially return an error. Therefore, error handling is mandatory each time `window.pockie.request(args)` is called.

Example using the `eth_chainId RPC` method:

<pre class="language-javascript"><code class="lang-javascript">window.pockie.request({ method: 'eth_chainId' })
    .then((chainId) => {
        console.log('Response:', chainId);
    }).catch((error) => {
        if (error.code === 4001) {
            // EIP-1193 userRejectedRequest error
            console.log('Please connect to MetaMask.');
        } else {
<strong>            console.error(error);
</strong>        }
    });
</code></pre>

Use `window.pockie.request(args)` as per the guidance in the [Ethereum Wiki](https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods).

## Methods

### **wallet\_getPermissions**

Retrieves the current wallet's permission information from the requester.

<pre class="language-javascript"><code class="lang-javascript">window.pockie.request({ method: 'wallet_getPermissions' })
<strong>    .then((result) => {
</strong>        console.log('Response:', result);
    });
</code></pre>

This gives information about the permissions linked to DApps in the wallet. If the requester has no permissions, the result array will be empty.

### **wallet\_requestPermissions**

Requests permissions from the user. Currently, only `eth_accounts` requires permission requests. This request triggers a Pockie popup. Permission requests should only be made in response to a direct user action, like a button click.

<pre class="language-javascript"><code class="lang-javascript">window.pockie
    .request({
<strong>        method: 'wallet_requestPermissions',
</strong>        params: [{ eth_accounts: {} }],
    })
    .then((permissions) => {
<strong>        const accountsPermission = permissions.find(
</strong>            (permission) => permission.parentCapability === 'eth_accounts'
        );
        if (accountsPermission) {
            console.log('eth_accounts permission successfully requested!');
        }
    })
    .catch((error) => {
        if (error.code === 4001) {
            // EIP-1193 userRejectedRequest error
            console.log('Permissions needed to continue.');
        } else {
            console.error(error);
        }
    });
</code></pre>

### **wallet\_switchEthereumChain**

Prompts the user to switch to the chain with the specified chain ID. This method should only be invoked in response to a direct user action. Pockie will reject requests if:

* The chain ID is incorrect.
* Pockie does not support chains with the specified chain ID.

This method is defined by EIP-3326.

```javascript
await pockie.request({
    method: 'wallet_switchEthereumChain',
    params: [{ chainId: '0x5' }],
});
```

### **wallet\_watchAsset**

Requests the user to track a specified token in Pockie.&#x20;

This allows DApp developers to request the user to track tokens in their wallet at runtime. This method is specified by EIP-747.

<pre class="language-javascript"><code class="lang-javascript">pockie
    .request({
<strong>        method: 'wallet_watchAsset',
</strong>        params: {
            type: 'ERC20',
            options: {
                address: '0xb60e8dd61c5d32be8058bb8eb970870f07233155',
                symbol: 'FOO',
                decimals: 18,
                image: 'https://foo.io/token-image.svg',
<strong>            },
</strong>        },
<strong>    })
</strong>    .then((success) => {
        if (success) {
            console.log('FOO successfully added to wallet!');
        } else {
            throw new Error('Something went wrong.');
        }
    })
    .catch(console.error);
</code></pre>

## Methods Not Supported

* wallet\_addEthereumChain
* wallet\_registerOnboarding
* wallet\_scanQRCode

The above RPC Methods are currently not supported. For more details about Ethereum JSON-RPC, refer to the [MetaMask API](https://docs.metamask.io/wallet/reference/json-rpc-api/) documentation.

<br>
