Hello again, everyone! Melvin here. Hopefully, you remember me from the last blogpost, where I showed you how to use Galleon. This time, I am back with a much longer and elaborated guide, where we will learn how to set up a tezos node so that we can interact with the Tezos blockchain using the tezos-client command line.
In this article, I will show you how to set up a tezos-node and sync up with the blockchain. Then, in a subsequent article, I will teach you how to perform various functions on the command line so that you can perform transactions, delegations, baking and much more! This guide is highly recommended for those of you who are interested in getting started on Tezos, as it consists of the essential tezos-client command lines that you need to familiarize yourself with before you start building your applications.
So, why use the tezos-client command line?
Well, this is the original and the best way to use Tezos, but it is also the most complicated compared to using wallets such as AirGap or Galleon. With the tezos-client command line, you can do just as much, or even more, than what a wallet can do! This includes sending transactions, interacting with smart contracts, and performing baking and delegation operations. In my opinion, this is the coolest way to use Tezos, and I had a ton of fun learning how to use it!
So, let’s get this started 😉 I hope by the end of this guide, you will better understand how to use the tezos-client command line and become a more experienced user, as well as get your first glimpse into what Tezos is.
Firstly, a short introduction to what the tezos-client command line is.
Have you ever seen something like this?
This is a command line interface, which is basically how a human can interact with a computer by typing in specific commands to perform certain actions. This method we are about to learn involves using the Ubuntu command line interface to interact with the Tezos node.
Ubuntu is what’s known as a distribution of Linux. Linux is a kernel, the core component of an operating system. Linux is something like a car engine, which is useless on its own. For an engine to be useful, we also need a vehicle. Thus, Linux is usually bundled with a distribution in order to be usable. In this case, Linux is our engine while Ubuntu is our vehicle to make use of the engine. When Ubuntu, or any other distribution, is used together with Linux, we have a functioning operating system.
So that is what Ubuntu is all about. Now, we need to get Ubuntu and Linux on our computer. As you are probably not running a Linux machine, you have to install a Virtual Machine in order to use Linux and Ubuntu.
What is a virtual machine (“VM”)?
Simply put, it is a computer inside of your computer! That is how we are able to run Linux and Ubuntu on our computers. Now that we’ve roughly understood the technicality of the process, I shall walk you through the entire process. 😀
Before we begin, find out more about Tezos here!
Firstly, we have some hardware requirements that you have to meet for the process to run smoothly:
- Ram: Minimal 8GB
- Storage: At least 100GB (SSD is strongly recommended)
- Good Internet Connection
Next up is the list of steps to set up your Virtual Machine:
1. Download virtual box
2. Download Ubuntu desktop 18.4 LTS
3. Run VirtualBox and create a new Virtual Machine
4. Follow the configuration listed below:
Name and operation system
Version: Ubuntu (64-bit)
Memory size: 8GB (If your hardware has less than 8GB of RAM, change the setting to 3GB)
Create a virtual hard disk now
Hard disk type
VirtualBox Disk Image
Storage on physical hard disk
File location and size
5. Right-click on your newly-created virtual box and click settings. Click ‘system’, select the Processor tab and change the amount of processors to more than 1 CPU (but do not use all the CPU, we recommend 2) and click OK. This is like giving your VM (a.k.a virtual box) more brains.
Setting it to 2 CPU
6. Start the Virtual Box and select the Ubuntu ISO you have downloaded.
7. Click Install Ubuntu
8. Follow the configuration listed below and click ‘install now’
Updates and other software
Download updates while installing Ubuntu
Erase disk and install Ubuntu
After your VM is all set up, it’s time to do the fun stuff!
So now in your VM, we are running an Ubuntu machine. We now have a computer inside our computer! To enter the ‘terminal’, which is the command line interface that I was talking about earlier, simply right click inside your VM and select ‘open terminal’.
You should see something like this:
Now, we are going to install the Tezos node, so follow me closely!
*Should you forget your password to your Virtual Machine, follow these instructions.
Step 1: Set up a Tezos node
At this step, we are installing all the necessary packages and drives to install the Tezos node by entering these commands into the terminal.
1. sudo apt-get update (update your ubuntu system)
2. sudo apt install -y rsync git m4 build-essential patch unzip bubblewrap wget (install libraries)
3. wget https://github.com/ocaml/opam/releases/download/2.0.5/opam-2.0.5-x86_64-linux (download the opam compiler)
4. sudo cp opam-2.0.5-x86_64-linux /usr/local/bin/opam (copy the opam compiler into the bin folder)
5. sudo chmod a+x /usr/local/bin/opam (give permissions)
6. git clone https://gitlab.com/Tezos/Tezos.git (fetch the tezos folder from gitlab)
7. cd Tezos (change directory to Tezos)
8. opam init --bare
At command no. 8, the client will prompt you to answer 2 questions, just enter ‘n’ for both of them.
9. make build-deps
When you run command no. 9, the client will tell you there is an error ‘No repository Tezos found’, which you can ignore.
10. eval $(opam env)
12. export PATH=~/Tezos:$PATH
13. source ./src/bin_client/bash-completion.sh
14. export TEZOS_CLIENT_UNSAFE_DISABLE_DISCLAIMER=Y
Some important things to take note of to ensure that the subsequent steps can be carried out smoothly:
- Whenever you are executing a command, make sure you are in this directory that is in purple (~/Tezos). Type cd tezos if you are not in the tezos folder in the terminal.
- If the file you want to point to is at other locations, always start your path with “~” (this is the home directory)
E.g. ~/Downloads this will point to home > Downloads
- The screenshot below shows the folder that you have cloned from Gitlab and these are all the script files that are used to interact with Tezos blockchain. This folder can be found under the “Tezos” folder by clicking on the “files” icon (make sure you have the baker, endorser, node file).
If you get something like this on the screenshot shown below after running a command, it means the command has a wrong syntax or wrong directory.
Step 2: Generate identity
Next, we have to generate an identity for our node. This step is akin to creating an account on a website, whereby we generate a new identity to interact with other nodes.
./tezos-node identity generate
Step 3: Configure network
Now, Tezos supports multi-network nodes. This means that you can connect to the mainnet and testnet without having to set up multiple nodes! It is helpful as you can perform operations in Tezos on the mainnet while experimenting with features on the testnet- all on one node! You can read more about it in this link: http://tezos.gitlab.io/user/multinetwork
However, I will not go in depth on this in today’s guide as it is not necessary. Hence, this is just for your own reading pleasure should you be interested in setting up a multinetwork node.
By default, your node is now connected to the mainnet. This is the ‘real’ network that is being used which involves the transactions of Tez tokens with real value. If you are ready to perform transactions or bake on the mainnet, you may proceed to the next step. However, if you are new to Tezos and want to experiment with it before moving on to the mainnet, you can configure your network to connect to carthagenet, which is the testnet for Tezos whereby all tokens are generated. For the purpose of this guide, I will be connecting to carthagenet.
./tezos-node config init --network carthagenet
This configures your network to carthagenet. If you are already on carthagenet and want to switch to mainnet instead, simply type “mainnet” instead of “carthagenet” in the above command.
Step 4: Import snapshot
Next, we have to import a snapshot. Importing a snapshot is like going to a particular time-stamp in the blockchain, and then syncing up with the blockchain from that time. This makes syncing up much faster as you will not have to sync up with the entire blockchain, which may take very long to do if the blockchain has grown very large, perhaps even taking days or weeks. First, you have to download a snapshot file.
The links provided below are the snapshot files for mainnet and carthagenet on the date of the release of this blog post. If you would like to receive a more updated snapshot file, feel free to contact us at [email protected], and we will gladly export one for you.
Take note that you have to download the file by using the browser inside the Virtual Machine in order to save the file to your VM.
Mainnet snapshot file (27 Apr 2020): https://drive.google.com/file/d/1guL-RnnCoCvk0ywxbZxSjzyF6dQZNpKE/view?usp=sharing
Carthagenet snapshot file (27 Apr 2020): https://drive.google.com/file/d/16ygYz-Wydy5JShcwnPYHr_2Rra5iu2Ip/view?usp=sharing
Your snapshot file should usually be in your Downloads folder in the Ubuntu, (~/Downloads).
After you have downloaded your snapshot file, you can
Run: ./tezos-node snapshot import <path to snapshot file>
When in doubt, use ls to find the file you are looking for.
If you ever need to import a newer snapshot, you have to remove all the files in ~/.tezos-node first (except for identity.json). You can access and remove the files by running:
1. Cd .tezos-node (when in home directory)
3. Rm -r <file/folder name>
Step 4.1: Export snapshot
There may be times when you want to export a snapshot for your own future use, such as when your node gets corrupted and you have to import another snapshot. It may be much more convenient to have an updated snapshot file on hand. Hence, this is an optional step and is not needed for you to sync up to the blockchain. To do so, your node must already be synced up to the blockchain. If you have not done so, please proceed to step 5 first.
./tezos-node snapshot export –block <block hash> <destination folder + filename.full>
For example: ./tezos-node snapshot export –block BKhwieudhwxduifhqieufdjeij WUDY93n ~/Downloads/latestsnapshotfile.full.
To view the block hash,
Run: ./tezos-client rpc get /chains/main/blocks/head
You should see this:
With this command, we have fetched the latest operations that have taken place on the blockchain. The block hash we are looking for is the one that says “branch”.
Step 5: Sync node with the blockchain
nohup ./tezos-node run --rpc-addr 127.0.0.1 --net-addr 127.0.0.1:<Port> > node.out &
This command allows your node to sync up with the blockchain by reaching the latest block in the chain.
Note that when selecting the port, select any number from 1025 to 65000, except for 8732 and 9732.
<nohup> is a command to ignore the hangup (HUP) signal, which basically directs the output that would normally go onto the terminal into a separate file. In this case, when we add > node.out, we are directing the output into a file called node.out.
So, to view the last few outputs of the file and check for any errors, run:
tail -f node.out
You should see this:
Press Ctrl+C to exit log.
But if you see this:
It means that the port you have chosen is currently being used. To fix this issue, we need to check for the process number of the node sync command, and kill the process, before starting the command again using a different port.
To see a list of all the processes you have run, you can
Run: ps aux | grep ./tezos
Additionally, if the command you have run does not show up here, it means there was an error in the command and the command was not executed. The process number is seen on the second column from the left.
To kill a process, run: kill -15 <process number>.
If you ever want to shut down your VM, you have to kill the node syncing process using this command as well to prevent any possible corruption to your snapshot data.
Then, run: ./tezos-client bootstrapped to check if your node is synced with the blockchain. When you see the message Bootstrapped, your tezos node is synced with the blockchain and you may now perform operations on the blockchain.
Congratulations on setting up a node! However, there’s much more to be done. Stay tuned for an upcoming blogpost where I will teach you how to use commands to connect your ledger nano, perform transactions, bake, endorse and much, much more on the tezos-node that you have set up! Remember to leave a like and share this blogpost with your friends!