RPC Commands Reference
This document provides a guide for interacting with your Bitcoin node using both curl and bitcoin-cli commands via RPC.
Try it live! Test these commands directly in the Bitcoin CLI Terminal. Connected to mainnet, no setup required.
RPC Configuration
bitcoin.conf Setup
Add these settings to your bitcoin.conf file:
# RPC Server Settings
server=1
rpcuser=your_username
rpcpassword=your_secure_password
rpcport=8332
# Restrict RPC to localhost (recommended)
rpcbind=127.0.0.1
rpcallowip=127.0.0.1
# Optional: Enable transaction index for full tx lookups
txindex=1
Environment Variables
# Set environment variables (replace with your actual credentials)
export BITCOIN_RPC_USER="your_username"
export BITCOIN_RPC_PASSWORD="your_password"
export BITCOIN_RPC_PORT="8332"
Basic RPC Structure
# Set up alias for easier use
alias btc='bitcoin-cli -rpcuser=$BITCOIN_RPC_USER -rpcpassword=$BITCOIN_RPC_PASSWORD -rpcport=$BITCOIN_RPC_PORT'
# Then use simple commands
btc <method_name> [parameters]
Programmatic RPC Access
For building applications, you can interact with Bitcoin Core RPC programmatically:
Essential Node Information Commands
1. Blockchain Information
btc getblockchaininfo
Key fields to monitor:
blocks: Current block heightheaders: Number of headers downloadedverificationprogress: Sync progress (0.0 to 1.0)initialblockdownload: Whether still in IBDpruned: Whether node is pruned
2. Network Information
btc getnetworkinfo
Key fields:
connections: Total peer connectionsconnections_in: Incoming connectionsconnections_out: Outgoing connectionsversion: Bitcoin Core versionsubversion: Detailed version info
3. Mempool Information
btc getmempoolinfo
Key fields:
size: Number of transactions in mempoolbytes: Total mempool size in bytestotal_fee: Total fees in mempool
4. Block Information
# Get latest block hash
btc getbestblockhash
# Get block by hash
btc getblock <block_hash>
# Get block by height
btc getblockhash <height>
5. Transaction Information
# Get transaction by ID
btc getrawtransaction <txid> true
# Get transaction from mempool
btc getmempoolentry <txid>
Wallet Commands
6. Wallet Information
# List wallets
btc listwallets
# Get wallet info
btc getwalletinfo
# Get balance
btc getbalance
7. Wallet Management
# List all loaded wallets
btc listwallets
# Get info about specific wallet
btc -rpcwallet=<walletname> getwalletinfo
# Unload a wallet (removes from memory)
btc unloadwallet <walletname>
# Load a wallet
btc loadwallet <walletname>
# Get transactions from specific wallet
btc -rpcwallet=<walletname> listtransactions "*" 100
# Get balance from specific wallet
btc -rpcwallet=<walletname> getbalance
Advanced Diagnostic Commands
8. Index Information
# Check if transaction index is available
btc getindexinfo
# Calculate indexing progress percentage
btc getindexinfo | jq '.txindex.best_block_height / 880000 * 100'
# Check if indexing is complete
btc getindexinfo | jq '.txindex.synced'
# Monitor indexing in real-time (updates every 30 seconds)
watch -n 30 'btc getindexinfo | jq ".txindex.best_block_height"'
9. UTXO Set Information
The UTXO Set is the complete database of all unspent transaction outputs. These commands allow you to query information about it.
# Get UTXO set statistics (can be slow)
btc gettxoutsetinfo
# Get specific fields
btc gettxoutsetinfo | jq '{total_amount, transactions, height}'
10. Peer Information
# Get peer information
btc getpeerinfo
# Get connection summary
btc getnetworkinfo | jq '{connections, connections_in, connections_out}'
11. ZMQ Notifications
ZeroMQ provides real-time notifications for blockchain events, enabling instant detection of new blocks and transactions without polling.
Configuration
Add to your bitcoin.conf:
# ZMQ Notifications
zmqpubhashblock=tcp://127.0.0.1:28332
zmqpubhashtx=tcp://127.0.0.1:28333
zmqpubrawblock=tcp://127.0.0.1:28334
zmqpubrawtx=tcp://127.0.0.1:28335
Benefits
- Instant notifications: No polling delays
- Lower resource usage: No constant RPC calls
- Better reliability: Catches blocks even after node restarts
- Real-time monitoring: Perfect for blockchain monitoring applications
Verification
# Check if ZMQ is enabled in Bitcoin logs
grep -i zmq ~/.bitcoin/debug.log
# Check Bitcoin help for ZMQ options
bitcoind -h | grep zmq
Troubleshooting
Connection Issues
# Test RPC connection
btc getblockchaininfo | jq '.chain'
# Check network status
btc getnetworkinfo | jq '{connections, connections_in, connections_out}'
# Verify wallet is accessible
btc getwalletinfo | jq '{walletname, txcount, balance}'
# Check if node is still syncing
btc getblockchaininfo | jq '{verificationprogress, initialblockdownload}'
Common RPC Error Codes
| Code | Meaning | Solution |
|---|---|---|
| -1 | General error | Check logs for details |
| -5 | Invalid address or key | Verify input format |
| -8 | Invalid parameter | Check parameter types |
| -25 | Transaction verification failed | Check inputs/outputs |
| -26 | Transaction already in mempool | Already broadcast |
| -27 | Transaction already in chain | Already confirmed |
| -28 | Node initializing | Wait for startup |
Log Monitoring
# Check recent activity in logs
tail -20 ~/.bitcoin/debug.log
# Monitor logs in real-time
tail -f ~/.bitcoin/debug.log
# Check for errors in logs
grep -i error ~/.bitcoin/debug.log | tail -10
JSON Output Formatting
To make the output more readable, pipe through jq:
# Install jq if not available
# macOS: brew install jq
# Ubuntu: apt install jq
btc getblockchaininfo | jq '{blocks, verificationprogress}'
Resources
- mempool.space: Real-time Bitcoin mempool and block explorer
- Clark Moody's Bitcoin Dashboard: Bitcoin metrics and analytics
- Bitcoin Core GitHub: Bitcoin Core source code repository
- Bitcoin Core RPC Docs: Official RPC documentation
