I'm doing some Web3 stuff, when an error appeared at the beginning of the process. Targeting the problem, I realized that the problem was with my RPC (which may have crashed). I temporarily tried an RPC from Solana's doc, (Serum) and same, same problem. I then switched to the mainnet-beta RPC and there it worked. I specify that I did not exceed the rate-limit. So I wondered if there was a way to test an RPC, in case of error go to a backup?
1 Answer
You can test the current health of a node using the getHealth
RPC method defined in the documentation.
For example a request would look like:
curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
{"jsonrpc":"2.0","id":1, "method":"getHealth"}
'
Healthy Response:
{ "jsonrpc": "2.0", "result": "ok", "id": 1 }
Unhealthy Response:
{
"jsonrpc": "2.0",
"error": {
"code": -32005,
"message": "Node is unhealthy",
"data": {}
},
"id": 1
}