Skip to main content

Set up RPC node 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.

This guide provides step-by-step instructions for setting up an RPC node on the Midnight blockchain.

Prerequisites

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

Set up an RPC node

The following steps show how to set up an RPC node on Midnight's Preview and Preprod networks.

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 (for example, 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.

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" \
midnightntwrk/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

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

Configure RPC methods

  • --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

Verify the Node

The commands below show how to verify the node's connectivity and logs.

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