DEV Community

smith@mcf.rocks
smith@mcf.rocks

Posted on • Updated on

Dusk - Running a Local Node

Run a local node on your machine, give yourself some coins, create two wallets and transfer coins... in under 10 minutes.

You will need Ubuntu 22.04 LTS (20.04 doesn't have the required libraries) and then clone the rusk github repo and build:

# git clone https://github.com/dusk-network/rusk.git
# cd rusk
# make
Enter fullscreen mode Exit fullscreen mode

There will now be a binary:

# ./target/release/rusk -V
rusk 0.7.0-rc.0 (cbd5c504 2023-12-22)
Enter fullscreen mode Exit fullscreen mode

Copy consensus keys:

# cp examples/consensus.keys ~/.dusk/rusk/consensus.keys
Enter fullscreen mode Exit fullscreen mode

Generate the genesis state. It uses the .toml file to create the binary .state file, we will do this again with coins in a moment, but for now just to show how it works:

# cargo r --release -p rusk -- recovery-state \
  --init examples/genesis.toml -o /tmp/example.state
Enter fullscreen mode Exit fullscreen mode

And run the node:

# export DUSK_CONSENSUS_KEYS_PASS=password 
# cargo r --release -p rusk -- -s /tmp/example.state
Enter fullscreen mode Exit fullscreen mode

You will see a bunch of output on the console, and if you check in another session, you will see port 8080 listening.

# netstat -tlpn | grep target
tcp        0      0 127.0.0.1:8080          0.0.0.0:*               LISTEN      77261/target/releas
Enter fullscreen mode Exit fullscreen mode

note: the 127.0.0.1 means the port (8080) will only accept connections from that server.

Stop the process and have it listen on a specific port:

# export DUSK_CONSENSUS_KEYS_PASS=password 
# ./target/release/rusk -s /tmp/example.state \
  --http-listen-addr 0.0.0.0:4321
Enter fullscreen mode Exit fullscreen mode

And observe:

# netstat -tlpn | grep target
tcp        0      0 0.0.0.0:4321            0.0.0.0:*               LISTEN      114057/./target/rel
Enter fullscreen mode Exit fullscreen mode

note: the 0.0.0.0 indicates the port accepts connections from anywhere (firewall permitting).

Can't do much without a wallet. Go back to home directory, clone the wallet-cli github repo and build:

# git clone https://github.com/dusk-network/wallet-cli.git
# cd wallet-cli/
# make build
# cd target
# cd release
# ./rusk-wallet -V
Dusk Wallet CLI 0.20.1
Enter fullscreen mode Exit fullscreen mode

We need to connect the wallet to a running node, in this case our local node:

# ./target/release/rusk-wallet \
  --state http://127.0.0.1:4321 \
  --prover http://127.0.0.1:4321
Enter fullscreen mode Exit fullscreen mode

Select the recover wallet option and enter the 12 words:

cost hungry lounge anger hint cheap buddy across road excuse vendor area

it's deterministic, so the first address will be:

471s2wnF6e5rEv3d6DgSmRHR5mjJGvXTitueNSMGDRV2U9WzhZHRHLJZNbNPZeVAoaGvtwoxRc4R8urC7oNeAueY
Enter fullscreen mode Exit fullscreen mode

You will note the balance is zero.

We need to fund the wallet, to do that we stop the node and generate the initial state again:

# rm /tmp/example.state
# cd ~/rusk
# vi examples/genesis.toml
Enter fullscreen mode Exit fullscreen mode

Add these lines to give initial balance of 100,000:

[[balance]]
address = '471s2wnF6e5rEv3d6DgSmRHR5mjJGvXTitueNSMGDRV2U9WzhZHRHLJZNbNPZeVAoaGvtwoxRc4R8urC7oNeAueY'
seed = 0xdead_beef
notes = [100_000_000_000_000]
Enter fullscreen mode Exit fullscreen mode

note: the last 9 zeros are decimals

Then regenerate the state:

# cargo r --release -p rusk -- recovery-state \
  --init examples/genesis.toml \
  -o /tmp/example.state
Enter fullscreen mode Exit fullscreen mode

Restart the node:

# export DUSK_CONSENSUS_KEYS_PASS=password 
# ./target/release/rusk -s /tmp/example.state \
  --http-listen-addr 0.0.0.0:4321
Enter fullscreen mode Exit fullscreen mode

In a second session, start the wallet as before:

# cd ~/wallet-cli
# ./target/release/rusk-wallet \
  --state http://127.0.0.1:4321 \
  --prover http://127.0.0.1:4321
Enter fullscreen mode Exit fullscreen mode

Recover the wallet, with our words:

cost hungry lounge anger hint cheap buddy across road excuse vendor area

You will see a balance of 100,000

We now need to fake a second wallet, open a third session and create another linux user account:

# sudo useradd -m testdusk
# sudo usermod --shell /bin/bash testdusk
Enter fullscreen mode Exit fullscreen mode

Copy the wallet directory to the new user and chown it:

# cp -R wallet-cli /home/testdusk/
# chown -R testdusk:testdusk /home/testdusk
Enter fullscreen mode Exit fullscreen mode

Create a new wallet:

# su - testdusk
# cd wallet-cli
# ./target/release/rusk-wallet \
  --state http://127.0.0.1:4321 \
  --prover http://127.0.0.1:4321
> Create a new wallet
Enter fullscreen mode Exit fullscreen mode

This will give you some new wallet with an address, with zero balance.

Copy the new address, and on the original wallet, send 100 coins to the new address.

> Transfer Dusk
// use suggested gas limit and price and proceed
Enter fullscreen mode Exit fullscreen mode

You will see the balance is less by 100 plus a very small amount for gas. Switching to the new wallet, you should see a balance of 100.

Top comments (0)