Overview
The RPC (Remote Procedure Call) interface is the primary programmatic way to interact with a Bitcoin full node. Bitcoin Core exposes a JSON-RPC server that accepts commands over HTTP, allowing wallets, block explorers, payment processors, and custom applications to query blockchain data, construct transactions, manage wallets, and control the node's behavior.
How RPC Works
RPC Architecture:
┌──────────────────┐ ┌──────────────────────┐
│ Client │ HTTP │ Bitcoin Core Node │
│ (application, │────────>│ │
│ script, or │ JSON │ ┌────────────────┐ │
│ bitcoin-cli) │<────────│ │ RPC Server │ │
│ │ │ │ (port 8332) │ │
└──────────────────┘ │ └───────┬────────┘ │
│ │ │
│ ┌───────▼────────┐ │
│ │ Blockchain │ │
│ │ + Wallet │ │
│ │ + Mempool │ │
│ │ + Network │ │
│ └────────────────┘ │
└──────────────────────┘
Common RPC Commands
RPC commands are organized into several categories:
Blockchain:
getblockchaininfo— General blockchain state informationgetblock— Retrieve a specific block's datagetblockcount— Current block height
Wallet:
getnewaddress— Generate a new receiving addresssendtoaddress— Send bitcoin to an addressgetbalance— Check wallet balancelistunspent— List available UTXOs
Transactions:
createrawtransaction— Build an unsigned raw transactionsignrawtransactionwithwallet— Sign a transactionsendrawtransaction— Broadcast a transaction
Network:
getpeerinfo— Information about connected peersgetnetworkinfo— Network state and configuration
Authentication
RPC access is protected by username/password authentication configured in bitcoin.conf. The default configuration only allows connections from localhost. The rpcauth option generates salted password hashes for secure authentication, and rpcallowip can be used to permit connections from specific remote addresses (though this should be done with extreme caution and ideally over an encrypted tunnel).
bitcoin-cli
Bitcoin Core includes bitcoin-cli, a command-line tool that communicates with the node via RPC. It handles authentication and formatting, providing a convenient way to interact with the node:
bitcoin-cli getblockchaininfo
bitcoin-cli getbalance
bitcoin-cli sendtoaddress "bc1q..." 0.001
Security Considerations
The RPC interface provides full control over a node and its wallet, including the ability to send bitcoin. It should be treated as a high-security interface:
- Never expose the RPC port to the public internet
- Use strong, unique
rpcauthcredentials - Restrict access by IP address when possible
- Consider using
rpcwhitelistto limit which commands specific users can execute
Common Misconception
RPC is not the same as the P2P network protocol. The P2P protocol is how nodes communicate with each other (exchanging blocks and transactions). RPC is how external applications communicate with a single node. They serve entirely different purposes and use different ports (8333 for P2P, 8332 for RPC on mainnet).