Running a Cardano-SL node on testnet

Because someone asked, here is the step-by-step of what I did.

Daedalus testnet wallet

You will want a Daedalus test wallet. Download and install it to your PC from here: https://testnet.iohkdev.io/cardano/get-started/testnet-wallet/

Once it starts it will sync the chain - on my 4GB Mac book pro this took 2.5 hours. Complete the steps as per the instructions on the web page and get test ADA from Faucet.

The testnet Daedalus looks different to the regular one - icon is red, and red “testnet” sticker inside - so no expensive mistakes.

As you know, Daedalus runs a node in the background, so congratulations - mission accomplished.

But what you really want to know is how to run a 24/7 node on a Linux server for the coming stake pools…

Create an account with Digital Ocean, Linode, AWS, or whoever.

Create a Ubuntu18.04 instance with 4GB RAM, 80GB storage and a static public IP address (you may have to setup the IP address after you create the instance, on AWS it’s called an elastic-ip).

Public/Private key ssh

Depending on your provider you may want to set up remote ssh access using public/private keys, and turn off ssh via a password. Only do this if you have some way of getting console access, otherwise you might be locked out forever.

On your PC do:

ssh-keygen

public key is:

cat ~/.ssh/id_rsa.pub

on server paste that into ~/.ssh/authorized_keys

If you are using the root account on server, from your PC do:

ssh root@111.222.333.444

It should go right in without a password.

On the server uncomment & change PasswordAuthentication yes to no in this file:

/etc/ssh/sshd_config

Then:

systemctl restart ssh

Check again it works from your PC. Also something like ssh abc@111.222.333.444 will not ask for password, but will reject immediately.

Create swap

To see how much swap you have do this:

swapon —show

I want 10G so I make a swap file like this:

fallocate -l 10G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
sysctl vm.swappiness=20

then edit the file /etc/fstab and add the following on the last line:

/swapfile swap swap defaults 0 0

reboot

Login, then to see if it worked:

free -h

Installation of software

Get latest everything:

apt-get update
apt-get upgrade			// takes 15m, if msg about grub, keep local.
apt-get dist-upgrade

reboot

login again, then get nix:

mkdir /etc/nix
echo "build-users-group =" > /etc/nix/nix.conf
curl https://nixos.org/nix/install | sh

then:

. /root/.nix-profile/etc/profile.d/nix.sh

Get Cardano node:

cd ~
git clone https://github.com/input-output-hk/cardano-sl.git
cd cardano-sl
git checkout master

Edit this file /etc/nix/nix.conf add these lines at the end exactly like this:

substituters         = https://hydra.iohk.io https://cache.nixos.org
trusted-substituters =
trusted-public-keys  = hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=

In the cardano-sl directory:

nix-build -A connectScripts.testnet.wallet -o connect-testnet-wallet

Run the node

Run node in foreground:

./connect-testnet-wallet

On another session observe sync, as the block data is written, takes about 2 hours:

cd ~/cardano-sl/state-wallet-testnet/db/blocks/data
watch ls -lrt1

Run the node on startup in the background

Create the file /etc/rc.local with this content:

#!/bin/bash
cd ~/cardano-sl/ ; ./connect-testnet-wallet >> ./sl.log 2>1 &

then:

chmod +x /etc/rc.local

People will say that isn’t “proper” but it works, do a reboot and check it’s running.

See the process:

ps auxww | grep cardano

Tail the log:

tail -f ./cardano-sl/sl.log

Later we can make it so if the node falls over it is automatically restarted.

Talking to the node

There is an API to talk to the node, eg:

cd ~
cd cardano-sl
curl -v —cacert ./state-wallet-testnet/tls/client/ca.crt --cert ./state-wallet-testnet/tls/client/client.crt --key ./state-wallet-testnet/tls/client/client.key https://localhost:8090/api/v1/wallets

This called the wallet API, to get a list of wallets - obviously there are none - and there was a lot of noise. Without the -v switch we just get the output without the noise.

I make a wallet like this:

curl -s -X POST https://localhost:8090/api/v1/wallets -H 'Accept: application/json; charset=utf-8' -H 'Content-Type: application/json; charset=utf-8' --cacert /root/cardano-sl/state-wallet-testnet/tls/client/ca.crt --cert /root/cardano-sl/state-wallet-testnet/tls/client/client.crt --key /root/cardano-sl/state-wallet-testnet/tls/client/client.key -d '{"name":"TestWallet2","operation":"create","backupPhrase":["note","behind","pause","hand","trigger","august","educate","table","salad","divorce","fade","glimpse"],"spendingPassword":"8a508a145bf4b4e324f54626a81c0b2a93823f7465b6eef9a0108a51f88788c8","assuranceLevel":"normal"}'  

>> {
   "status" : "success",
   "data" : {
      "assuranceLevel" : "normal",
      "spendingPasswordLastUpdate" : "2019-03-21T20:40:02.641728",
      "hasSpendingPassword" : true,
      "syncState" : {
         "data" : null,
         "tag" : "synced"
      },
      "balance" : 0,
      "createdAt" : "2019-03-21T20:40:02.641728",
      "id" : "2cWKMJemoBajgtUAcVTh2JCCC91pGkVWvW8RmesSk2gXFoL6gRcDs59oEVdoFVD5Kyi21",
      "name" : "TestWallet2"
   },
   "meta" : {
      "pagination" : {
         "page" : 1,
         "perPage" : 1,
         "totalEntries" : 1,
         "totalPages" : 1
      }
   }
}

Now we can see the wallet:

curl -s --cacert /root/cardano-sl/state-wallet-testnet/tls/client/ca.crt --cert /root/cardano-sl/state-wallet-testnet/tls/client/client.crt --key /root/cardano-sl/state-wallet-testnet/tls/client/client.key https://localhost:8090/api/v1/wallets 

>> {
   "data" : [
      {
         "syncState" : {
            "tag" : "synced",
            "data" : null
         },
         "createdAt" : "2019-03-21T20:40:02.641728",
         "name" : "TestWallet2",
         "spendingPasswordLastUpdate" : "2019-03-21T20:40:02.641728",
         "hasSpendingPassword" : true,
         "id" : "2cWKMJemoBajgtUAcVTh2JCCC91pGkVWvW8RmesSk2gXFoL6gRcDs59oEVdoFVD5Kyi21",
         "balance" : 0,
         "assuranceLevel" : "normal"
      }
   ],
   "status" : "success",
   "meta" : {
      "pagination" : {
         "totalPages" : 1,
         "totalEntries" : 1,
         "page" : 1,
         "perPage" : 10
      }
   }
}

The balance is zero.

Now generate address:

curl -s --cacert /root/cardano-sl/state-wallet-testnet/tls/client/ca.crt --cert /root/cardano-sl/state-wallet-testnet/tls/client/client.crtt/cardano-sl/state-wallet-testnet/tls/client/client.key POST https://localhost:8090/api/v1/addresses -H 'Accept: application/json; charset=utf-8' -H 'Content-Type: application/json; charset=utf-8' -d '{"accountIndex":2147483648,"spendingPassword":"8a508a145bf4b4e324f54626a81c0b2a93823f7465b6eef9a0108a51f88788c8","walletId":"2cWKMJemoBajgtUAcVTh2JCCC91pGkVWvW8RmesSk2gXFoL6gRcDs59oEVdoFVD5Kyi21"}'

>> {
	"data": {
		"id": "37btjrVyb4KGG7zYWz9h8Hvad11aG6LiRwdBXnqe5yRQAFPh8tHksGcM1CyMcmUfFN7mLKAnWthFyBH5MdpwgDQXikWEkMAm9KFZQv5ZQMyzkutrmT",
		"used": false,
		"changeAddress": false,
		"ownership": "isOurs"
	},
	"status": "success",
	"meta": {
		"pagination": {
			"totalPages": 1,
			"page": 1,
			"perPage": 1,
			"totalEntries": 1
		}
	}
}

This is the generated address:

37btjrVyb4KGG7zYWz9h8Hvad11aG6LiRwdBXnqe5yRQAFPh8tHksGcM1CyMcmUfFN7mLKAnWthFyBH5MdpwgDQXikWEkMAm9KFZQv5ZQMyzkutrmT

I go to my Daedalus test wallet and send 14 ADA to the address, then get the wallet details again to check balance:

curl -s --cacert /root/cardano-sl/state-wallet-testnet/tls/client/ca.crt --cert /root/cardano-sl/state-wallet-testnet/tls/client/client.crt --key /root/cardano-sl/state-wallet-testnet/tls/client/client.key https://localhost:8090/api/v1/wallets 

>> {
   "status" : "success",
   "data" : [
      {
         "createdAt" : "2019-03-21T20:40:02.641728",
         "spendingPasswordLastUpdate" : "2019-03-21T20:40:02.641728",
         "syncState" : {
            "data" : null,
            "tag" : "synced"
         },
         "id" : "2cWKMJemoBajgtUAcVTh2JCCC91pGkVWvW8RmesSk2gXFoL6gRcDs59oEVdoFVD5Kyi21",
         "hasSpendingPassword" : true,
         "balance" : 14000000,
         "name" : "TestWallet2",
         "assuranceLevel" : "normal"
      }
   ],
   "meta" : {
      "pagination" : {
         "totalEntries" : 1,
         "totalPages" : 1,
         "perPage" : 10,
         "page" : 1
      }
   }
}

The balance is 14.

There is a whole API here: https://cardanodocs.com/technical/wallet/api/v1/

Hope it helps you.

8 Likes

I really appreciate what you have done here.
I have made some progress and I am certainly learning as I go. I am having some trouble with - AND I FIGURED IT OUT !

– En Dash ## U+2013 before –cacert

should be --cacert

root@ubuntu-s-2vcpu-4gb-tor1-01:~/cardano-sl# curl -v —cacert ./state-wallet-testnet/tls/client/ca.crt --cert ./state-wallet-testnet/tls/client/client.crt --key ./state-wallet-testnet/tls/client/client.key https://localhost/api/v1/wallets

1 Like

An other one

cd ~/cardano-sl/ ; ./connect-testnet-wallet >> ./sl.log 2>1 &

should be

cd ~/cardano-sl/ ; ./connect-testnet-wallet >> ./sl.log 2>&1 &

Cheers,

1 Like

edit
I have gotten through it with some help from Priyank
I finally sent test ADA to my test wallet!:fireworks::fireworks:

We (Priyank :wink:) found another prtt s/b prt

Thanks for sharing this awesome research. I absolutely loved it as the process is very well explained covering all the minor issues. However, I was wondering. What if someone does not have his account on the conventional server and instead he is using the managed DigitalOcean, Linode, AWS server, etc. As their are companies like Cloudways who are providing the managed services of these famous hosts.

1 Like

I used Digital Ocean!
In fact if you sign up you get $100 credit!
( and if you use https://m.do.co/c/a7ace014e2f4 I get $25 too!)

you do NOT want to be using the root user to 1) ssh or 2) run an application

you should also DISABLE ssh password authentication in favour of SSH keys

learn about securing ssh here: https://infosec.mozilla.org/guidelines/openssh

1 Like

I got the ssh key set up. I also have 2FA on the account.
I think you are referring to this part
root@ubuntu-s-2vcpu-4gb-tor1-01:~/cardano-sl#

How would you suggest I have it set up?

Are you planning to lease server space?

Yes. I’ve got a few colo servers and plan on expanding to a rack.

It is never good practice to run applications as the root user. Especially those which open network connections. If someone finds an exploit in that code now they can execute things as the root user (depending on the exploit).

this is what i do:

adduser appname
groupadd -g okssh
usermod -G okssh appname

edit /etc/ssh/sshd_config
add
AllowGroups okssh

Then ssh as/to and run the node as appname

appname is whatever username you want to create.

1 Like

Maybe a dumb question, but how do I know when it’s finished syncing?
On Ubuntu 18.04 and watch ls -lrt1 is not longer updating even though ./connect-testnet-wallet continues to output messages.

edit: answered my own question after looking through the docs

curl -X GET https://localhost:8090/api/v1/node-info -H 'Accept: application/json; charset=utf-8' -H 'Content-Type: application/json; charset=utf-8' --cacert /root/cardano-sl/state-wallet-testnet/tls/client/ca.crt --cert /root/cardano-sl/state-wallet-testnet/tls/client/client.crt --key /root/cardano-sl/state-wallet-testnet/tls/client/client.key