# JSON-RPC API

포키는 `window.pockie.request(args)` provider method를 사용하여 JSON-RPC API를 래핑합니다.

표준 Ethereum RPC 메서드에 대한 자세한 내용은[ Ethereum Wiki](https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods)를 참고해주세요.

모든 RPC 메서드 요청은 오류를 반환할 수 있습니다. `window.pockie.request(args)`를 호출할 때마다 오류 처리를 반드시 해야 합니다.

아래는 RPC 메서드 중 `eth_chainId` 로 호출하는 예제입니다.

<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>

[Ethereum Wiki](https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods)를 참조하여 `window.pockie.request(args)` 를 사용해주세요.

## Methods

### **wallet\_getPermissions**

요청자에게 현재 지갑의 권한 정보들을 가져옵니다.

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

지갑의 디앱 연결된 권한의 정보를 가져옵니다. 요청자가 권한을 가지고 있지 않은 경우, 결과의 배열은 비어 있습니다.

### **wallet\_requestPermissions**

사용자로부터 권한을 요청합니다. 현재 `eth_accounts` 만 권한 요청이 필요합니다.

이 요청은 포키 팝업을 트리거합니다. 권한을 요청하는 것은 사용자의 직접적인 액션(버튼 클릭 등)에 대한 응답으로만 요청해야 합니다.

<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**

지정된 체인 ID를 가진 체인으로 전환하도록 사용자에게 확인 메시지를 제공합니다.

이 메서드는 사용자의 직접적인 액션(버튼 클릭 등)에 대한 응답으로만 호출해야 합니다.

다음 중 하나라도 해당되는 경우, 포키는 요청을 거부합니다.

* 체인 ID가 올바르지 않음
* 지정된 체인 ID를 가진 체인을 포키가 지원하지 않음

이 메서드는 EIP-3326에 의해 정의됩니다.

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

### **wallet\_watchAsset**

이 메서드는 사용자가 포키에서 지정된 토큰을 추가할 수 있도록 요청합니다.

이 메서드는 디앱 개발자가 런타임에 사용자에게 지갑에서 토큰을 추적하고 추가할 수 있도록 합니다. 메서드는 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

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

위 RPC Method는 현재 지원하지 않습니다.

Ethereum JSON-RPC의 더 자세한 내용은[ MetaMask API](https://docs.metamask.io/wallet/reference/json-rpc-api/) 를 통해 확인해주세요.

<br>


---

# 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://docs.bifrostnetwork.com/pockie/for-developers/json-rpc-api.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.
