Skip to main content

RPC | Bitcoin Glossary | Mapping Bitcoin

RPC

Desenvolvimento

Also known as: Remote Procedure Call, JSON-RPC

Remote Procedure Call, an interface provided by Bitcoin Core and other node implementations that allows external software to interact with the node programmatically. RPC commands can query blockchain data, manage wallets, create transactions, and control the node.

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 information
  • getblock — Retrieve a specific block's data
  • getblockcount — Current block height

Wallet:

  • getnewaddress — Generate a new receiving address
  • sendtoaddress — Send bitcoin to an address
  • getbalance — Check wallet balance
  • listunspent — List available UTXOs

Transactions:

  • createrawtransaction — Build an unsigned raw transaction
  • signrawtransactionwithwallet — Sign a transaction
  • sendrawtransaction — Broadcast a transaction

Network:

  • getpeerinfo — Information about connected peers
  • getnetworkinfo — 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 rpcauth credentials
  • Restrict access by IP address when possible
  • Consider using rpcwhitelist to 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).