> For the complete documentation index, see [llms.txt](https://ground-x.gitbook.io/kas-docs-dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ground-x.gitbook.io/kas-docs-dev/tutorial/klaytn-node-api.md).

# JSON-RPC API

이 페이지는 Node API로 Klaytn Endpoint Node가 제공하는 JSON-RPC 함수들을 호출하는 법을 안내합니다.

## 튜토리얼에 앞서 <a href="#tutorial-node-api-start" id="tutorial-node-api-start"></a>

* API 호출에 사용되는 `x-chain-id` 값은 8217(Cypress) 또는 1001(Baobab)입니다.
* API 호출에 필요한 필수 파라미터는 각 예시에 설명됩니다.

API 호출 시 사용자가 입력해야 하는 값은 중괄호 1개(`{}`)로 표시합니다. 사용자가 입력해야 하는 값은 아래 테이블과 같습니다.

| 항목                | 값                     | 비고                                                      |
| ----------------- | --------------------- | ------------------------------------------------------- |
| chain-id          | 8217 또는 1001          | Cypress(Klaytn 메인넷) 또는 Baobab(Klaytn 테스트넷)              |
| access-key-id     | 인증 아이디                | KAS 콘솔 - Security - Credential에서 발급받은 `accessKeyId`     |
| secret-access-key | 인증 비밀번호               | KAS 콘솔 - Security - Credential에서 발급받은 `secretAccessKey` |
| krn               | (optional) 계정 저장소의 ID | 기본 계정 저장소 사용 시 불필요                                      |

API 인증 키가 있으면 모든 KAS 서비스를 사용할 수 있으며 Wallet API를 호출해 만든 Klaytn 계정에 대한 모든 권한을 소유합니다. 모든 권한에는 Klaytn 계정의 자산(KLAY 등) 이동이나 [트랜잭션](/kas-docs-dev/tutorial/wallet-transaction-api.md) 전송 및 실행 권한이 포함됩니다. 만약 API 인증 키에 타인이 접근한다면 Klaytn 계정 권한을 탈취당해 원치 않는 트랜잭션이 발생할 수 있습니다.

{% hint style="danger" %}
KAS/Klaytn 계정 보안을 위해 KAS API 인증 키(Secret Access Key)를 타인과 함부로 공유하지 말고 주의해 관리하십시오.
{% endhint %}

{% hint style="info" %}
KAS SDK(caver-js/caver-java extension) 설치, 실행에 관한 자세한 내용은 [KAS SDK](/kas-docs-dev/sdk.md#kas-sdk)를 확인하십시오.\
Klaytn Node에서 Klaytn 계정 정보를 확인하려면 계정 저장소와 계정을 생성하고 사용할 계정을 선택해야 합니다.\
계정 저장소 생성, 계정 생성, 계정 선택에 관한 자세한 내용은 [Getting Started](/kas-docs-dev/getting-started/account.md)를 확인하십시오.
{% endhint %}

## Klaytn Node에서 Klaytn 계정 정보 확인하기 <a href="#tutorial-node-api-account" id="tutorial-node-api-account"></a>

### 가장 최근에 생성된 블록 번호 확인하기 <a href="#tutorial-node-api-blockinfo" id="tutorial-node-api-blockinfo"></a>

Node API로 여러분 계정의 잔고, 계정 키 타입 등 계정에 관한 가장 최신 정보를 확인하려면 클레이튼상에 있는 가장 최신 블록의 블록 번호를 알아야합니다. 이를 위해 JSON-RPC 요청 `{ "method": "klay_blockNumber", "id": 1 }`을 보내고 최신의 블록 번호를 요청합니다.

{% hint style="info" %}
Node API에 관한 더 자세한 내용은 [다음](https://ko.docs.klaytn.com/bapp/json-rpc/api-references)을 확인하십시오.
{% endhint %}

#### API 호출

{% tabs %}
{% tab title="curl" %}

```
curl --location --request POST 'https://node-api.klaytnapi.com/v1/klaytn' \
    -u {accessKeyId}:{secretAccessKey} \
    --header 'x-chain-id: {chain-id}' \
    --header 'Content-Type: application/json' \
    --data-raw '{"jsonrpc":"2.0","method":"klay_blockNumber","params":[],"id":1}'
```

{% endtab %}

{% tab title="javascript" %}

```javascript
const accessKeyId = "{accessKeyId}"
const secretAccessKey = "{secretAccessKey}"
const chainId = 1001

const caver = new CaverExtKAS()
caver.initKASAPI(chainId, accessKeyId, secretAccessKey)
const blockNumber = await caver.rpc.klay.getBlockNumber()
```

{% endtab %}

{% tab title="java" %}

```java
String accessKey = "your accessKey";
String secretAccessKey = "your secret accessKey";

CaverExtKAS caver = new CaverExtKAS();
caver.initKASAPI(1001, accessKey, secretAccessKey);

Quantity response = caver.rpc.klay.getBlockNumber().send();
System.out.println(response.getValue());
/* call an appropriate method via caver.rpc */
```

{% endtab %}
{% endtabs %}

* `id`는 임의의 값입니다.
* `params`, `jsonrpc`는 생략 가능합니다.

{% hint style="info" %}
API 호출에 관한 더 자세한 내용은 [다음](https://ko.docs.klaytn.com/bapp/json-rpc/api-references/klay/block#klay_blocknumber)을 확인하십시오.
{% endhint %}

{% hint style="warning" %}
Node API는 매번 다른 클레이튼 엔드포인트 노드를 호출하며 블록 번호에 `pending`을 입력할 경우 결과값이 기대와 다를 수 있습니다.
{% endhint %}

#### API 응답

API가 성공적으로 실행되면 다음과 같은 응답을 받습니다.

{% tabs %}
{% tab title="curl" %}

```javascript
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": "0x5d39"
}
```

{% endtab %}

{% tab title="javascript" %}

```javascript
0x5d39
```

{% endtab %}

{% tab title="java" %}

```java
0x5d39
```

{% endtab %}
{% endtabs %}

* `result`는 16진수로 표현된 블록 번호값입니다.

Klaytn JSON-RPC API에 관한 더 자세한 내용은 [다음](https://ko.docs.klaytn.com/bapp/json-rpc/api-references)을 확인하십시오.\
이 API에 관한 자세한 내용은 [다음](https://refs.klaytnapi.com/ko/node/latest#operation/JSONRPC%ED%98%B8%EC%B6%9C)을 확인하십시오.\
이 문서 혹은 KAS에 관한 문의는 [개발자 포럼](https://forum.klaytn.com/c/kas/kasko/26)을 방문해 도움을 받으십시오. <br>

### EOA로 Klaytn 계정 정보 확인하기 <a href="#tutorial-node-api-accountinfo" id="tutorial-node-api-accountinfo"></a>

#### API 호출

블록 번호와 클레이튼 계정 주소(EOA)를 입력하고 계정 정보를 조회하는 JSON-RPC 함수 `klay_getAccount`를 실행합니다. `klay_getAccount`는 주소(필수)와 블록번호/태그(필수 또는 선택) 파라미터를 받습니다. curl 등 HTTP 방식으로 직접 RPC를 호출할 경우 블록번호/태그는 필수 파라미터입니다.

{% tabs %}
{% tab title="curl" %}

```
curl --location --request POST 'https://node-api.klaytnapi.com/v1/klaytn' \
    -u {accessKeyId}:{secretAccessKey} \
    --header 'x-chain-id: {chain-id}' \
    --header 'Content-Type: application/json' \
    --data-raw '{"jsonrpc":"2.0","method":"klay_getAccount","params":["0x3111a0577f322e8fb54f78d9982a26ae7ca0f722", "0x5d39"],"id":1}'
```

{% endtab %}

{% tab title="javascript" %}

```javascript
const accessKeyId = "{accessKeyId}"
const secretAccessKey = "{secretAccessKey}"
const chainId = 1001 // for Baobab; 8217 if Cypress

const caver = new CaverExtKAS()
caver.initKASAPI(chainId, accessKeyId, secretAccessKey)
const account = await caver.rpc.klay.getAccount()
```

{% endtab %}

{% tab title="java" %}

```java
String accessKey = "your accessKey";
String secretAccessKey = "your secret accessKey";

CaverExtKAS caver = new CaverExtKAS();
caver.initKASAPI(1001, accessKey, secretAccessKey); // for Baobab; 8217 if Cypress

Account res = caver.rpc.klay.getAccount("0x3111a0577f322e8fb54f78d9982a26ae7ca0f722").send();
```

{% endtab %}
{% endtabs %}

* `id`는 임의의 값입니다.
* `jsonrpc`는 생략 가능합니다.
* 클레이튼 계정 주소값 `0x3111a0577f322e8fb54f78d9982a26ae7ca0f722`은 예시값입니다.
* SDK(caver-js, caver-java)는 구현에 따라 블록번호/태그를 생략 가능합니다. 이 경우 `"latest"` 태그가 사용됩니다.

{% hint style="info" %}
API 호출에 관한 더 자세한 내용은 [다음](https://ko.docs.klaytn.com/bapp/json-rpc/api-references/klay/account#klay_getaccount)을 확인하십시오.
{% endhint %}

{% hint style="warning" %}
Node API는 매번 다른 클레이튼 엔드포인트 노드를 호출하며 블록 번호에 `pending`을 입력할 경우 결과값이 기대와 다를 수 있습니다.
{% endhint %}

#### API 응답

API가 성공적으로 실행되면 다음과 같이 입력한 EOA를 가지고 있는 클레이튼 계정 정보를 나타내는 응답을 받습니다.

{% tabs %}
{% tab title="curl" %}

```javascript
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "accType": 1,
        "account": {
            "nonce": 4,
            "balance": "0x8d286271f52600",
            "humanReadable": false,
            "key": {
                "keyType": 1,
                "key": {}
            }
        }
    }
}
```

{% endtab %}

{% tab title="javascript" %}

```javascript
{
    accType: 1,
    account: {
        nonce: 4,
        balance: "0x8d286271f52600",
        humanReadable: false,
        key: { keyType: 1, key: {} }
    }
}
```

{% endtab %}

{% tab title="java" %}

```java
/* skipped */
```

{% endtab %}
{% endtabs %}

Klaytn JSON-RPC API에 관한 더 자세한 내용은 [다음](https://ko.docs.klaytn.com/bapp/json-rpc/api-references)을 확인하십시오.\
이 API에 관한 자세한 내용은 [다음](https://refs.klaytnapi.com/ko/node/latest#operation/JSONRPC%ED%98%B8%EC%B6%9C)을 확인하십시오.\
이 문서 혹은 KAS에 관한 문의는 [개발자 포럼](https://forum.klaytn.com/c/kas/kasko/26)을 방문해 도움을 받으십시오. <br>

### KAS에서 현재 지원하는 Node API 목록 <a href="#tutorial-node-api-support-list" id="tutorial-node-api-support-list"></a>

위에서 안내한 방식으로 Klaytn의 다른 JSON-RPC API도 KAS에서 호출할 수 있습니다. 단, 현재 KAS는 일부 Node API만을 지원합니다. 현재 KAS에서 지원하는 Node API 목록은 아래와 같습니다.

| Category      | Module                | Method                                        | Support |
| ------------- | --------------------- | --------------------------------------------- | ------- |
| Platform      | Account               | klay\_isContractAccount                       | O       |
| Platform      | Account               | klay\_getTransactionCount                     | O       |
| Platform      | Account               | klay\_getCode                                 | O       |
| Platform      | Account               | klay\_getBalance                              | O       |
| Platform      | Account               | klay\_getAccountKey                           | O       |
| Platform      | Account               | klay\_getAccount                              | O       |
| Platform      | Account               | klay\_accountCreated                          | O       |
| Platform      | Account               | klay\_encodeAccountKey                        | O       |
| Platform      | Account               | klay\_decodeAccountKey                        | O       |
| Platform      | Block                 | klay\_syncing                                 | O       |
| Platform      | Block                 | klay\_getStorageAt                            | O       |
| Platform      | Block                 | klay\_getCouncilSize                          | O       |
| Platform      | Block                 | klay\_getCouncil                              | O       |
| Platform      | Block                 | klay\_getCommitteeSize                        | O       |
| Platform      | Block                 | klay\_getCommittee                            | O       |
| Platform      | Block                 | klay\_getBlockWithConsensusInfoByNumber       | O       |
| Platform      | Block                 | klay\_getBlockWithConsensusInfoByHash         | O       |
| Platform      | Block                 | klay\_getBlockTransactionCountByNumber        | O       |
| Platform      | Block                 | klay\_getBlockTransactionCountByHash          | O       |
| Platform      | Block                 | klay\_getBlockReceipts                        | O       |
| Platform      | Block                 | klay\_getBlockByNumber                        | O       |
| Platform      | Block                 | klay\_getBlockByHash                          | O       |
| Platform      | Block                 | klay\_blockNumber                             | O       |
| Platform      | Configuration         | klay\_protocolVersion                         | O       |
| Platform      | Configuration         | klay\_gasPriceAt                              | O       |
| Platform      | Configuration         | klay\_gasPrice                                | O       |
| Platform      | Configuration         | klay\_clientVersion                           | O       |
| Platform      | Configuration         | klay\_chainID                                 | O       |
| Platform      | Filter                | klay\_getLogs                                 | O       |
| Platform      | Miscellaneous         | klay\_sha3                                    | O       |
| Platform      | Transaction           | klay\_sendRawTransaction                      | O       |
| Platform      | Transaction           | klay\_getTransactionReceipt                   | O       |
| Platform      | Transaction           | klay\_getTransactionByHash                    | O       |
| Platform      | Transaction           | klay\_getTransactionByBlockNumberAndIndex     | O       |
| Platform      | Transaction           | klay\_getTransactionByBlockHashAndIndex       | O       |
| Platform      | Transaction           | klay\_estimateGas                             | O       |
| Platform      | Transaction           | klay\_estimateComputationCost                 | O       |
| Platform      | Transaction           | klay\_call                                    | O       |
| Network       | net                   | net\_peerCountByType                          | O       |
| Network       | net                   | net\_peerCount                                | O       |
| Network       | net                   | net\_networkID                                | O       |
| Network       | net                   | net\_listening                                | O       |
| Platform      | Account               | klay\_sign                                    | X       |
| Platform      | Account               | klay\_accounts                                | X       |
| Platform      | Block                 | klay\_mining                                  | X       |
| Platform      | Filter                | klay\_uninstallFilter                         | X       |
| Platform      | Filter                | klay\_newPendingTransactionFilter             | X       |
| Platform      | Filter                | klay\_newFilter                               | X       |
| Platform      | Filter                | klay\_newBlockFilter                          | X       |
| Platform      | Filter                | klay\_getFilterLogs                           | X       |
| Platform      | Filter                | klay\_getFilterChanges                        | X       |
| Debug         | Blockchain Inspection | debug\_setHead                                | X       |
| Debug         | Blockchain Inspection | debug\_printBlock                             | X       |
| Debug         | Blockchain Inspection | debug\_preimage                               | X       |
| Debug         | Blockchain Inspection | debug\_getModifiedAccountsByNumber            | X       |
| Debug         | Blockchain Inspection | debug\_getModifiedAccountsByHash              | X       |
| Debug         | Blockchain Inspection | debug\_getBlockRlp                            | X       |
| Debug         | Blockchain Inspection | debug\_dumpBlock                              | X       |
| Platform      | Configuration         | klay\_writeThroughCaching                     | X       |
| Platform      | Configuration         | klay\_rewardbase                              | X       |
| Platform      | Configuration         | klay\_isSenderTxHashIndexingEnabled           | X       |
| Platform      | Configuration         | klay\_isParallelDBWrite                       | X       |
| Governance    | Governance            | governance\_vote                              | X       |
| Governance    | Governance            | governance\_totalVotingPower                  | X       |
| Governance    | Governance            | governance\_showTally                         | X       |
| Governance    | Governance            | governance\_nodeAddress                       | X       |
| Governance    | Governance            | governance\_myVotingPower                     | X       |
| Governance    | Governance            | governance\_myVotes                           | X       |
| Governance    | Governance            | governance\_itemsAt                           | X       |
| Governance    | Governance            | governance\_chainConfig                       | X       |
| Debug         | Logging               | debug\_vmodule                                | X       |
| Debug         | Logging               | debug\_verbosity                              | X       |
| Debug         | Logging               | debug\_setVMLogTarget                         | X       |
| Debug         | Logging               | debug\_backtraceAt                            | X       |
| service chain | Main-bridge           | convertServiceChainBlockHashToMainChainTxHash | X       |
| Debug         | Profiling             | debug\_writeMemProfile                        | X       |
| Debug         | Profiling             | debug\_writeBlockProfile                      | X       |
| Debug         | Profiling             | debug\_stopPProf                              | X       |
| Debug         | Profiling             | debug\_stopCPUProfile                         | X       |
| Debug         | Profiling             | debug\_startPProf                             | X       |
| Debug         | Profiling             | debug\_startCPUProfile                        | X       |
| Debug         | Profiling             | debug\_setBlockProfileRate                    | X       |
| Debug         | Profiling             | debug\_isPProfRunning                         | X       |
| Debug         | Profiling             | debug\_cpuProfile                             | X       |
| Debug         | Profiling             | debug\_blockProfile                           | X       |
| Debug         | Runtime Debugging     | debug\_stacks                                 | X       |
| Debug         | Runtime Debugging     | debug\_setGCPercent                           | X       |
| Debug         | Runtime Debugging     | debug\_metrics                                | X       |
| Debug         | Runtime Debugging     | debug\_memStats                               | X       |
| Debug         | Runtime Debugging     | debug\_gcStats                                | X       |
| Debug         | Runtime Debugging     | debug\_freeOSMemory                           | X       |
| Debug         | Runtime Tracing       | debug\_stopGoTrace                            | X       |
| Debug         | Runtime Tracing       | debug\_startGoTrace                           | X       |
| Debug         | Runtime Tracing       | debug\_goTrace                                | X       |
| service chain | Sub-bridge            | sendChainTxslimit                             | X       |
| service chain | Sub-bridge            | latestAnchoredBlockNumber                     | X       |
| service chain | Sub-bridge            | anchoring                                     | X       |
| Platform      | Transaction           | klay\_signTransaction                         | X       |
| Platform      | Transaction           | klay\_sendTransaction                         | X       |
| Platform      | Transaction           | klay\_getTransactionReceiptBySenderTxHash     | X       |
| Platform      | Transaction           | klay\_getTransactionBySenderTxHash            | X       |
| Debug         | VM Standard Tracing   | debug\_standardTraceBlockToFile               | X       |
| Debug         | VM Standard Tracing   | debug\_standardTraceBadBlockToFile            | X       |
| Debug         | VM Tracing            | debug\_traceTransaction                       | X       |
| Debug         | VM Tracing            | debug\_traceBlockFromFile                     | X       |
| Debug         | VM Tracing            | debug\_traceBlockByNumber                     | X       |
| Debug         | VM Tracing            | debug\_traceBlockByHash                       | X       |
| Debug         | VM Tracing            | debug\_traceBlock                             | X       |
| Debug         | VM Tracing            | debug\_traceBadBlock                          | X       |
| Management    | admin                 | admin\_stopWS                                 | X       |
| Management    | admin                 | admin\_stopRPC                                | X       |
| Management    | admin                 | admin\_startWS                                | X       |
| Management    | admin                 | admin\_startRPC                               | X       |
| Management    | admin                 | admin\_removePeer                             | X       |
| Management    | admin                 | admin\_peers                                  | X       |
| Management    | admin                 | admin\_nodeInfo                               | X       |
| Management    | admin                 | admin\_importChain                            | X       |
| Management    | admin                 | admin\_exportChain                            | X       |
| Management    | admin                 | admin\_datadir                                | X       |
| Management    | admin                 | admin\_addPeer                                | X       |
| service chain | service chain         | removePeer                                    | X       |
| service chain | service chain         | nodeInfo                                      | X       |
| service chain | service chain         | addPeer                                       | X       |
| Management    | personal              | personal\_unlockAccount                       | X       |
| Management    | personal              | personal\_sign                                | X       |
| Management    | personal              | personal\_sendValueTransfer                   | X       |
| Management    | personal              | personal\_sendTransaction                     | X       |
| Management    | personal              | personal\_sendAccountUpdate                   | X       |
| Management    | personal              | personal\_replaceRawKey                       | X       |
| Management    | personal              | personal\_newAccount                          | X       |
| Management    | personal              | personal\_lockAccount                         | X       |
| Management    | personal              | personal\_listAccounts                        | X       |
| Management    | personal              | personal\_importRawKey                        | X       |
| Management    | personal              | personal\_ecRecover                           | X       |
| Management    | txpool                | txpool\_status                                | X       |
| Management    | txpool                | txpool\_inspect                               | X       |
| Management    | txpool                | txpool\_content                               | X       |

이 문서 혹은 KAS에 관한 문의는 [개발자 포럼](https://forum.klaytn.com/c/kas/kasko/26)을 방문해 도움을 받으십시오. <br>
