Accessing the node database (Arcticle )

In this tutorial we are going to access the database directly. Let’s just jumps into the step, shall we? 

Interact with the database 

  1. Connect to the server 

ssh root @IPAddress

2. Go into the ZooBC mainnet directory 

cd zoobc/zoobc.mainnet/

3. Go inside the resources directory and let’s all the list by using command below 

cd resource/ 

Ls -alsh 

And you can see above, the database folder is inside the resource directory. 

4. To interact with database, let’s first installed the sqlite3 using the command:


apt-get install sqlite3 

Once it is installed we can access the database. 

5. Launch the database


6. Go inside the database directory 

.open /root/zoobc/zoobc.mainnet/resource/zoobc.db 

In this way, we are setting the sqlite3 to work with our database. And for little reminder, to see all the different command that we can run on the sqlite you the command below:


By doing this you can get all the information about the functionalities which will be really helpful to guide you along the way.

7. Let’s test the query!

– For example I want to find all the fields from the account balance but we want to limit only 5 data, then we do this query below. 

SELECT * from account_balance LIMIT 5;

As you can see here you get all the first 5 data from the account balance. And here you can see all those result are hard to understand, but we can solve it by running the command


.schema account_balance   

This command will shows us the instruction what the result was about. As you can see below the first one is the account address in a form of a BLOB. A BLOB means a set of byte of a data that is not readable, so that’s why the list is start by the separated “|” icons  and not by a data. Moreover, block height means the height of the block, the spendable balance simply means how much balance is available to be spent, next we have balance of the account and so fort. 

 – Next, let’s do a query to show 5 the account address from the account balance but make it in hexadecimal.  

SELECT hex (account_address), * FROM account_balance LIMIT 5;

And as you can see here, instead of getting a separator icons in the first line, now we get an actual data because I change the value to hexadecimal to make it readable. 

  • Let’s do a query again but this time, we only want to know about 5 data of the account address (in hexadecimal), block height, and balance  from the account balance.  By using the command:

SELECT hex (account_address),  block_height, balance FROM account_balance LIMIT 5;

And you can see from above, it only shows 3 data from the account balance.  

8. Changing a hexadecimal into a readable format 

Let’s take the last result (Just select and copy), then exit the sqlite3 


Then let’s go to the previous directory 

Cd ..

Next go inside the zcmd account

./zcmd account hex decode —hexAccountAddress #TheLastAccountBalanceAddress (the one that we copied ealier)

And we execute this you can see it change the value to a readable version of the account address. Let’s copy this address and search it on our ZooBC explorer. 

But unfortunately we can’t find the account in the ZooBc Explorer. The reason, why it happened because the current account address that we search doesn’t have any transactions. So, let us try using the other account that has transaction. To check the transaction, simply click the “Transaction” option on the menu bar, and you can find a lots of transaction. 

Let’s use the one that received 500 ZBC, just click that, copy the account address and let’s go back to our terminal.  

In the terminal, we gonna do the opposite. We are going to find the hex value of the readable account address. By using command down below:

./zcmd account hexcov—encodedAccountAddress #TheLastAccountBalanceAddress (the one that we copied ealier)

And it gives you the hexadecimal format of the account address. We need to copy this and let’s test it for the sqlite. 

But first, we need to launch the sqlite. 


Go inside the database directory 

.open /root/zoobc/zoobc.mainnet/resource/zoobc.db


Once it’s launched let do the query:

SELECT hex (account_address),  block_height, balance FROM account_balance WHERE account_address = X ‘#HexThatWeCopied’ ;

Here we can get the exact data from one particular account_address 

If we look closer at the last number which is 94082, and go back to our ZooBC explorer. You will see the same data. That this sender was receiving 10 ZBC.

Thank you for following this tutorial, In next episode we are going to learn how to interacting with the database! But before that, If you want to see the full step-by-step of this episode kindly check our Youtube – Accessing the node database