Skip to main content

Ronin JSON-RPC API reference

Overview

The Ronin JSON-RPC API provides a robust interface for developers to interact programmatically with Ronin nodes. This API facilitates a variety of blockchain-related operations, including:

  • Querying blockchain data: blocks, transactions, and balances.
  • Smart contract interaction: Query and execute contract functions.
  • Transaction management: send transactions and estimate gas requirements.

Authentication

Access to this API requires an API key. Retrieve your API key from the Developer Console > your app > Information > KEY section. For more information, see Get started.

Using the API with Web3.js and ethers.js

Web3.js example

Web3.js
const options = {
headers: [
{ name: 'x-api-key', value: 'xxxxxx' },
],
};

const web3Provider = new Web3.providers.HttpProvider('https://api-gateway.skymavis.com/rpc', options);
const web3 = new Web3(web3Provider);

console.log('Latest block number:', await web3.eth.getBlockNumber());

Ethers.js example

Ethers.js
const connection = {
url: 'https://api-gateway.skymavis.com/rpc',
headers: {
'x-api-key': 'xxxxx'
}
};

const provider = new ethers.providers.JsonRpcProvider(connection);

console.log('Latest block number:', await provider.getBlockNumber());

Adding API key in request header

For simpler scenarios, you can include your API key directly in the query string:

Web3.js
const apiKey = 'YOUR_API_KEY';
const web3Provider = new Web3.providers.HttpProvider('https://api-gateway.skymavis.com/rpc?apikey=' + apiKey);
Ethers.js
const apiKey = 'YOUR_API_KEY';
const provider = new ethers.providers.JsonRpcProvider('https://api-gateway.skymavis.com/rpc?apikey=' + apiKey);
cURL
curl --location --request POST 'https://api-gateway.skymavis.com/rpc?apikey=YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"jsonrpc": "2.0",
"method": "eth_blockNumber",
"params": [
],
"id": 1
}'

Status codes and error handling

Understand common error codes to troubleshoot API requests effectively:

CodeMessageDescription
-32700Parse errorInvalid JSON format.
-32600Invalid requestJSON is not a valid request object.
-32601Method not foundSpecified method does not exist.
-32602Invalid paramsParameters do not match method requirements.
-32603Internal errorAn internal JSON-RPC error occurred. error

Error object format

Errors are structured to provide clear and actionable information:

{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32602,
"message": "too many arguments, want at most 0"
}
}

See also

Was this page helpful?
Happy React is loading...