### Install Prerequisites on Debian/Ubuntu Source: https://docs.waku.org/run-node/build-source Installs essential build tools, Git, PostgreSQL client library, and Rustup on Debian-based systems like Ubuntu. Curl is used to download and execute the Rustup installation script. ```bash sudo apt-get install build-essential git libpq5 jq curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh source "$HOME/.cargo/env" ``` -------------------------------- ### Install Prerequisites on Fedora Source: https://docs.waku.org/run-node/build-source Installs development tools, Git, PostgreSQL development libraries, and Rustup on Fedora systems. Curl is used to download and execute the Rustup installation script. ```bash sudo dnf install @development-tools git libpq-devel which curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Clone and Start Nwaku Node with Docker Compose Source: https://docs.waku.org/run-node This code snippet demonstrates the recommended quick start process for running a Waku node using Docker Compose. It involves cloning the nwaku-compose repository, navigating into the directory, copying the example environment file, configuring it, and finally starting the node in detached mode. ```bash # Clone the repository git clone https://github.com/waku-org/nwaku-compose cd nwaku-compose # Configure your node cp .env.example .env # Edit .env with your settings # Start your node docker-compose up -d ``` -------------------------------- ### Start Nwaku Node with Custom Node Key Source: https://docs.waku.org/run-node/configure-nwaku Starts a nwaku node using a provided 32-byte hexadecimal private key as its node key. ```bash ./build/wakunode2 --nodekey=286cae9f2990bfc49dafdd3a9e737f56ddba3656e5e427108cef456fb67680e8 ``` -------------------------------- ### Install Prerequisites on Arch Linux Source: https://docs.waku.org/run-node/build-source Installs base development packages, Git, PostgreSQL libraries, and Rustup on Arch Linux using an AUR helper. Curl is used to download and execute the Rustup installation script. ```bash # Using your favoured AUR helper sudo [AUR HELPER] -S base-devel git postgresql-libs curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh ``` -------------------------------- ### Install Prerequisites on macOS Source: https://docs.waku.org/run-node/build-source Installs CMake, Git, PostgreSQL 15, and Rustup using Homebrew on macOS. It also creates a symbolic link for the PostgreSQL client library. ```bash brew install cmake git postgresql@15 rustup-init # Create a symbolic link to libpq.5.dylib in /usr/local/lib/ sudo mkdir -p /usr/local/lib/ sudo ln -s /opt/homebrew/opt/postgresql@15/lib/libpq.5.dylib /usr/local/lib/libpq.dylib ``` -------------------------------- ### Install protobufjs using npm Source: https://docs.waku.org/build/javascript Installs the protobufjs package using npm. This library is recommended for creating structured message formats for Waku, ensuring consistency and efficiency. ```bash npm install protobufjs ``` -------------------------------- ### Run Nwaku Binary Source: https://docs.waku.org/run-node/build-source Executes the compiled nwaku binary ('wakunode2') from the './build/' directory. Includes an example for running with default configuration and another for viewing command-line options. ```bash # Run with default configuration ./build/wakunode2 # See available command line options ./build/wakunode2 --help ``` -------------------------------- ### Install protobufjs using Yarn Source: https://docs.waku.org/build/javascript Installs the protobufjs package using Yarn. This is an alternative to npm for managing JavaScript dependencies, used here for the Protocol Buffers library. ```bash yarn add protobufjs ``` -------------------------------- ### Install @waku/message-encryption and @waku/utils Source: https://docs.waku.org/build/javascript/message-encryption Installs the necessary Waku message encryption and utility packages using NPM or Yarn. Ensure you have Node.js and a package manager installed. ```bash npm install @waku/message-encryption @waku/utils ``` ```bash yarn add @waku/message-encryption @waku/utils ``` -------------------------------- ### Create and Start a Waku Light Node Source: https://docs.waku.org/build/javascript/store-retrieve-messages Initializes a Waku Light Node, optionally connecting to bootstrap nodes, and starts its services. This is the first step to interacting with the Waku network. ```typescript import { createLightNode } from "@waku/sdk"; // Create and start a Light Node const node = await createLightNode({ defaultBootstrap: true }); await node.start(); ``` -------------------------------- ### Generate SSL Certificate with Certbot Source: https://docs.waku.org/run-node/configure-nwaku A command-line example using Certbot to obtain a free SSL certificate from Let's Encrypt for a given domain name, which can be used for secure WebSocket transport. ```bash sudo certbot certonly -d ``` -------------------------------- ### Install JavaScript Waku SDK using Yarn Source: https://docs.waku.org/build/javascript Installs the @waku/sdk package using Yarn, an alternative package manager for JavaScript. This command is equivalent to the npm install command for adding the SDK. ```bash yarn add @waku/sdk ``` -------------------------------- ### Create and Start a Basic Light Node Source: https://docs.waku.org/build/javascript/light-send-receive Initializes and starts a Waku Light Node using the `createLightNode` function with default bootstrapping enabled. The node can be stopped using the `stop()` method. ```typescript import { createLightNode } from "@waku/sdk"; // Create and start a Light Node const node = await createLightNode({ defaultBootstrap: true }); await node.start(); // Use the stop() function to stop a running node // await node.stop(); ``` -------------------------------- ### Install @waku/dns-discovery Package Source: https://docs.waku.org/build/javascript/configure-discovery Installs the `@waku/dns-discovery` package required for configuring DNS discovery. This package provides the necessary functions to integrate DNS-based peer discovery into your Waku node. ```bash npm install @waku/dns-discovery ``` ```bash yarn add @waku/dns-discovery ``` -------------------------------- ### Initialize Project with NPM - @waku/create-app Source: https://docs.waku.org/build/javascript/use-waku-create-app Initializes a new @waku/sdk project using the create-app package via NPM. This command scaffolds a project in the specified directory using a default template. Ensure you have Node.js and npm installed. ```bash npx @waku/create-app [PROJECT DIRECTORY] ``` -------------------------------- ### Install Waku React Dependencies with NPM Source: https://docs.waku.org/build/javascript/use-waku-react Installs the necessary @waku/react, @waku/sdk, and protobufjs packages using NPM. These are the core libraries for integrating Waku into a React application. ```bash npm install @waku/react @waku/sdk protobufjs ``` -------------------------------- ### Install Waku SDK Source: https://docs.waku.org/build/javascript/reliable-channels Installs the latest version of the Waku SDK using npm. This is the primary method for incorporating Waku functionalities into your project. ```bash npm install @waku/sdk@latest ``` -------------------------------- ### Configure nwaku as a Light Push Client Source: https://docs.waku.org/run-node/configure-nwaku Set up nwaku as a Light Push client using the `lightpushnode` option. This enables the node to request lightpush of published messages from peers, specifying the peer's multiaddr. ```bash ./build/wakunode2 --lightpushnode=[LIGHT PUSH PEER MULTIADDR] ``` ```bash ./build/wakunode2 --lightpushnode=/dns4/node-01.ac-cn-hongkong-c.waku.sandbox.status.im/tcp/30303/p2p/16Uiu2HAmSJvSJphxRdbnigUV5bjRRZFBhTtWFTSyiKaQByCjwmpV ``` -------------------------------- ### Install JavaScript Waku SDK using npm Source: https://docs.waku.org/build/javascript Installs the @waku/sdk package using npm, the Node Package Manager. This is a common way to add Waku functionality to web projects. ```bash npm install @waku/sdk ``` -------------------------------- ### Install Waku React Dependencies with Yarn Source: https://docs.waku.org/build/javascript/use-waku-react Installs the necessary @waku/react, @waku/sdk, and protobufjs packages using Yarn. These are the core libraries for integrating Waku into a React application. ```bash yarn add @waku/react @waku/sdk protobufjs ``` -------------------------------- ### Enable Light Push Protocol for nwaku Source: https://docs.waku.org/run-node/configure-nwaku Configure nwaku to serve light clients by enabling the Light Push protocol using the `lightpush` option. This allows the node to act as a light push server. ```bash ./build/wakunode2 --lightpush=true ``` -------------------------------- ### Configure Nwaku as a Store Client Source: https://docs.waku.org/run-node/configure-nwaku Configures a nwaku node to act as a Store client, enabling it to query peers for historical messages without storing any itself. Requires the multiaddr of a store peer. ```bash ./build/wakunode2 --storenode=[STORE PEER MULTIADDR] ``` ```bash ./build/wakunode2 --storenode=/dns4/node-01.ac-cn-hongkong-c.waku.sandbox.status.im/tcp/30303/p2p/16Uiu2HAmSJvSJphxRdbnigUV5bjRRZFBhTtWFTSyiKaQByCjwmpV ``` -------------------------------- ### Initialize Project with Yarn - @waku/create-app Source: https://docs.waku.org/build/javascript/use-waku-create-app Initializes a new @waku/sdk project using the create-app package via Yarn. This command scaffolds a project in the specified directory using a default template. Ensure you have Node.js and Yarn installed. ```bash yarn create @waku/app [PROJECT DIRECTORY] ``` -------------------------------- ### Configure nwaku Node Environment Source: https://docs.waku.org/run-node/run-docker-compose This command copies the example environment file to be used for configuration. You should then edit the .env file to set your specific configuration values. Ensure no secrets are committed to version control. ```bash cp .env.example .env ${EDITOR} .env ``` -------------------------------- ### Generate and Use Nwaku Node Private Key Source: https://docs.waku.org/run-node/configure-nwaku Allows using a pre-generated private key for consistent node multiaddrs. The key must be a 64-character hex string (Secp256k1). ```bash ./build/wakunode2 --nodekey=[NODE PRIVATE KEY] ``` ```bash openssl rand -hex 32 ``` ```bash # 286cae9f2990bfc49dafdd3a9e737f56ddba3656e5e427108cef456fb67680e8 ``` ```bash # Generate key file openssl ecparam -genkey -name secp256k1 -out my_private_key.pem ``` -------------------------------- ### Use useWaku Hook in React Source: https://docs.waku.org/build/javascript/use-waku-react Demonstrates how to use the `useWaku()` hook within a React component (`App.jsx`) to create and start a Waku Light Node. It shows how to access the node instance, potential errors, and loading status. ```jsx import { useWaku } from "@waku/react"; function App() { // Create and start a Light Node const { node, error, isLoading } = useWaku(); // "node" is the created Light Node // "error" captures any error that occurs during node creation // "isLoading" indicates whether the node is still being created } ``` -------------------------------- ### Build Nwaku Docker Image Locally Source: https://docs.waku.org/run-node/run-docker This snippet demonstrates how to clone the nwaku repository and build the Docker image locally using make commands. Ensure you have Git and Docker installed. ```shell # Clone the repository git clone --recurse-submodules https://github.com/waku-org/nwaku cd nwaku # Build docker image make docker-image ``` -------------------------------- ### Configure Nwaku Store Synchronization Source: https://docs.waku.org/run-node/configure-nwaku Enables the store synchronization protocol and sets parameters for synchronization interval, range, and relay jitter. Defaults are provided for interval (300s), range (3600s), and jitter (20s). ```bash ./build/wakunode2 \ --store-sync=true \ --store-sync-interval=300 \ --store-sync-range=3600 \ --store-sync-relay-jitter=20 ``` -------------------------------- ### Run nwaku Behind a Reverse Proxy Source: https://docs.waku.org/run-node/configure-nwaku Configure nwaku to run behind a reverse proxy for SSL/TLS encryption. Use `ext-multiaddr-only` and `ext-multiaddr` options to specify the proxy server's IP or domain for announcing multiaddr. ```bash ./build/wakunode2 \ --ext-multiaddr-only=true \ --ext-multiaddr=[MULTIADDR TO PUBLISH] ``` -------------------------------- ### Filter Messages by Time Frame in Waku JavaScript Source: https://docs.waku.org/build/javascript/store-retrieve-messages This example shows how to retrieve messages within a specific time range using the timeFilter option. It defines start and end times, typically representing the last week, and passes them to the `queryWithOrderedCallback` function. Using `timeFilter` can impact performance, and resuming with a cursor is recommended for optimization. ```javascript // Get the time frame const endTime = new Date(); const startTime = new Date(); startTime.setDate(endTime.getDate() - 7); // Retrieve a week of messages const queryOptions = { timeFilter: { startTime, endTime, }, }; // Assuming 'node', 'decoder', 'callback', and 'options' are defined elsewhere // Query the Store peer with options await node.store.queryWithOrderedCallback([decoder], callback, queryOptions); const storeQuery = node.store.queryGenerator([decoder, queryOptions]); ``` -------------------------------- ### Create Vite React App with NPM Source: https://docs.waku.org/build/javascript/use-waku-react Boilerplate project creation using Vite and React with NPM. This command initializes a new React project in the specified directory. ```bash npm create vite@latest [PROJECT DIRECTORY] -- --template react ``` -------------------------------- ### Initialize LightNodeProvider in React Source: https://docs.waku.org/build/javascript/use-waku-react Sets up the LightNodeProvider context in `main.jsx` to wrap the entire React application with Waku functionality. This involves importing the provider and defining node options. ```jsx import { LightNodeProvider } from "@waku/react"; // Set the Light Node options const NODE_OPTIONS = { defaultBootstrap: true }; ReactDOM.createRoot(document.getElementById('root')).render( // Use the Light Node context provider , ) ``` -------------------------------- ### Run Nwaku Test Suite Source: https://docs.waku.org/run-node/build-source Executes the test suite for the Waku project using the 'make test' command. This is a crucial step to verify the integrity of the built binary. ```bash make test ``` -------------------------------- ### Create Vite React App with Yarn Source: https://docs.waku.org/build/javascript/use-waku-react Boilerplate project creation using Vite and React with Yarn. This command initializes a new React project in the specified directory. ```bash yarn create vite [PROJECT DIRECTORY] --template react ``` -------------------------------- ### Get nwaku Version via REST API Source: https://docs.waku.org/run-node/run-docker-compose This command uses curl to make a GET request to the nwaku node's debug endpoint to retrieve its version information. It targets the local REST API running on port 8645. ```bash curl --location 'http://127.0.0.1:8645/debug/v1/version' ``` -------------------------------- ### Display Nwaku Docker Container Help Source: https://docs.waku.org/run-node/run-docker Command to display all available configuration options and arguments for the nwaku Docker container. ```shell docker run -t wakuorg/nwaku:v0.32.0 --help ``` -------------------------------- ### Configure Node with DNS Discovery and Static Peers Source: https://docs.waku.org/build/javascript/configure-discovery Sets up a Waku light node to use both DNS Discovery and Static Peers simultaneously. This is achieved by providing both `bootstrapPeers` and `peerDiscovery` configurations within the `libp2p` settings. ```javascript import { createLightNode } from "@waku/sdk"; import { bootstrap } from "@libp2p/bootstrap"; import { enrTree, wakuDnsDiscovery } from "@waku/dns-discovery"; // Define the list of static peers to bootstrap const peers = [ "/ip4/0.0.0.0/tcp/60002/ws/p2p/16Uiu2HAkzjwwgEAXfeGNMKFPSpc6vGBRqCdTLG5q3Gmk2v4pQw7H", "/ip4/0.0.0.0/tcp/60003/ws/p2p/16Uiu2HAmFBA7LGtwY5WVVikdmXVo3cKLqkmvVtuDu63fe8safeQJ", ]; // Define node requirements const NODE_REQUIREMENTS = { store: 3, lightPush: 3, filter: 3, }; // Bootstrap node using DNS Discovery and static peers const node = await createLightNode({ libp2p: { bootstrapPeers: peers, peerDiscovery: [wakuDnsDiscovery([enrTree["PROD"]], NODE_REQUIREMENTS)], }, }); ``` -------------------------------- ### Get nwaku Node Information via REST API Source: https://docs.waku.org/run-node/run-docker-compose This command uses curl to make a GET request to the nwaku node's debug endpoint to retrieve general information about the node. It targets the local REST API running on port 8645. ```bash curl --location 'http://127.0.0.1:8645/debug/v1/info' ``` -------------------------------- ### Enable Nwaku Filter Protocol Server Source: https://docs.waku.org/run-node/configure-nwaku Enables the Filter protocol on the nwaku node, allowing it to serve light clients. This is done by setting the --filter option to true. ```bash ./build/wakunode2 --filter=true ``` -------------------------------- ### Retrieve Connected Peers with Waku SDK (JavaScript) Source: https://docs.waku.org/build/javascript/configure-discovery This snippet demonstrates how to initialize a Waku light node, wait for peers to connect, and then retrieve and log the array of connected peers using the `libp2p.getPeers()` function. It requires the `@waku/sdk` package. ```javascript import { createLightNode } from "@waku/sdk"; const node = await createLightNode({ defaultBootstrap: true }); await node.waitForPeers(); // Retrieve array of peers connected to the node console.log(node.libp2p.getPeers()); ``` -------------------------------- ### Create Symmetric Decoder and Receive Encrypted Message Source: https://docs.waku.org/build/javascript/message-encryption Creates a symmetric message decoder using `createDecoder` from `@waku/message-encryption/symmetric` to process received messages. Used with Filter subscriptions or Store queries. ```javascript import { createDecoder } from "@waku/message-encryption/symmetric"; // Create a symmetric message decoder const decoder = createDecoder(contentTopic, symmetricKey); // Receive messages from a Filter subscription await subscription.subscribe([decoder], callback); // Retrieve messages from Store peers await node.store.queryWithOrderedCallback([decoder], callback); ``` -------------------------------- ### Configure Nwaku REST API Server Source: https://docs.waku.org/run-node/configure-nwaku Enables and configures the REST API server for nwaku, allowing interaction with the node and Waku Network. Configuration options include enabling the server, setting listening address and port, message cache capacity, and enabling admin and private APIs. ```bash ./build/wakunode2 \ --rest=true \ --rest-address=[REST SERVER LISTENING ADDRESS] \ --rest-port=[REST SERVER LISTENING PORT] \ --rest-relay-cache-capacity=[MESSAGE CACHE CAPACITY] \ --rest-admin=[true|false] \ --rest-private=[true|false] ``` ```bash ./build/wakunode2 \ --rest=true \ --rest-port=9000 \ --rest-address=127.0.0.1 ``` ```bash ./build/wakunode2 \ --rest=true \ --rest-admin=true \ --rest-private=true \ --rest-relay-cache-capacity=100 ``` -------------------------------- ### Import protobufjs from CDN (JavaScript) Source: https://docs.waku.org/build/javascript Imports the protobufjs library from a CDN using an ES module import. This makes the Protocol Buffers functionality available in your JavaScript application without local installation. ```javascript // Import the CDN import "https://cdn.jsdelivr.net/npm/protobufjs@latest/dist/protobuf.min.js"; ``` -------------------------------- ### Extract 32-byte Private Key for Nwaku Node Key Source: https://docs.waku.org/run-node/configure-nwaku This command extracts a 32-byte private key from a PEM file and formats it as a hex string, suitable for use as a Node Key with nwaku. ```bash openssl ec -in my_private_key.pem -outform DER | tail -c +8 | head -c 32| xxd -p -c 32 ``` -------------------------------- ### Generate Symmetric Key for Encryption Source: https://docs.waku.org/build/javascript/message-encryption Generates a random symmetric key using the `generateSymmetricKey` function from the @waku/message-encryption package. This key is essential for symmetric encryption and must be securely shared between sender and receiver. ```javascript import { generateSymmetricKey } from "@waku/message-encryption"; // Generate a random symmetric key const symmetricKey = generateSymmetricKey(); ```