2023-08-09 12:36:03 +02:00
# nwaku-compose
2023-11-07 19:01:28 +01:00
Ready to use docker-compose to run your own [nwaku ](https://github.com/waku-org/nwaku ) full node:
2023-11-01 16:45:46 +01:00
* nwaku node running relay and store protocols with RLN enabled.
2023-11-01 16:51:30 +01:00
* Simple frontend to interact with your node and the network, to publish and receive messages.
* Grafana dashboard for advanced users or node operators.
* Requires `docker-compose` and `git` .
2023-08-09 12:36:03 +02:00
2024-10-14 16:17:56 +11:00
## Setup and Run
2023-11-07 19:01:28 +01:00
2024-10-14 16:17:56 +11:00
### 📝 0. Prerequisites
2023-11-07 19:01:28 +01:00
You need:
2025-07-16 08:51:15 +02:00
* Linea Sepolia HTTP endpoint. Get one free from [Infura ](https://www.infura.io/ ).
* Linea Sepolia account with some balance < 0.01 Eth .
* You can get some Linea Sepolia [here ](https://www.infura.io/faucet/sepolia )
* If you have ETH on Sepolia, it can be bridged to Linea Sepolia [here ](https://bridge.linea.build/native-bridge ).
2023-11-07 19:01:28 +01:00
* A password to protect your rln membership.
2024-02-02 07:03:49 +11:00
`docker-compose` [will read the `./.env` file ](https://docs.docker.com/compose/environment-variables/set-environment-variables/#additional-information-3 ) from the filesystem. There is `.env.example` available for you as a template to use for providing the above values. The process when working with `.env` files is to copy the `.env.example` , store it as `.env` and edit the values there.
2023-11-13 12:58:23 +01:00
```
cp .env.example .env
2023-11-13 16:06:39 +01:00
${EDITOR} .env
2023-11-13 12:58:23 +01:00
```
2023-11-13 16:06:39 +01:00
Make sure to **NOT** place any secrets into `.env.example` , as they might be unintentionally published in the Git repository.
2024-10-14 16:17:56 +11:00
### EXPERIMENTAL - Use wizard script
2024-02-02 07:03:49 +11:00
2024-10-14 16:17:56 +11:00
Run the wizard script.
Once the script is done, the node will be started for you, so there is nothing else to do.
The script is experimental, feedback and pull requests are welcome.
```
./setup_wizard.sh
```
### 🔑 1. Register RLN membership
2023-11-07 19:01:28 +01:00
2025-07-17 14:05:38 +05:30
> **Note:** If upgrading from less than v0.36.0, run the following commands before proceeding with the registration:
>
> ```sh
> sudo rm -r rln_tree
> sudo rm keystore/keystore.json
> ```
The RLN membership is your access key to The Waku Network. Its registration is done on-chain, allowing your `nwaku` node to send messages in a decentralized and private way, respecting some [rate limits ](https://rfc.vac.dev/spec/64/#rate-limit-exceeded ). Other peers won't relay messages that exceed the rate limit.
#### Recommended: Register via rln.waku.org
To register for RLN membership and generate your keystore:
1. Visit [https://rln.waku.org ](https://rln.waku.org ).
2. Follow the instructions to register your membership and generate a `keystore.json` file.
3. Download the generated `keystore.json` and place it in the `keystore/` directory of your `nwaku-compose` setup (i.e., at `keystore/keystore.json` ).
#### Alternative: Register locally
You can also register your membership using the provided script, which will store it in `keystore/keystore.json` .
Note that if you just want to relay traffic (not publish), you don't need to perform the registration.
2023-11-10 08:56:34 +01:00
2025-07-16 08:51:15 +02:00
Before registering you need to mint and approve the tokens to pay for the registration.
The simplest way is using Foundry's [cast ](https://getfoundry.sh/ ) tool, which you can install with:
```
curl -L https://foundry.paradigm.xyz | bash
foundryup
```
Mint the token used to pay for RLN Membership registration from your Linea Sepolia account (This is a generic ERC20 token used for testnet only):
The amount of "5000000000000000000" is how much is needed to register with a `rln-relay-user-message-limit` of 100
```
cast send $TOKEN_CONTRACT_ADDRESS "mint(address,uint256)" $ETH_TESTNET_ACCOUNT 5000000000000000000 --private-key $ETH_TESTNET_KEY --rpc-url $RLN_RELAY_ETH_CLIENT_ADDRESS
```
Approve the RLN contract to spend tokens on behalf of your account:
```
cast send $TOKEN_CONTRACT_ADDRESS "approve(address,uint256)" $RLN_CONTRACT_ADDRESS 5000000000000000000 --private-key $ETH_TESTNET_KEY --rpc-url $RLN_RELAY_ETH_CLIENT_ADDRESS
```
2025-07-17 14:05:38 +05:30
This command will register your membership and store it in `keystore/keystore.json` :
2023-11-07 19:01:28 +01:00
2023-11-01 16:45:46 +01:00
```
2023-11-07 19:01:28 +01:00
./register_rln.sh
2023-08-09 12:36:03 +02:00
```
2025-02-17 20:17:34 +11:00
### 💽 2. Select DB Parameters
2024-10-14 16:17:56 +11:00
Waku runs a PostgreSQL Database to store messages from the network and serve them to other peers.
To prevent the database to grow indefinitely, you need to select how much disk space to allocate.
You can either run a script that will estimate and set a good value:
```
./set_storage_retention.sh
```
Or select your own value. For example, `50GB` :
```shell
echo "STORAGE_SIZE=50GB" >> .env
```
2025-02-17 20:17:34 +11:00
Depending on your machine's memory, it may be worth allocating more memory to the Postgres container to ensure heavy queries are served:
```shell
./set_postgres_shm.sh
```
Or select your own value manually, for example, `4g` :
```shell
echo "POSTGRES_SHM=4g" >> .env
```
2024-10-14 16:17:56 +11:00
### 🖥️ 3. Start your node
2023-11-07 19:01:28 +01:00
2024-03-14 10:06:08 +01:00
Start all processes: nwaku node, database and grafana for metrics. Your [RLN ](https://rate-limiting-nullifier.github.io/rln-docs/what_is_rln.html ) membership is loaded into nwaku under the hood.
2023-10-03 15:34:52 +03:00
```console
2023-11-01 16:45:46 +01:00
docker-compose up -d
2023-10-03 15:34:52 +03:00
```
2024-10-14 16:17:56 +11:00
⚠️ The node might take a few minutes the very first time it runs because it needs to build locally the RLN community membership tree.
###🏄🏼♂️ 4. Interact with your nwaku node
2023-10-03 15:34:52 +03:00
2024-07-03 18:35:45 +02:00
* See [localhost:3000 ](http://localhost:3000/d/yns_4vFVk/nwaku-monitoring ) for node metrics.
* See [localhost:4000 ](http://localhost:4000 ) for a nice frontend to chat with other users.
2023-11-07 19:01:28 +01:00
2024-07-03 18:35:45 +02:00
**📬 4. Use the REST API**
2023-11-07 19:01:28 +01:00
Your nwaku node exposes a [REST API ](https://waku-org.github.io/waku-rest-api/ ) to interact with it.
2023-10-03 15:34:52 +03:00
2023-11-07 19:01:28 +01:00
```
# get nwaku version
curl http://127.0.0.1:8645/debug/v1/version
# get nwaku info
curl http://127.0.0.1:8645/debug/v1/info
```
2023-11-07 19:14:56 +01:00
**Publish a message to a `contentTopic` **. Everyone subscribed to it will receive it. Note that `payload` is base64 encoded.
2023-11-07 19:01:28 +01:00
```
curl -X POST "http://127.0.0.1:8645/relay/v1/auto/messages" \
-H "content-type: application/json" \
2024-03-04 17:19:52 -06:00
-d '{"payload":"'$(echo -n "Hello Waku Network - from Anonymous User" | base64)'","contentTopic":"/my-app/2/chatroom-1/proto"}'
2023-11-07 19:01:28 +01:00
```
2023-11-07 19:14:56 +01:00
**Get messages sent to a `contentTopic` **. Note that any store node in the network is used to reply.
2023-11-07 19:01:28 +01:00
```
curl -X GET "http://127.0.0.1:8645/store/v1/messages?contentTopics=%2Fmy-app%2F2%2Fchatroom-1%2Fproto& pageSize=50& ascending=true" \
-H "accept: application/json"
```
2023-10-03 15:34:52 +03:00
2023-11-09 16:18:53 +01:00
For advanced documentation, refer to [ADVANCED.md ](https://github.com/waku-org/nwaku-compose/blob/master/ADVANCED.md ).
2024-07-26 19:42:31 +02:00
-----
2024-10-14 16:17:56 +11:00
## How to update to latest version
2024-07-26 19:42:31 +02:00
2024-07-29 11:07:38 +02:00
We regularly announce new available versions in our [Discord ](https://discord.waku.org/ ) server.
2024-07-26 19:42:31 +02:00
2024-10-14 16:17:56 +11:00
### From `v0.29` or older
You will need to delete both the `keystore` and `rln_tree` folders, and register your membership again before using the new version by running the following commands:
2024-08-02 10:42:59 +03:00
2024-08-28 15:41:04 +02:00
1. `cd nwaku-compose` ( go into the root's repository folder )
2. `docker-compose down`
3. `sudo rm -r keystore rln_tree`
4. `git pull origin master`
5. `./register_rln.sh`
6. `docker-compose up -d`
2024-08-02 10:42:59 +03:00
2024-10-14 16:17:56 +11:00
### From `v0.30` or newer
Updating the node is as simple as running the following:
2024-08-28 15:41:04 +02:00
1. `cd nwaku-compose` ( go into the root's repository folder )
2. `docker-compose down`
3. `git pull origin master`
4. `docker-compose up -d`
2024-09-02 21:40:27 +02:00
2024-10-14 16:17:56 +11:00
### Set size
To improve storage on the network, you can increase the allocated space for the database.
To do so, you can simply run:
```
./set_storage_retention.sh
```
### Check
Once done, check your node is healthy:
```
./chkhealth.sh
```
All good:
```
02:15:51 - node health status is:
{
"nodeHealth": "Ready",
"protocolsHealth": [
{
"Rln Relay": "Ready"
}
]
}
```
If the `./chkhealth.sh` script is hanging or returns the following, wait a few minutes and run it again:
```
02:17:57 - node health status is:
{
"nodeHealth": "Initializing",
"protocolsHealth": []
}
```
### Clean-up
Docker artefact can take some precious disk space, run the following commands to free space **while your node is running** .
**Only do this if this machine is solely used for Waku and you have no other docker services**.
**I repeat, this will clean other docker services and images not running, only do this if this machine is only used for Waku**.
```
# Be sure that your containers **are running**
sudo docker-compose up -d
# Clean docker system files
sudo docker system prune -a
# Delete docker images
sudo docker image prune -a
# Delete docker containers
sudo docker container prune
# Delete docker volumes
sudo docker volume prune
```
2025-02-12 12:14:56 +11:00
#### journal
If your `/var/log` gets quite large:
```
journalctl --disk-usage
> Archived and active journals take up 1.5G in the file system.
```
You can cap the size in ` /etc/systemd/journald.conf` with
```
SystemMaxUse=50M
```
then restart to apply
```
systemctl restart systemd-journald
```
and verify
```
journalctl --disk-usage
> Archived and active journals take up 55.8M in the file system.
```
2024-09-02 21:40:27 +02:00
-----
2025-02-12 12:14:56 +11:00
2024-09-02 21:40:27 +02:00
# FAQ
[see ](FAQ.md )