Testnet - Communicating With Tezos
JSON/RPC interface
So far we have used the testnet script to execute tezos-client commands. This client communicates with the tezos-node.
Communication works with the help of the JSON/RPC interface. The tezos-node responses are JSON based. Notice it is not the JSON-RPC protocol, the communication is done over HTTP protocol.
Let us first list what the RPC offers:
$ ./hangzhounet.sh client rpc list
This should list you the GET/POST
queries you can do.
Analogous to the previous section we want to get the balance first.
First, we need to see all the addresses in our wallet:
$ ./hangzhounet.sh client list known addresses
Look for myFirstKey
from the last section and use its address to get the balance, replace the MYFIRSTKEY_ADDRESS
string in the following command with it:
$ ./hangzhounet.sh client rpc get /chains/main/blocks/head/context/contracts/MYFIRSTKEY_ADDRESS/balance
Now you should see the balance. But where is the JSON we are talking about? Let us add a flag and use the command again:
$ ./hangzhounet.sh client -l rpc get /chains/main/blocks/head/context/contracts/MYFIRSTKEY_ADDRESS/balance
This time you should see the HTTP requests and the JSON responses the client does.
You can find the reference for the JSON/RPC interface at the Tezos Developer Resource Documentation.
We can use the flag -l
for all commands from the previous section. So, if you run the command:
$ ./hangzhounet.sh client transfer 1 from faucetWallet to myFirstKey --burn-cap 0.5
From the last section, you will see all the queries and responses traveling in the background.
We can also use curl
for a request
if you start the network and with an exposed RPC port:
./hangzhounet.sh start --rpc-port 8732
Let us request the balance again:
curl -s localhost:8732/chains/main/blocks/head/context/contracts/MYFIRSTKEY_ADDRESS/balance
We could continue endlessly listing how different requests and their responses look. For the interested reader, we recommend checking out the full description.