JSON-RPC Interface Overview
The Bitcoin Core JSON-RPC interface provides programmatic access to blockchain data, wallet operations, network information, and mining functions. The headless daemonbitcoind has the JSON-RPC API enabled by default, while the GUI bitcoin-qt requires the -server option to enable it.
Endpoints
Bitcoin Core provides two JSON-RPC endpoints:Root Endpoint (/)
The root endpoint is always active and can:
- Service all non-wallet requests
- Service wallet requests when exactly one wallet is loaded
Wallet Endpoint (/wallet/<walletname>/)
The wallet endpoint:
- Only available when wallet component is compiled in
- Can service both wallet and non-wallet requests
- Required when two or more wallets are loaded
- Used automatically by
bitcoin-cliwith the-rpcwallet=parameter
Best practice: Use the
/wallet/<walletname>/ endpoint for all requests when multiple wallets are loaded.Authentication
Bitcoin Core supports multiple authentication methods:Cookie Authentication (Recommended)
When norpcpassword is specified, Bitcoin Core generates unique credentials on each restart:
- Credentials stored in
.cookiefile in the data directory - File readable only by the user running Bitcoin Core
- Automatic authentication for local RPC clients
- Most secure method for local connections
RPC Auth Script
For static credentials, use theshare/rpcauth/rpcauth.py script:
bitcoin.conf:
Manual Username/Password
Directly specify credentials inbitcoin.conf (least secure):
JSON-RPC Protocol Versions
Bitcoin Core supports both JSON-RPC 1.1 and 2.0:Version 2.0 Example
Parameter Passing
Bitcoin Core supports three parameter formats:By Position
By Name
Mixed (Named with Positional Args)
Use theargs array for initial positional values combined with named parameters:
Versioning and Deprecation
The RPC interface is implicitly versioned on Bitcoin Core’s major version:- Check version with
getnetworkinfoRPC (versionfield) - Deprecated features can be re-enabled during grace period using
-deprecatedrpc=<feature> - Release notes document deprecated features and re-enable instructions
- Breaking changes only occur between major versions
Security Best Practices
Securing the Executable
Securing Local Network Access
By default, RPC is only accessible from localhost:- Requires valid authentication credentials
- Any local program can access if credentials are compromised
- Only run trusted software on the same system
Securing Remote Network Access
For remote access:- Use only over secure private networks
- Or use VPN/SSH tunneling
- Configure
rpcallowipandrpcbindcarefully - RPC does not use encryption by default
- Credentials sent as clear text over network
Docker Security
When exposing RPC in Docker, bind only to localhost:String Handling
RPC interface only escapes data for JSON encoding:- Always validate and escape RPC data in your applications
- Display serialized data in hex form only
- Prevent injection attacks (path traversal, XSS, etc.)
Consistency Guarantees
Chain State
State returned via RPCs is guaranteed to be up-to-date with the chain state immediately prior to the call’s execution.Transaction Pool (Mempool)
Mempool state returned is:- Consistent with itself and chain state at call time
- Only includes mine-able transactions
- May not reflect very recent mempool changes
- Reflects all prior mempool/chain RPC effects
Wallet State
Wallet RPCs return state that is:- Consistent with itself and chain state
- Reflects all blocks and confirmed transactions
- May lag behind current mempool state
- BIP-125 replacements may not be immediately reflected
Limitations
Mitigation strategies:- Increase system file descriptor limit
- Limit concurrent connections to RPC interface
- Avoid making hundreds of simultaneous requests
Common RPC Categories
Bitcoin Core organizes RPCs into functional categories:- Blockchain RPCs - Query blockchain data
- Wallet RPCs - Manage wallets and transactions
- Network RPCs - Network and peer information
- Mining RPCs - Mining and block generation
- Utility RPCs - Utility functions and validation