GuidesAPI Reference

RPC Method Call

You can use the Xplorer API to invoke the RPC method for each blockchain platform.

๐Ÿ“˜

Did you create a project and get an API Key?

Reading the instructions for 'Create a project' and 'Generate API key' will make the process easier."


Get the latest block number

Let's practice retrieving the latest block numbers from Klaytn's Main Network.
Before practicing, it's important to note that the Xplorer API requires a program that supports HTTPS protocol.
This example will demonstrate calling the RPC method using the cURL program.

  1. Go to 'Dashboard โžก๏ธ Project Details' and copy the endPoint.
2800

2. Place the copied endPoint in {INPUT_YOUR_ENDPOINT} of the following cURL example.
curl -X 'POST' \
  '{INPUT_YOUR_ENDPOINT}' \
  -H 'Content-Type: application/json' \
  -d '{
  "jsonrpc": "2.0",
  "method": "klay_blockNumber",
  "params": [],
  "id": 83
}'

And enter the above command in the Terminal to obtain the latest block number.
A response value similar to the following will be returned.

{
  "jsonrpc": "2.0",
  "id": 83,
  "result": "0x6707c7e"
}


3. Check the API request status in the Metrics tab. 2800


Integrating Caver.js with Xplorer API

Besides cURL, there are other ways to use the Xplorer API. One option is to integrate Caver.js, Klaytn's JavaScript SDK, with the Xplorer API and use them together. For more detailed information about Caver.js, please refer to this link.

const Caver = require("caver-js");
const caver = new Caver("https://api.xplorer.tech/KLAY/rpc/{INPUT_YOUR_KEY}");



When Xplorer API usage is not possible

  • When the usage limit per minute or per month has been exceeded
  • When the user's IP address is not included in the IP whitelist
  • When an incorrect value is entered for the Coin symbol parameter of the Xplorer API
  • When the API Key has been deactivated

Whatโ€™s Next