I'm trying to query information from the Solana blockchain using the API examples in the documentation (https://docs.solana.com/developing/clients/jsonrpc-api). I'm using:
curl https://api.mainnet-beta.solana.com:8899 -X POST -H "Content-Type: application/json" -d '
{
"jsonrpc": "2.0",
"id": 1,
"method": "getBalance",
"params": [
"KEY"
]
}
'
Whenever I run this, I get a timeout error:
curl: (7) Failed to connect to api.mainnet-beta.solana.com port 8899: Timed out
curl: (3) [globbing] unmatched brace in column 1
curl: (6) Couldn't resolve host 'jsonrpc'
curl: (6) Couldn't resolve host '2.0,'
curl: (6) Couldn't resolve host 'id'
curl: (6) Couldn't resolve host '1,'
curl: (6) Couldn't resolve host 'method'
curl: (6) Couldn't resolve host 'getBalance,'
curl: (6) Couldn't resolve host 'params'
curl: (3) [globbing] bad range specification in column 2
curl: (6) Couldn't resolve host 'Key'
curl: (3) [globbing] unmatched close brace/bracket in column 1
curl: (3) [globbing] unmatched close brace/bracket in column 1
Am I doing something wrong here? Can somebody please explain why this doesn't work? I also tried with Python:
import requests
import json
url = "https://api.mainnet-beta.solana.com:8899"
payload = {
"jsonrpc": "2.0",
"id": 1,
"method": "getBalance",
"params": [
"KEY"
]
}
response = requests.post(url, json=payload).json()
print(response)
KEY
is the wallet address
and I another timeout error: https://pastebin.com/38BC2xds. Would somebody please explain why this doesn't work and what I need to do to fix it?
CodePudding user response:
The port number isn't needed when accessing the main clusters, so you can try:
$ curl https://api.mainnet-beta.solana.com -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0", "id":1, "method":"getBalance", "params":["83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"]}'
which should give something like:
{"jsonrpc":"2.0","result":{"context":{"slot":101535695},"value":0},"id":1}
Except the slot number will be higher when you run it.