How to Set Up a Cardano Node?
What is the Cardano node?
Cardano node is the key element inside the blockchain framework that upholds the entire network. Alternatively, the Cardano blockchain network consists of nodes interconnected to drive data exchanges and validate the transactions via the POS consensus mechanism. The definition of consensus differs from network to network. The Cardano network is supported by Ouroboros protocol. To join and contribute to the blockchain platform, users run Cardano nodes. And, in the context of Alonzo testnet, Cardano establishes and manages separate nodes, aside from the mainnet, which makes it easy for the miners to test and verify the ledger.
How does Cardano Node work?
Cardano node acts exactly how banks and authorized entities work in the centralized financial system. It’s basically a service node that authenticates the interaction within the network to impart complete transparency. Nodes further undertake the responsibility to validate transactions and produce blocks.
Cardano produces individually verifiable blocks in a peer-to-peer protocol. The platform employs a robust block-producing system to develop the blockchain. Meanwhile, consensus adds security layers and decides who can participate.
Validation of transactions is a method in which slot leaders ascertain the needed amount for the senders. Their obligation also includes the determination of transactional parameters. Once confirmed, leaders record the data assuming it is an active block, to add it later after cross-verification.
How to set up the Cardano node in simple steps?
Since we have all the crucial information, such as Cardano and Cardano node definition, it’s time to discuss how to set up the Cardano node. We will explain installing the node and running it into multiple operating systems from the source node.
You will need the following for component setup:
Any latest operating system, whether Windows, Linux, or MacOS.
Dual-core CPU, 8GB RAM, and 10GB disk space.
Note:- Do not use a firewalled network. We recommend using TCP/IP 3000 and 3001 to establish an uninterrupted connection between the nodes.
Select the desired operating system
The section is entirely dedicated to explaining Cardano node setup into the Linux operating system. We will go through the download, compilation, and installation process in sheer steps.
Step 1: OS (operating system) dependencies Installation
In order to download and then built the source code, you should have the given tools and packages on the Linux system:
the version control system git
the gcc C-compiler
C++ support for gcc
developer libraries for the arbitrary precision library gmp
developer libraries for the compression library zlib
developer libraries for systemd
developer libraries for ncurses
ncurses compatibility libraries
the Haskell build tool cabal
the GHC Haskell compiler (version must be 8.10.4 or above)
If you are working on Redhat, Centos, and Fedora, then type the command:
sudo yum update -y sudo yum install git gcc gcc-c++ tmux gmp-devel make tar xz wget zlib-devel libtool autoconf -y sudo yum install systemd-devel ncurses-devel ncurses-compat-libs -y
And, for Debian or Ubuntu, type the following command:
sudo apt-get update -y sudo apt-get install automake build-essential pkg-config libffi-dev libgmp-dev libssl-dev libtinfo-dev libsystemd-dev zlib1g-dev make g++ tmux git jq wget libncursesw5 libtool autoconf -y
Furthermore, the yum or apt-get package manager won’t be compatible with the different flavors of Linux. In that plot, you need to choose a suitable different package manager after a thorough examination.
Step 2. GHC and Cabal installation
GHC Stands for Glassglow Haskell Compiler and Cabal for Common Architecture for Building Applications and Libraries. Using ghcup, one can conveniently and quickly install GHC and Cabal.
Type the given command to install and use ghcup:
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
Now, follow the further instructions properly to equip essential input to the installer. When done right, you will have ghc and cabal installed into your operating system.
*Additional instruction: Consider restarting your PC once the ghc is installed as ghcup tries to detect the shell and direct users to add it to the existing environment variables.
You can also ensure if the ghcup is installed properly. For doing so, you need to type the command prompt- ghcup –version in the terminal. The result will appear like this:
The GHCup Haskell installer, version v0.1.14.1
Although ghcup automatically installs the latest ghc version, most blockchain infrastructure experts suggest ghc 8.10.4 to worldwide users. Hence, we will stick to the recommendation and use ghcup to install and swap to the latest version. Here’s the command:
ghcup install ghc 8.10.4 ghcup set ghc 8.10.4
The next step is to validate the versions of ghc and cabal.
Verify ghc version using:
The input will display something similar to this:
The Glorious Glasgow Haskell Compilation System, version 8.10.4
Checking the cabal version:
The command will display something similar to this:
cabal-install version 126.96.36.199
compiled using version 188.8.131.52 of the Cabal library
Note: Before you jump to the next step of Cardano node installation, double-check that your installed version should align with the recommended version. No issues will occur unless you have skipped a few of the previous steps.
Step3: Download and compilation
The section will guide you on the creation of a working directory used to store source-code and builds. Run the command:.
mkdir -p ~/cardano-src cd ~/cardano-src
After this, you need to download, compile, and then install libsodium.
Use the command:
git clone https://github.com/input-output-hk/libsodium cd libsodium git checkout 66f017f1 ./autogen.sh ./configure make sudo make install
We will add the given command into the bottom part of configuration files based on the shell application you use (~/.zshrc or ~/.bashrc). It helps the compiler to determine the libsodium installation in the system.
export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
Again, depending on your preferred shell application, we have to reload the shell profile to explore the new variables. For that, start typing
source ~/.bashrc or source ~/.zshrc.
Finally, we are all set to set up the Cardano node. However, it’s crucial to ensure that we are back to the initial stage of the working directory.
Then, download the repository: Cardano-node
git clone https://github.com/input-output-hk/cardano-node.git cd cardano-node git fetch --all --recurse-submodules --tags
Get the latest tag commit on the git repository:
git checkout tags/1.27.0
Step 4: Configuration of build option
You must use the same ghc version that we already installed. By doing so, it prevents defaulting the ghc’s system version.
cabal configure --with-compiler=ghc-8.10.4
Now, to use the Libsodium, you will need to revamp the local project:
echo "package cardano-crypto-praos" >> cabal.project.local echo " flags: -external-libsodium-vrf" >> cabal.project.local
Step 5: Building up and installation of the node
You can construct a Haskell-based Cardano-node as it produces feasible binaries.
cabal build all
Proceed to install the generated node and CLI commands into ~/.local/bin directory.
mkdir -p ~/.local/bin cp -p "$(./scripts/bin-path.sh cardano-node)" ~/.local/bin/ cp -p "$(./scripts/bin-path.sh cardano-cli)" ~/.local/bin/
Don’t forget to add the command right below the Shell profile. The command helps the associated terminal to identify cardano-node and cardano-cli as global commands.
Once you saved the shell profile, reload it by writing: source ~/.zshrc or source ~/.bashrc (shell script depends on which application you choose)
Now, check the installed version.
cardano-cli –version cardano-node –version
Kudos! You are done with the installation of Cardano components in Linux.
Here, we will discover how to set up the Cardano node into MacOS. We will go through the download, compilation, and installation process. (Useful for Intel-based hardware).
Step 1: OS (operating system) dependencies installation
To download and then built the source code, you should have the given tools and packages on the MacOS system:
Xcode – The Apple Development IDE and SDK/Tools
Xcode Command Line Tools, you can install it by typing xcode-select –install in the terminal.
Homebrew – The Missing Package Manager for MacOS (or Linux)
Step 2: Homebrew packages installation
For the proper compilation of both cardano-node and cardano-cli, you need to install libraries via brew:
brew install jq brew install libtool brew install autoconf brew install automake brew install pkg-config
Other steps are the same as what we did for Linux. (Refer to step 3 to the final step).
Windows Cardano-node installation is quite similar to MacOs and Linux. All you need is to use WSL (windows subsystem for Linux) to transform the windows environment into Linux.
After that, you can follow the Linux guide to set up and install the Cardano node.
How to run the Cardano Node?
Running the Cardano node requires the implementation of the run command. Type the following in the terminal.
cardano-node run \ --topology path/to/mainnet-topology.json \ --database-path path/to/db \ --socket-path path/to/db/node.socket \ --host-addr x.x.x.x \ --port 3001 \ --config path/to/mainnet-config.json