Running a Cardano Node with Docker
Cardano is a cryptocurrency and smart contract platform that is in my opinion one of the most understated projects in the space. The uber-academic team at cardano keep their heads down and create quality software. Unfortunately, figuring out how to use it is an exercise in trial and error as there is little documentation or developer community around it compared to Ethereum or EOS. I did a couple articles earlier this year on the Cardano testnets and the CLI tool, Mallet.
Cardano Smart Contracts 101 — Testnets
Cardano 101 — Your First Contract
Unfortunately, when I began my research into connecting with the Cardano mainnet, I found that Mallet was just for the upcoming kevm and iele testnets. I had to figure out how to connect to the mainnet and send custom RPC calls to the cardano node via a custom Node.js client.
Requirements
- Ubuntu — OSX did not work for me ;(
- Git
- Docker
Fat Wallet
I found that I could download and install the Daedalus wallet application and connect to the mainnet rather easily. The wallet runs a cardano-sl node in the background that is accessible via a RESTful interface. This may be a good idea to install and play around with locally before blindly installing a docker image on a remote server.
Daedalus Wallet - Windows/OSX Version
Once you have the Wallet downloaded and synced, go ahead and add a wallet via the GUI. You will need to write down the mnemonic and add a password if you want.
Postman
I would suggest that you download the Postman application here and import the following swagger definition here. In order for your postman queries to work locally with your Daedalus wallet, you will need to turn off ssl certificate validation as the wallet uses a self-signed certificate.
Play around with with the postman collection provided by cardano and you will get an idea of the wallet => account => address relationship and other subtle aspects of the model.
Docker
Options
You can build the image or use a prebuilt image. Both options are presented below, but you will need to create the data dir.
Create Data Dir
$ mkdir cardano && cd cardano
$ mkdir data && chmod 777 data
Building Image
$ git clone https://github.com/cipherzzz/cardano-node$ cd cardano-node# Build the image locally
$ docker build -t cardano-node .
Updating an Image
# Login to docker hub
$ docker login# Tag the local build with a remote tag
$ docker tag cardano-node cipherz/cardano-node# Push the new tag to the remote
$ docker push cipherz/cardano-node
Use Existing Image
# Pull the remote built image
$ docker pull cipherz/cardano-node
Run Built/Pulled Image
# Get image id below
$ docker images# Create and run the container
$ docker run -d — name=cardano-node -v ~/cardano/data:/home/cardano/cardano-sl/state-wallet-mainnet:Z -p 127.0.0.1:8090:443 <image id>
Verify
# Curl Wallet API
$ curl -k
https://127.0.0.1:8090/api/v1/node-info# Verify wallet /data dir
$ ls ../data# Peek at Node logs
$ docker logs -f cardano-node
Maintenance
# Start/Stop Container
$ docker stop cardano-node
$ docker start cardano-node# Remove Container
$ docker ps
$ docker container rm -f <container id>
Creating a Wallet
Once you have verified the node is running, we need to create a wallet on it. Run the following command to create your wallet on your node and edit the parameters as you wish.
curl -k -X POST https://127.0.0.1:8090/api/v1/wallets \
-d ‘{ “operation”: “create”, “backupPhrase”: [<12 word mnemonic>], “assuranceLevel”: “normal”, “name”: “Test Wallet” }’ \
-H “Accept: application/json; charset=utf-8” \
-H “Content-Type: application/json; charset=utf-8”
Now that you have created a wallet, let’s list the wallets for our node. Find and write down the id param for the wallet from this response.
curl -k https://127.0.0.1:8090/api/v1/wallets
Now we need to get the accountIndex for the wallet id. Execute the following curl with the substitution of the id param. You will find an array of accounts from the response below. Write down the accountIndex param.
curl -k https://localhost:8090/api/v1/wallets/<wallet id>/accounts
We have created a wallet and noted the wallet id and the default wallet accountIndex. We will need these in order to interact with our wallet to do things like generate an address and send a transaction.
Note that you may want to transfer some ADA to this account. You will see an array of addresses from the previous
Summary
You can download the project here if you like. I hope that this helped you out and I look forward to being able to use the Mallet CLI in the near future!
My repo was forked from [here](https://github.com/TheDevKnight/cardano-sl-wallet) and thanks to @TheDevKnight for his help in getting me up and going. I also borrowed config content from [here](https://github.com/EmurgoVN/cardano_docker).