Blockchain By Example
上QQ阅读APP看书,第一时间看更新

Interactions with RSK

After having configured the RSK node, we can then manage it as a service that can be started with the following:

sudo service rsk start

As a result, RSK will run as a daemon in the background and download the blockchain (a few GBs) in the   /var/lib/rsk/database/testnet directory. Similarly, you can stop, restart, or check the situation of the service using the following:

sudo service rsk restart
sudo service rsk stop
service rsk status
For a detailed overview of an RSK node's behavior, you can consult its logs using  tail -f /var/log/rsk/rsk.log.

The RSK project provides a useful console that enables interaction with an RSK node through RPC calls. We can install this utility using npm:

git clone https://github.com/rsksmart/utilities.git
cd utilities/console && npm install

After the installation is complete, open a new CLI and run the following command to access the console (by default, the RSK node runs in port 4444):

node console.js -server localhost:4444

This will open for you an interactive console that allows you to send commands to your RSK smart node.  You can find a list of available RPC commands in the official documentation (https://github.com/rsksmart/rskj/wiki/JSON-RPC-API-compatibility-matrix).

It is worth mentioning that an RSK node behaves like an Ethereum node by exposing the Web3 API over RPC, whereas the JavaScript console is a wrapper for the web3js API (part of the Ethereum project) to execute Web3 available calls in a bitcoin-related environment. We will cover  this API in depth in Chapter 4Peer-to-Peer Auctions in Ethereum, Chapter 5Tontine Game with Truffle and Drizzle and Chapter 6, Blockchain-Based Futures System.

To check whether the blockchain is synced, we can use the  web3.eth.syncing  command in the RSK console which should return false (which might also mean that the node isn't syncing), and the web3.eth.blockNumber command should return the same block number as the latest block in the RSK explorer ( explorer.testnet.rsk.co/blocks).