Skip to main content
For the complete documentation index, see llms.txt

Set up full node

This guide provides step-by-step instructions for setting up a full node for Midnight.

Prerequisites​

Before setting up your Midnight full node, ensure you have the following:

Install Midnight node​

The Midnight node is the core client for the Midnight protocol. Install the Midnight node by following the steps below.

Create directories for the node:

mkdir -p ~/data ~/res ~/.local/bin
  • ~/data: For node database/base path.
  • ~/res: For chain configuration files.
  • All owned by midnight user.

Download and install the Midnight node binary:

Create a temporary directory and navigate to it:

mkdir -p ~/tmp && cd ~/tmp

Download the Midnight node binary:

curl -L -O https://github.com/midnightntwrk/midnight-node/releases/download/node-1.0.400/midnight-node-1.0.400-linux-amd64.tar.gz
Node version

Preview, Preprod, and Mainnet run node 1.0.400. For the node version that each network runs now, see the compatibility matrix. When a newer node release appears, check its release notes for the runtime it supports before you upgrade. An older binary can't run a newer runtime and stops importing blocks at the runtime upgrade.

Extract the binary:

tar -xvzf midnight-node-1.0.400-linux-amd64.tar.gz

Move the binary to the local bin directory:

mv ~/tmp/midnight-node ~/.local/bin/

Move the chain config files to the res directory:

mv ~/tmp/res/* ~/res/

Reload the shell environment:

source ~/.bashrc # or source ~/.zshrc

Set environment variables​

Create an .env configuration file and set the environment variables for the PostgreSQL database:

# PostgreSQL connection
export POSTGRES_HOST="localhost"
export POSTGRES_DB="cexplorer"
export POSTGRES_PORT="5432"
export POSTGRES_USER="midnight"
export POSTGRES_PASSWORD="YOUR_POSTGRES_PASSWORD"

# Cardano database connection string
export DB_SYNC_POSTGRES_CONNECTION_STRING="postgresql://midnight:YOUR_POSTGRES_PASSWORD@localhost:5432/cexplorer"

export NODE_NAME="your_node_name"

Load the variables into the shell environment:

source ~/.env

Confirm that the variables are loaded successfully:

echo $DB_SYNC_POSTGRES_CONNECTION_STRING

Run a full node​

Start the node from your home directory. On startup, the node reads its configuration from res/cfg, relative to the directory you start it from.

cd ~

Once the environment variables are set, run the Midnight node using the following command:

CFG_PRESET=preview CARDANO_SECURITY_PARAMETER=432 midnight-node \
--chain /home/midnight/res/preview/chain-spec-raw.json \
--base-path /home/midnight/data \
--pool-limit 35 \
--name $NODE_NAME \
--bootnodes /dns/bootnode-1.preview.midnight.network/tcp/30333/ws/p2p/12D3KooWK66i7dtGVNSwDh9tTeqov1q6LSdWsRLJvTyzTCaywYgK \
--bootnodes /dns/bootnode-2.preview.midnight.network/tcp/30333/ws/p2p/12D3KooWHqFfXFwb7WW4jwR8pr4BEf562v5M6c8K3CXAJq4Wx6ym \
--no-private-ip

Available networks​

The CFG_PRESET environment variable selects the network. The node loads the settings for that network from res/cfg. The presets for the public networks are:

  • preview: For the Preview network.
  • preprod: For the Preprod network.
  • mainnet: For the Mainnet network.

The node also reads CARDANO_SECURITY_PARAMETER from the environment. Set it to the security parameter of the matching Cardano network: 432 for Preview, and 2160 for Preprod and Mainnet.

The --chain flag takes the path to the network's chain specification file, not a network name. The Preview chain specification lists no boot nodes, so the Preview command passes the known Preview boot nodes with --bootnodes.

Mainnet sync with node 1.0.300

A Mainnet node that syncs from genesis with node 1.0.300 stops at block 1788979. Node 1.0.400 includes a fix. If your node stopped at that block, restart it with node 1.0.400.

Verify the node​

Monitor the node's logs to ensure it syncs with the network. What to look for in the output:

  • Cardano db connection: If you see Using candidate data source configuration, then the node has connected to the Cardano-db-sync database. If the node exits with Could not connect to database, then check the connection string in your .env file.
  • Peers: The status line shows the peer count, for example (4 peers). If it stays at Idle (0 peers), then check your firewall (port 30333) or the --bootnodes address.
  • Syncing: You should see best: #0 ... start to increment as it pulls blocks from the network. If it stays at #0 and the log repeats Verification failed for block, then check that Cardano-db-sync has finished syncing. The node verifies each Midnight block against the Cardano data in the Cardano-db-sync database.

Full node vs. archive node​

A full node syncs with the blockchain, validates transactions, and provides real-time state queries. It prunes historical states older than a configurable number (defaulting to 256 blocks). This makes it suitable for most DApp development and real-time interactions with the network. Its key advantage lies in its efficient use of disk space, requiring significantly less storage than an archive node.

An archive node maintains the entire history of the blockchain, including all blocks and states. This comprehensive storage consumes substantial disk space. However, it is essential for use cases requiring access to historical data, such as building block explorers, conducting in-depth debugging, or querying past events.

To run the Midnight node in archive mode, use the --state-pruning archive and --blocks-pruning archive flags. The node stores the state pruning mode when it first creates its database. To switch a full node to archive mode, start it with an empty base path directory.

CFG_PRESET=preview CARDANO_SECURITY_PARAMETER=432 midnight-node \
--chain /home/midnight/res/preview/chain-spec-raw.json \
--base-path /home/midnight/data \
--state-pruning archive \
--blocks-pruning archive \
--bootnodes /dns/bootnode-1.preview.midnight.network/tcp/30333/ws/p2p/12D3KooWK66i7dtGVNSwDh9tTeqov1q6LSdWsRLJvTyzTCaywYgK \
--bootnodes /dns/bootnode-2.preview.midnight.network/tcp/30333/ws/p2p/12D3KooWHqFfXFwb7WW4jwR8pr4BEf562v5M6c8K3CXAJq4Wx6ym \
--no-private-ip \
--name $NODE_NAME

Next steps​

With the full node set up, you can start using the Node endpoints to interact with the Midnight blockchain.