Skip to main content

Ronin JSON-RPC

Overview

This section contains a collection of the Ronin JSON-RPC API methods, which you can use to interact with Ronin nodes programmatically.

Here are some of the features provided by the API:

  • Querying blocks, transactions, balances
  • Querying smart contracts
  • Sending transactions, estimating gas

Authentication

This API requires an API key for authentication.

Authorization

The following RPC services require authorized access:

  • Ronin Archive Node
  • Ronin WebSockets

For more information, see Connect to an archive node and Connect over WebSocket.

Use with web3.js and ethers.js libraries

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

 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())

Another way is to add your API key in the request header:

const apiKey = 'YOUR_API_KEY'

/*8* For web3.js */
const web3Provider = new Web3.providers.HttpProvider('https://api-gateway.skymavis.com/rpc?apikey=' + apiKey);

/* For ether.js */
const provider = new ethers.providers.JsonRpcProvider('https://api-gateway.skymavis.com/rpc?apikey=' + apiKey);

/* Or using 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
}'

Errors

All errors returned by the Ronin JSON-RPC API return an object with this structure:

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

The following table includes common error codes and their meaning.

CodeMessageDescription
-32700Parse errorInvalid JSON
-32600Invalid requestJSON is not a valid request object
-32601Method not foundMethod does not exist
-32602Invalid paramsInvalid method parameters
-32603Internal errorInternal JSON-RPC error

See also

Was this helpful?
Happy React is loading...