Running a Single Node Local Network

Following this guide, you can set up a single-node local network manually or by using the provided automated script. Running a single-node setup is beneficial for developers who need a quick and simple environment to test their applications and protocol features. For more complex setups, please refer to the Multi-Node Setup guide.

Prerequisites

  • Install Binary

  • Automated Script

Automated Script

The simplest way to start a local Dhive node is by utilizing the helper script included in the Dhive repository. This script sets up a default configuration optimized for testing purposes:

$ local_node.sh

Tip: To prevent accidental data loss on a production node, the automatically generated test configuration is stored at ~/.tmp-dhived instead of the default ~/.dhived.

When using the local_node.sh script, all dhived commands targeting the local test node must include the --home ~/.tmp-dhived flag, as the home directory cannot be stored in the dhived configuration. To simplify usage, consider exporting this directory as an environment variable:

$ export TMP=$HOME/.tmp-dhived
$ dhived config --home $TMP
{
  "chain-id": "dhive_9000-1",
  "keyring-backend": "test",
  "output": "text",
  "node": "tcp://localhost:26657",
  "broadcast-mode": "sync"
}

You can customize the local node script by modifying the configuration variables. For example:

KEYS[0]="dev0"
KEYS[1]="dev1"
KEYS[2]="dev2"
CHAINID="dhive_9000-1"
MONIKER="localtestnet"
KEYRING="test"
KEYALGO="eth_secp256k1"
LOGLEVEL="info"
HOMEDIR="$HOME/.tmp-dhived"
TRACE=""

Manual Deployment

This guide walks you through setting up a single validator node for local testing and development.

Initialize the Chain

Before running the node, initialize the chain and its genesis file using the following command:

MONIKER=testing
KEY=dev0
CHAINID="dhive_9000-4"

dhived init $MONIKER --chain-id=$CHAINID

Tip: The moniker can be edited later by modifying the config.toml file.

Adding Genesis Accounts

Create a local account and fund it with tokens:

dhived keys add my_validator
dhived add-genesis-account my_validator 10000000000adhive

To add a validator, create a gentx transaction:

dhived add-genesis-account my_validator 1000000000stake,10000000000adhive
dhived gentx --help

After creating the gentx, add it to the genesis file:

dhived collect-gentxs

Running a Single Node

Validate the genesis.json file:

dhived validate-genesis

Start the node:

dhived start

Tip: Use the --help flag to explore customizable options.

Key Management

To ensure the same key is used across restarts, modify local_node.sh:

echo "your mnemonic here" | dhived keys add $KEY --recover

Generate a new key:

dhived keys add $KEY

To export your Dhive key as an Ethereum private key:

dhived keys unsafe-export-eth-key $KEY

Clearing Data

To reset the blockchain data and address book:

rm $HOME/.dhived/config/addrbook.json $HOME/.dhived/config/genesis.json
dhived tendermint unsafe-reset-all --home $HOME/.dhived

To delete all data and start fresh:

rm -rf ~/.dhived

Recording Transactions Per Second (TPS)

To monitor TPS using Prometheus, update your config.yaml:

global:
  scrape_interval: 10s
external_labels:
  monitor: 'dhive'
scrape_configs:
- job_name: 'dhive'
  scrape_interval: 10s
  static_configs:
    - targets: ['localhost:8877']

Start Prometheus:

prometheus --config.file=prom_config.yaml

In the Prometheus dashboard (http://localhost:9090), use this query to monitor TPS:

rate(dhived_transactions_processed[1m])

This guide provides the necessary steps to set up a single-node local network with Dhive efficiently. For multi-node configurations and additional features, please refer to the official documentation.

Last updated

Was this helpful?