B9lab Logo
Tezos Developer Portal
Developer PortalDeveloper Portal

Testnet - Communicating with Tezos

JSON/RPC interface

Reading Time: 23 min

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's first list what the RPC offers:

$ ./florencenet.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:

$ ./florencenet.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:

$ ./florencenet.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's add a flag and use the command again:

$ ./florencenet.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.

tip icon

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 previous section. So, if you run the command:

$ ./florencenet.sh client transfer 1 from faucetWallet to myFirstKey --burn-cap 0.5

from 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:

./florencenet.sh start --rpc-port 8732

Let's request the balance again:

curl -s localhost:8732/chains/main/blocks/head/context/contracts/MYFIRSTKEY_ADDRESS/balance
tip icon

We could continue endlessly listing how different requests and their responses look. For the interested reader, we recommend checking out the full description.

reading icon
Discuss on Slack
Rate this Page
Would you like to add a message?
Thank you for your Feedback!