Dusk - Running a Local Node
Tags: dusk, node, crypto, rwa
Published: 2023-12-27 16:15:42

**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
```

There will now be a binary:

```
# ./target/release/rusk -V
rusk 0.7.0-rc.0 (cbd5c504 2023-12-22)
```

Copy consensus keys:

```
# cp examples/consensus.keys ~/.dusk/rusk/consensus.keys
```

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
```

And run the node:

```
# export DUSK_CONSENSUS_KEYS_PASS=password 
# cargo r --release -p rusk -- -s /tmp/example.state
```

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
```

_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
```

And observe:

```
# netstat -tlpn | grep target
tcp        0      0 0.0.0.0:4321            0.0.0.0:*               LISTEN      114057/./target/rel
```

_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
```

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
```

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
```

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
```

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

```
[[balance]]
address = '471s2wnF6e5rEv3d6DgSmRHR5mjJGvXTitueNSMGDRV2U9WzhZHRHLJZNbNPZeVAoaGvtwoxRc4R8urC7oNeAueY'
seed = 0xdead_beef
notes = [100_000_000_000_000]
```

_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
```

Restart the node:

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

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
```

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
```

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

```
# cp -R wallet-cli /home/testdusk/
# chown -R testdusk:testdusk /home/testdusk
```

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
```

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
```

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.