Running a Node
Running a Node
Run a full validating node, connect it to peers, and expose only the services you intend to expose.
The JSON-RPC server is plaintext HTTP authenticated by a rotating cookie. Keep --rpc 127.0.0.1:18332 (or the testnet equivalent) unless you terminate TLS in front of it. Only expose the P2P port to the public internet.
Network presets
| Network | P2P magic | Default P2P | Default RPC | Coinbase maturity | Initial target | DNS seeds |
|---|---|---|---|---|---|---|
mainnet | XSL1 | 18333 | 18332 | 24 blocks (~2 h) | 0x1e0fffff | seed{1,2,3}.scruple.money:18333 |
testnet | XSLT | 28333 | 28332 | 6 blocks (~30 m) | 0x1f0fffff | seed{1,2,3}.testnet.scruple.money:28333 |
devnet | XSLD | 18333 | 18332 | 2 blocks | 0x200fffff | none |
Networks are isolated by genesis seed and P2P magic. A mainnet node will not sync with a testnet peer. The target block time is 300 seconds on all networks; testnet and devnet simply start at easier difficulty.
Start a node
Mainnet
./target/release/scruple node \
--network mainnet \
--data-dir ./mainnet-data \
--p2p 0.0.0.0:18333 \
--rpc 127.0.0.1:18332 \
--external-addr <PUBLIC_IP>:18333
Binding P2P to 0.0.0.0 accepts inbound peers. --external-addr advertises a publicly reachable numeric IP:port in the P2P handshake so peers can gossip your node. Use a numeric IP, not a hostname; peer gossip rejects non-numeric hostnames to avoid SSRF and DNS amplification.
Testnet
./target/release/scruple node \
--network testnet \
--data-dir ./testnet-data \
--p2p 0.0.0.0:28333 \
--rpc 127.0.0.1:28332 \
--external-addr <PUBLIC_IP>:28333 \
--txindex
Devnet
./target/release/scruple node \
--network devnet \
--data-dir ./devnet-data \
--p2p 127.0.0.1:18333 \
--rpc 127.0.0.1:18332
Devnet has no built-in DNS seeds. For a local cluster, connect nodes explicitly with --seed or --peer.
Node flags
| Flag | Description |
|---|---|
--network <mainnet|testnet|devnet> | Select consensus parameters, magic, ports, and DNS seeds. Defaults to mainnet. |
--data-dir <PATH> | Directory for chain.redb, peers.json, .cookie, and related state. Defaults to ./data. |
--p2p <ADDR> | TCP P2P bind address. Defaults to 127.0.0.1:<network P2P port>. |
--rpc <ADDR> | HTTP JSON-RPC bind address. Defaults to 127.0.0.1:<network RPC port>. |
--external-addr <IP:PORT> | Public numeric address advertised in the P2P handshake. Essential on a VPS bound to 0.0.0.0. |
--peer <ADDR> | Repeatable explicit peer. Bypasses /16 IPv4 and /32 IPv6 outbound subnet diversity for LAN clusters. |
--seed <HOST:PORT> | Repeatable additional DNS/bootstrap seed. |
--no-dns-seeds | Disable built-in DNS seed resolution. Use for isolated LANs or offline clusters. |
--prune <N> | Keep only the most recent N full blocks (minimum 288). Headers, UTXOs, and the seen-address index are retained. |
--txindex | Maintain a persistent txid -> (height, tx_index) index for confirmed get_tx lookups. Mutually exclusive with --prune. |
--rpc-cookie <PATH> | Mirror the generated RPC cookie to an additional path with mode 0600. The default <data-dir>/.cookie is always written. |
Data directory
| Path | Contents |
|---|---|
<data-dir>/chain.redb | Embedded redb database: headers, height index, cumulative work, active UTXO set, raw blocks, undo logs, seen-address index, and optional tx index. |
<data-dir>/.cookie | Fresh 32-byte random hex RPC token, regenerated on every node restart, mode 0600. |
<data-dir>/peers.json | Atomically persisted healthy peer addresses, mode 0600, capped at 256 entries. |
<data-dir>/wallets/ | Default multi-wallet directory used by scruple-gui --wallets. |
<data-dir>/pending-multisig.json | Tracked pending multisig outpoints created by multisig propose. |
<wallet>.lock | Exclusive OS-level sidecar lock held while a wallet is open for mutation or signing. |
On restart, metadata and UTXOs load directly from chain.redb without replaying the chain. The RPC cookie is replaced with a new random token, so external clients must re-read .cookie from disk instead of caching it across restarts.
Peer discovery and connectivity
Scruple discovers peers through built-in DNS seeds, explicit --seed entries, explicit --peer entries, and persisted peers.json addresses. DNS lookups expand all returned A/AAAA records and enforce outbound subnet diversity for untrusted peers.
| Mechanism | Behaviour |
|---|---|
| DNS seeds | Resolved on startup and periodically when isolated. Mainnet and testnet have built-in seeds; devnet does not. |
--seed | Adds an explicit bootstrap target. Subject to the same diversity rules as DNS peers unless also passed as --peer. |
--peer / RPC add_peer | Explicit operator target. Bypasses /16 IPv4 and /32 IPv6 diversity checks for LAN full-mesh clusters. |
peers.json | Healthy non-banned peers are persisted atomically every 60 seconds and on clean shutdown, then reloaded on restart. |
| Peer gossip | GetPeers/Peers exchange bounded address lists; misbehaving peers accrue a score and are banned at the threshold. |
VPS deployment checklist
- Open only the P2P TCP port in the firewall (
18333mainnet,28333testnet). - Keep the RPC port closed or bound to
127.0.0.1. - Pass a numeric
--external-addr <PUBLIC_IP>:<PORT>; do not use a DNS name. - Run under a service manager with restart-on-failure and a dedicated unprivileged user.
- Back up the wallet file and recovery phrase separately from the chain database.
- Use
--txindexfor an explorer/archive node, or--prune <N>for a bounded-disk node, but not both.
Home-LAN cluster
Machines on the same /16 subnet can full-mesh using explicit peers. For an offline LAN, disable DNS seeds and connect each node to the others explicitly.
# Node A
./target/release/scruple node \
--network devnet --data-dir ./lan-a \
--p2p 0.0.0.0:18333 --rpc 127.0.0.1:18332 \
--external-addr 192.168.1.10:18333 \
--peer 192.168.1.11:18333 --no-dns-seeds
# Node B
./target/release/scruple node \
--network devnet --data-dir ./lan-b \
--p2p 0.0.0.0:18334 --rpc 127.0.0.1:18335 \
--external-addr 192.168.1.11:18334 \
--peer 192.168.1.10:18333 --no-dns-seeds
Pruning and transaction index
Two storage modes change what the node retains:
| Mode | Retains | Trade-offs |
|---|---|---|
--prune <N> (N ≥ 288) | All headers, the full active UTXO set, the seen-address index, and the most recent N full blocks plus undo logs. | Lower disk usage. Cannot reorg deeper than N blocks. Historical block bodies and confirmed tx lookups older than the window are unavailable. |
--txindex | Raw blocks, undo logs, and a persistent txid index across tip extensions and reorgs. | Archive-style confirmed get_tx lookups. Mutually exclusive with --prune. Backfills from stored unpruned blocks on startup. |
| Default | Raw blocks and undo logs for the full chain, without a tx index. | Full block bodies are available, but confirmed get_tx requires --txindex. |
--txindex cannot be combined with --prune. Pruned nodes discard historical block bodies that the transaction index would need. Choose one policy per data directory.
RPC cookie and authentication
On startup the node generates a fresh 32-byte random hex token, writes it to <data-dir>/.cookie with mode 0600, and accepts it through either of these headers:
X-Scruple-Cookie: <64-hex-token>
Authorization: Basic <base64("__cookie__:<64-hex-token>")>
The token is regenerated on every restart. Read it from disk at call time:
COOKIE=$(cat ./mainnet-data/.cookie)
curl -sS http://127.0.0.1:18332 \
-H "X-Scruple-Cookie: $COOKIE" \
-H 'Content-Type: application/json' \
-d '{"method":"info","params":{}}'
See JSON-RPC API for the full protocol, method reference, and client examples.
Monitoring and shutdown
# Chain, mempool, peer, and storage status
./target/release/scruple info \
--data-dir ./mainnet-data \
--rpc 127.0.0.1:18332
# Recent headers
curl -sS http://127.0.0.1:18332 \
-H "X-Scruple-Cookie: $(cat ./mainnet-data/.cookie)" \
-H 'Content-Type: application/json' \
-d '{"method":"get_headers","params":{"count":10}}'
SIGINT and SIGTERM trigger a clean shutdown: the node stops background threads, persists healthy peers to peers.json, and disconnects sessions. Avoid SIGKILL during a reorg or block write.
For a visual view of testnet blocks, transactions, and mempool activity, use the public Scruple block explorer.
Troubleshooting
| Symptom | Likely cause and fix |
|---|---|
| No peers after startup | Check the network preset, firewall, DNS, and seed settings. Devnet has no DNS seeds; pass --peer or --seed. |
| Peers connect then drop | Wrong network magic (mainnet/testnet/devnet mismatch), clock skew, or a banned IP. Check the node logs. |
| RPC returns 401 | Missing or stale cookie. Re-read <data-dir>/.cookie; it rotates on restart. |
| RPC returns 405 | The server accepts only POST. Send a JSON body with Content-Length. |
| RPC returns 413 | The request body exceeds 2,065,536 bytes. Large block submissions are hex-encoded and can approach the limit. |
get_tx says transaction not found | The node is not running with --txindex, or the transaction is older than the prune window. |
| Cannot reorg deep enough | --prune N limits reorg depth to N blocks. Increase N or run an archive node. |
| RPC bound to non-loopback | The node warns because RPC traffic is plaintext. Put a TLS reverse proxy in front, or use an SSH tunnel. |