To start we need to understand what are nodes ?
Well nodes allow two things:
- Exchange of information about transactions
- New block creation
Nodes can connect to other nodes via static configuration (defined in the topology file which we will see later) and relays.
Relays are responsible for:
- Communication between other relays and nodes
- Broadcasting blocks
So if relays go offline, nodes will be unable to speak to each other. Hence, this is why the Cardano team IOHK offers a list of all registered relays to avoid a problem where relay nodes go offline.
Usually each node is accompanied by one or more relay nodes.
Cardano node
There are many ways to setup your own cardano node.
- Via a Daedalus wallet
- On your own computer MAC, Linux / windows (tutorial here)
- Docker image of the Cardano node
- DockerFile of the Cardano node
In this tutorial we will be choosing option 4.
DockerFile
To get started, download the DockerFile from the Github repo
This tutorial assumes you understand docker and you have docker desktop installed on your computer
Then run the command:
docker build --build-arg NODE_VERSION=1.29.0 --build-arg NODE_BRANCH=master \ --build-arg NODE_REPO="https://github.com/input-output-hk/cardano-node" .
After it has built you will see your image and then now run as root to execute commands
docker run -ti -u root <your image id>
Then install curl to install packages
apt-get updateapt-get install --yes curlcurl --silent --location https://deb.nodesource.com/setup_17.x | bash -apt-get install -yq nodejs build-essential
Once you have installed curl you will need to download a few json files
curl -O -J https://hydra.iohk.io/build/<BuildVersion>/download/1/mainnet-config.jsoncurl -O -J https://hydra.iohk.io/build/<BuildVersion>/download/1/mainnet-byron-genesis.jsoncurl -O -J https://hydra.iohk.io/build/<BuildVersion>/download/1/mainnet-shelley-genesis.jsoncurl -O -J https://hydra.iohk.io/build/<BuildVersion>/download/1/mainnet-alonzo-genesis.jsoncurl -O -J https://hydra.iohk.io/build/<BuildVersion>/download/1/mainnet-topology.json
After installing these files start the cardano-node
cardano-node run \--topology path/to/mainnet-topology.json \--database-path /db \--socket-path /db/node.socket \--port 3001 \--config path/to/mainnet-config.json
Which results in
Awesome, you have now built your very first Cardano node !
This will take awhile and you can check your progress with the slot number on https://explorer.cardano.org/en
As writing this tutorial, the current tip or the most recent slot/epoch is 310, so our Cardano node will need time to reach there.
After the node has finished running,
You can then start executing the cardano CLI command as a simple test
But before you do make sure you set the PATH of CARDANO_NODE_SOCKET_PATH
, which in our previous command was installed to db/node.socket
export CARDANO_NODE_SOCKET_PATH="/db/node.socket"
Now we can run Cardano cli
cardano-cli query tip --mainnet
For more help or video tutorial here are a few links that i’ve used which might help you.
Happy coding :)