Links

Klaytn Node API

This page introduces how to call JSON-RPC API that Klaytn Endpoint Node offered.

Before Getting Started

  • The x-chain-id value for calling the API is 8217 (Cypress) or 1001 (Baobab).
  • Essential parameters for calling APIs are described in individual examples.
Values that a user needs to enter for calling APIs will be represented with one pair of braces ({}). A user must enter the following values.
Item
Description
Note
chain-id
8217 or 1001
Cypress(Klaytn mainnet) or Baobab(Klaytn testnet
access-key-id
Auth ID
accessKeyId obtained from KAS Console - Security - Credential
secret-access-key
Auth Password
secretAccessKey obtained from KAS Console - Security - Credential
krn
(optional) ID of Account Pool
Unnecessary when using Default Account Pool
A KAS API Authentication Key (API Auth Key) provides access to all KAS services and all the rights to a Klaytn account which was created by calling Wallet API via this API Auth Key. The rights here include accessing and transferring all the assets (KLAY, etc.) of or sending a transaction from a Klaytn account. If you shared your API Auth Key with any unauthorized personnel, your Klaytn account could be compromised and might cause unwanted transaction execution.
DO NOT share your API Auth Key (Secret AccessKey or Authorization) with any unauthorized personnel. DO PUT efforts necessary to keep your API Auth Key safe for the security of your KAS/Klaytn account.
For details about KAS SDK (caver-js/caver-java extensions) installation and execution, please visit KAS SDK. To check Klaytn account information through Klaytn Node, create an Account Pool and select an account to use. For more details on creating an Account Pool, account, and selecting an account, refer to Getting Started.

Get Klaytn account Information on Klaytn Node

Check the Block Number of the Most Recent Block

The block number of the latest block on Klaytn is required for checking the account balance, key type, and other recent information on the account using Node API. To this end, a user must send the JSON-RPC request { "method": "klay_blockNumber", "id": 1 } for the latest block number.
For more details about Node API, please visit here.

API Request

curl
javascript
java
curl --location --request POST "https://node-api.klaytnapi.com/v2/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}"
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()
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());
  • “id” is a random value.
  • “params” and “jsonrpc” can be omitted.
For more details about API Request, please visit here.
Node API calls different Klaytn endpoint nodes each time, and the result value may be unexpected if “pending” is entered as the block number.

API Response

The following response will be received if the API is successfully executed.
curl
javascript
java
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x5d39"
}
0x5d39
0x5d39
  • “result” is a block number value represented in hexadecimal.
For details about Klaytn JSON-RPC API, please visit here. For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum.

Get Klaytn account Information by EOA

API Request

Enter the block number and Klaytn EOA, and then, execute the JSON-RPC function, klay_getAccount, to search for account information. klay_getAccount then receives the address (required) and block number/tag (required or optional) parameters. The block number and tag parameters are needed if RPC is directly called through curl or other HTTP methods.
curl
javascript
java
curl --location --request POST "https://node-api.klaytnapi.com/v2/klaytn" \
-u {accessKeyId}:{secretAccessKey} \
--header "x-chain-id: 8217" \
--header "Content-Type: application/json" \
--data-raw "{"jsonrpc":"2.0","method":"klay_getAccount","params":["0x3111a0577f322e8fb54f78d9982a26ae7ca0f722", "0x5d39"],"id":1}"
const accessKeyId = "{accessKeyId}"
const secretAccessKey = "{secretAccessKey}"
const chainId = 1001
const caver = new CaverExtKAS()
caver.initKASAPI(chainId, accessKeyId, secretAccessKey)
const account = await caver.rpc.klay.getAccount()
String accessKey = "your accessKey";
String secretAccessKey = "your secret accessKey";
CaverExtKAS caver = new CaverExtKAS();
caver.initKASAPI(1001, accessKey, secretAccessKey);
Account res = caver.rpc.klay.getAccount("0x3111a0577f322e8fb54f78d9982a26ae7ca0f722").send();
  • “id” is a random value.
  • “jsonrpc” can be omitted.
  • This is an example of Klaytn account address value: 0x3111a0577f322e8fb54f78d9982a26ae7ca0f722.
  • According to the implementation of SDK (caver-js, caver-java), the block number/tag can be omitted. Here, the “latest” tag is used.
For more details about API Request, please visit here.
Node API calls different Klaytn endpoint nodes each time, and the result value may be unexpected if “pending” is entered as the block number.

API Response

Once the API is successfully executed, the user will receive a response regarding the information of the Klaytn account that entered the EOA.
curl
javascript
java
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"accType": 1,
"account": {
"nonce": 4,
"balance": "0x8d286271f52600",
"humanReadable": false,
"key": {
"keyType": 1,
"key": {}
}
}
}
}
{
accType: 1,
account: {
nonce: 4,
balance: "0x8d286271f52600",
humanReadable: false,
key: { keyType: 1, key: {} }
}
}
/* skipped */
For details about Klaytn JSON-RPC API, please visit here. For details about this API, please visit here. For inquires about this document or KAS, please visit KAS Developer forum.

List of Node API KAS Currently Supports

Other JSON-RPC APIs of Klaytn can be called through KAS using the same process. However, KAS only supports a few Node APIs currently. Here is a list of Node APIs supported by KAS.
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
For inquires about this document or KAS, please visit KAS Developer forum.