Skip to main content

Setting up RPC nodes for Midnight

RPC nodes serve as the primary interface for applications to interact with the Midnight blockchain programmatically. These nodes expose WebSocket and HTTP APIs that enable developers to submit transactions, query blockchain data, subscribe to events, and integrate DApps with the network.

RPC node

An RPC node is a node configured to expose external APIs for blockchain interaction. It provides WebSocket (default port 9944) endpoints that applications and developers use to communicate with the Midnight blockchain. You can configure RPC nodes with different security levels to control which methods they expose publicly.

Prerequisites

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

Setting up an RPC node

Step 1: Configure PostgreSQL database

Set up a Cardano-db-sync/ PostgreSQL instance with the following parameters:

  • Host: PostgreSQL server address.
  • Port: Default 5432.
  • Username: Database user.
  • Password: Database password.
  • Database Name: Name of the database (e.g., cexplorer).

Step 2: Run the Docker command for an RPC node

Use the following Docker command to set up your RPC node. Choose the configuration for your target network.

For Preview network:

docker run \
--name midnight-rpc-node \
--platform linux/amd64 \
-p 9944:9944 \
-p 30333:30333 \
-v midnight-data:/node \
-e CFG_PRESET="preview" \
-e BASE_PATH="/node/chain/" \
-e POSTGRES_HOST="<your-postgres-host>" \
-e POSTGRES_PORT="5432" \
-e POSTGRES_USER="<your-db-user>" \
-e POSTGRES_PASSWORD="<your-db-password>" \
-e POSTGRES_DB="cexplorer" \
midnightnetwork/midnight-node:<VERSION> \
--chain=/res/preview/chain-spec-raw.json \
--bootnodes /dns/bootnode-1.preview.midnight.network/tcp/30333/ws/p2p/12D3KooWK66i7dtGVNSwDh9tTeqov1q6LSdWsRLJvTyzTCaywYgK \
--bootnodes /dns/bootnode-2.preview.midnight.network/tcp/30333/ws/p2p/12D3KooWHqFfXFwb7WW4jwR8pr4BEf562v5M6c8K3CXAJq4Wx6ym \
--rpc-methods=Safe \
--rpc-cors=all \
--rpc-external \
--ws-external \
--no-private-ip

For Preprod network:

docker run \
--name midnight-rpc-node \
--platform linux/amd64 \
-p 9944:9944 \
-p 30333:30333 \
-v midnight-data:/node \
-e CFG_PRESET="preprod" \
-e BASE_PATH="/node/chain/" \
-e POSTGRES_HOST="<your-postgres-host>" \
-e POSTGRES_PORT="5432" \
-e POSTGRES_USER="<your-db-user>" \
-e POSTGRES_PASSWORD="<your-db-password>" \
-e POSTGRES_DB="cexplorer" \
midnightnetwork/midnight-node:<VERSION> \
--chain=/res/preprod/chain-spec-raw.json \
--bootnodes /dns/bootnode-1.preprod.midnight.network/tcp/30333/ws/p2p/12D3KooWQxxUgq7ndPfAaCFNbAxtcKYxrAzTxDfRGNktF75SxdX5 \
--bootnodes /dns/bootnode-2.preprod.midnight.network/tcp/30333/ws/p2p/12D3KooWNrUBs22FfmgjqFMa9ZqKED2jnxwsXWw5E4q2XVwN35TJ \
--rpc-methods=Safe \
--rpc-cors=all \
--rpc-external \
--ws-external \
--no-private-ip

Replace the following:

  • <VERSION> - Node version from the release compatibility matrix
  • <your-postgres-host> - PostgreSQL server address (use host.docker.internal if Cardano-db-sync runs on the same machine)
  • <your-db-user> - Database username configured in Cardano-db-sync
  • <your-db-password> - Database password configured in Cardano-db-sync

RPC configuration options

  • --rpc-methods=Safe - Exposes only safe RPC methods (recommended for public nodes)
  • --rpc-methods=Unsafe - Exposes all RPC methods including node administration (use only on private networks)
  • --rpc-cors=all - Allows cross-origin requests from any domain
  • --rpc-external - Makes RPC accessible from external networks
  • --ws-external - Makes WebSocket accessible from external networks
Security

For production RPC nodes exposed to the internet:

  • Always use --rpc-methods=Safe to prevent unauthorized node administration
  • Consider implementing rate limiting and authentication at the infrastructure level
  • Use a reverse proxy (nginx, Caddy) with SSL/TLS termination
  • Restrict access using firewall rules when possible

Verifying the Node

Check logs

Monitor the node's logs to ensure it syncs with the network:

docker logs -f <node-name>

Test connectivity

Ensure the node's P2P port (default: 30333) is open and reachable for network communication. Use tools like telnet, netcat, or nmap to verify the port status and ensure the node is properly connected to the network.

Additionally, to preview the available RPC methods, run the following curl command, which lists all endpoints exposed by the node:

curl -H "Content-Type: application/json" \
-X POST \
-d '{
"jsonrpc":"2.0",
"id":1,
"method":"rpc_methods",
"params":[]
}' \
http://127.0.0.1:9944