Set up RPC node for Midnight
Remote Procedure Call (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:
- Cardano-db-sync instance set up with accessible PostgreSQL port.
- Midnight node set up with the environment variables set.
Run the Midnight node in RPC mode
Use the following command to run Midnight node in RPC mode. Choose the configuration for your target network.
- Preview
- Preprod
midnight-node \
--chain /home/midnight/res/preview/chain-spec-raw.json \
--base-path /home/midnight/data \
--rpc-port 9933 \
--rpc-methods Safe \
--rpc-cors all \
--rpc-external \
--ws-external \
--no-private-ip
midnight-node \
--chain /home/midnight/res/preprod/chain-spec-raw.json \
--base-path /home/midnight/data \
--rpc-port 9933 \
--rpc-methods Safe \
--rpc-cors all \
--rpc-external \
--ws-external \
--no-private-ip
Configure RPC methods
--rpc-methods Safe: Exposes only safe RPC methods (recommended for public nodes)--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
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
Next steps
With the RPC node set up, you can start using the Node endpoints to interact with the Midnight blockchain.