# JSON-RPC API

Biport는 `window.biport.request(args)` provider method를 사용하여 JSON-RPC API를 래핑합니다.&#x20;

표준 Ethereum RPC 메소드에 대한 자세한 내용은 [Ethereum Wiki](https://ethereum.org/en/developers/docs/apis/json-rpc/#json-rpc-methods)를 참조하십시오.

{% hint style="info" %}
모든 RPC 메소드 요청은 오류를 반환할 수 있습니다. `window.biport.request(args)`를 호출할 때마다 오류 처리를 반드시 해야 합니다.
{% endhint %}

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

```typescript
window.biport.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 {
        console.error(error);
      }
    });
```

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

### Methods

#### wallet\_getPermissions <a href="#wallet_getpermissions" id="wallet_getpermissions"></a>

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

```typescript
window.biport.request({ method: 'wallet_getPermissions' })
    .then((result) => {
      console.log('Response:', result);
    });
```

지갑에서 DApp과 연결된 권한의 정보입니다. 요청자가 권한을 가지고 있지 않은 경우, 결과의 배열은 비어 있습니다.

#### wallet\_requestPermissions <a href="#wallet_requestpermissions" id="wallet_requestpermissions"></a>

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

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

```typescript
window.biport
  .request({
    method: 'wallet_requestPermissions',
    params: [{ eth_accounts: {} }],
  })
  .then((permissions) => {
    const accountsPermission = permissions.find(
      (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);
    }
  });
```

#### wallet\_switchEthereumChain <a href="#wallet_switchethereumchain" id="wallet_switchethereumchain"></a>

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

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

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

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

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

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

#### wallet\_watchAsset <a href="#wallet_watchasset" id="wallet_watchasset"></a>

이 메서드는 사용자가 Biport에서 지정된 토큰을 추적하도록 요청합니다.

이 메서드는 dapp 개발자가 런타임에서 사용자에게 지갑에서 토큰을 추적하도록 요청할 수 있도록 합니다.

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

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

### 지원하지 않는 Methods

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

&#x20;위 RPC Method는 현재 지원하지 않습니다.

Ethereum JSON-RPC의 더 자세한 내용은 [MetaMask API](https://docs.bifi.finance/biport-wallet-api-documentation/) 를 통해 확인할 수 있습니다.


---

# 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.bifi.finance/biport-guide-kr/api-documentation/api/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.
