Learning objectives
- Understand how bitcoin-cli and raw RPC calls work under the hood
- Make authenticated JSON-RPC requests using curl
- Configure and secure your RPC credentials
- Learn best practices for securing RPC access in production environments
bitcoin-cli vs curl RPC calls
When you run:- Method: what you want to execute (eg. getnewaddress )
- params: arguments in array format
- id: request ID (any unique string)
- jsonrpc: always “1.0” for Bitcoin Core
Reading and writing raw JSON requests
Example 1: Get a new addressAuthentication options
Cookie-based (default & recommended) Bitcoin Core writes an auth cookie to:Securing RPC on real nodes
Never expose RPC publicly. Always bind to localhost or use strict firewall rules. Key configuration options:- Use cookie auth or a strong password
- Disable or restrict RPC access by IP
- Avoid exposing RPC over HTTP (use HTTPS reverse proxy if needed)
- Regularly rotate rpcpassword if using manual auth
Activity
- Create a JSON-RPC payload to get a new address.
- Use curl to post the payload to your running regtest node.
- Inspect the .cookie file and try using it for auth.
- Update your bitcoin.conf with rpcuser and rpcpassword , restart, and authenticate manually
- Attempt a bad request and read the JSON-RPC error response.