Before We Begin: Think Like a Developer
Before diving into development tools, consider the fundamental challenges of building Bitcoin applications:
You can't practice on mainnet—mistakes could cost thousands. But testnet coins have value too. What's the solution?
Waiting 10 minutes (or 60 minutes for 6 confirmations) for every test would make development impossibly slow.
Bitcoin Core doesn't have a "click here to send" button. How do programmatic tools interact with it?
How do professional developers build, test, and deploy Bitcoin applications safely?
This module teaches you the professional Bitcoin development workflow
Bitcoin Core: Your Development Foundation
Bitcoin Core is the reference implementation of Bitcoin. It's not just a wallet—it's a complete Bitcoin node that validates all transactions and blocks according to consensus rules. For developers, it's your Swiss Army knife.
Why Bitcoin Core for Development?
- Reference Implementation: The authoritative Bitcoin protocol implementation
- Full Validation: Independently verify every transaction and block
- RPC Interface: Programmatic access to all Bitcoin functionality
- Built-in Wallet: Create transactions, manage keys, sign PSBTs
- Regtest Mode: Your personal Bitcoin network for instant testing
Installation
1Download Bitcoin Core
Visit bitcoincore.org/en/download/ and download the latest version for your operating system.
2Verify the Download
Always verify signatures! This is critical for security:
# Import Bitcoin Core release signing keys
gpg --keyserver hkps://keys.openpgp.org --recv-keys \
01EA5486DE18A882D4C2684590C8019E36C2E964
# Verify the signature
gpg --verify SHA256SUMS.asc SHA256SUMS
# Check file hash
sha256sum --ignore-missing --check SHA256SUMS
3Install Bitcoin Core
Extract and install based on your OS:
# Linux/macOS
tar -xzf bitcoin-*.tar.gz
sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin-*/bin/*
# Verify installation
bitcoind --version
⚠️ Development Setup Note
For development, you don't need to sync the entire mainnet blockchain (500+ GB). We'll use regtest mode which creates a private blockchain on your machine. Perfect for testing!
Regtest Mode: Your Personal Bitcoin Network
Regression Test Mode (regtest) is a local Bitcoin network where you have complete control. Mine blocks instantly, reset the chain anytime, and test without limits.
Why Regtest?
- Instant blocks: Mine blocks on demand (no 10-minute wait)
- Free coins: Mine as much BTC as you need for testing
- Complete control: Reset, reorganize, test edge cases
- Isolated: No network connection needed, completely private
- Fast iteration: Test, break, reset, repeat
Configuring Bitcoin Core for Regtest
Create a bitcoin.conf file for your development environment:
# ~/.bitcoin/bitcoin.conf (or your custom datadir)
# Enable regtest mode
regtest=1
# RPC Settings
server=1
rpcuser=your_username
rpcpassword=your_strong_password
rpcallowip=127.0.0.1
# Network settings
listen=0
dnsseed=0
upnp=0
# Development preferences
txindex=1 # Index all transactions (useful for development)
blockfilterindex=1 # Enable compact block filters
fallbackfee=0.00001 # Default fee rate
# Logging (helpful for debugging)
debug=rpc
debug=net
Security Note
The RPC credentials in your bitcoin.conf control your node. For development,
simple passwords are fine. For production or mainnet nodes, use strong passwords and consider
rpcauth instead of plain rpcpassword.
Starting Bitcoin Core in Regtest
# Start bitcoind in regtest mode
bitcoind -regtest -daemon
# Or specify a custom datadir
bitcoind -regtest -datadir=/path/to/dev/datadir -daemon
# Check it's running
bitcoin-cli -regtest getblockchaininfo
You should see output showing 0 blocks, confirming you have a fresh regtest network!
Bitcoin RPC: Controlling Bitcoin Core Programmatically
The Remote Procedure Call (RPC) interface is how your applications communicate with Bitcoin Core.
It's a JSON-RPC interface accessible via HTTP or through bitcoin-cli.
Essential RPC Commands
Blockchain Information:
# Get blockchain status
bitcoin-cli -regtest getblockchaininfo
# Get network info
bitcoin-cli -regtest getnetworkinfo
# Get wallet info
bitcoin-cli -regtest getwalletinfo
# Get mempool info
bitcoin-cli -regtest getmempoolinfo
Wallet Operations:
# Create a new wallet
bitcoin-cli -regtest createwallet "dev_wallet"
# Get a new address
bitcoin-cli -regtest getnewaddress
# Get wallet balance
bitcoin-cli -regtest getbalance
# List unspent outputs (UTXOs)
bitcoin-cli -regtest listunspent
# Send bitcoin
bitcoin-cli -regtest sendtoaddress "bcrt1q..." 1.5
Transaction Operations:
# Get raw transaction
bitcoin-cli -regtest getrawtransaction "txid" true
# Decode raw transaction
bitcoin-cli -regtest decoderawtransaction "hex"
# Create raw transaction
bitcoin-cli -regtest createrawtransaction '[...]' '{...}'
# Sign raw transaction
bitcoin-cli -regtest signrawtransactionwithwallet "hex"
# Send raw transaction
bitcoin-cli -regtest sendrawtransaction "hex"
Using RPC from Code
Most Bitcoin applications use RPC libraries. Here's an example using Python:
from bitcoinrpc.authproxy import AuthServiceProxy
# Connect to Bitcoin Core
rpc_connection = AuthServiceProxy(
"http://your_username:your_password@127.0.0.1:18443"
)
# Get blockchain info
info = rpc_connection.getblockchaininfo()
print(f"Chain: {info['chain']}")
print(f"Blocks: {info['blocks']}")
# Create a new address
new_address = rpc_connection.getnewaddress()
print(f"New address: {new_address}")
# Get balance
balance = rpc_connection.getbalance()
print(f"Balance: {balance} BTC")
RPC Documentation
Bitcoin Core has excellent built-in documentation. Use bitcoin-cli help to see all commands,
and bitcoin-cli help <command> for detailed information about specific commands.
Creating Test Wallets and Mining Blocks
Now let's put it all together: create wallets, generate addresses, mine blocks, and send transactions.
Step-by-Step: Your First Regtest Workflow
1Create Development Wallets
# Create two wallets for testing
bitcoin-cli -regtest createwallet "alice"
bitcoin-cli -regtest createwallet "bob"
# Load a wallet
bitcoin-cli -regtest -rpcwallet=alice getwalletinfo
2Generate Addresses
# Get Alice's address
bitcoin-cli -regtest -rpcwallet=alice getnewaddress
# Get Bob's address
bitcoin-cli -regtest -rpcwallet=bob getnewaddress
# Generate a P2WPKH (native SegWit) address
bitcoin-cli -regtest -rpcwallet=alice getnewaddress "" "bech32"
3Mine Blocks to Alice
# Generate 101 blocks to Alice's address (coinbase requires 100 confirmations)
ALICE_ADDR=$(bitcoin-cli -regtest -rpcwallet=alice getnewaddress)
bitcoin-cli -regtest generatetoaddress 101 $ALICE_ADDR
# Check Alice's balance
bitcoin-cli -regtest -rpcwallet=alice getbalance
# Output: 50.00000000 (one mature coinbase)
Why 101 blocks? Coinbase transactions (mining rewards) require 100 confirmations before they can be spent. Mining 101 blocks gives us 1 spendable coinbase.
4Send Transaction from Alice to Bob
# Get Bob's address
BOB_ADDR=$(bitcoin-cli -regtest -rpcwallet=bob getnewaddress)
# Alice sends 10 BTC to Bob
bitcoin-cli -regtest -rpcwallet=alice sendtoaddress $BOB_ADDR 10
# Mine a block to confirm the transaction
bitcoin-cli -regtest generatetoaddress 1 $ALICE_ADDR
# Check balances
bitcoin-cli -regtest -rpcwallet=alice getbalance
# ~40 BTC (50 - 10 sent, plus new coinbase)
bitcoin-cli -regtest -rpcwallet=bob getbalance
# 10 BTC
5Inspect Transactions
# List recent transactions
bitcoin-cli -regtest -rpcwallet=alice listtransactions
# Get detailed transaction info
TXID=$(bitcoin-cli -regtest -rpcwallet=alice listtransactions | jq -r '.[0].txid')
bitcoin-cli -regtest getrawtransaction $TXID true
# See the UTXO set
bitcoin-cli -regtest -rpcwallet=alice listunspent
Hands-On Exercise: Build a Mini Blockchain
Goal: Practice the complete regtest workflow
Tasks:
- Start Bitcoin Core in regtest mode
- Create three wallets: "miner", "merchant", "customer"
- Mine 150 blocks to the miner wallet
- Send 25 BTC from miner to merchant
- Send 5 BTC from merchant to customer
- Verify all balances are correct
- Export the transaction hex and decode it
- Inspect the UTXOs for each wallet
Bonus Challenge:
- Create a multisig address (2-of-3) using addresses from all three wallets
- Send funds to the multisig address
- Create a transaction spending from the multisig (requires 2 signatures)
Show Solution
# Start Bitcoin Core
bitcoind -regtest -daemon
# Create wallets
bitcoin-cli -regtest createwallet "miner"
bitcoin-cli -regtest createwallet "merchant"
bitcoin-cli -regtest createwallet "customer"
# Mine blocks
MINER_ADDR=$(bitcoin-cli -regtest -rpcwallet=miner getnewaddress)
bitcoin-cli -regtest generatetoaddress 150 $MINER_ADDR
# Send transactions
MERCHANT_ADDR=$(bitcoin-cli -regtest -rpcwallet=merchant getnewaddress)
bitcoin-cli -regtest -rpcwallet=miner sendtoaddress $MERCHANT_ADDR 25
CUSTOMER_ADDR=$(bitcoin-cli -regtest -rpcwallet=customer getnewaddress)
bitcoin-cli -regtest -rpcwallet=merchant sendtoaddress $CUSTOMER_ADDR 5
# Confirm transactions
bitcoin-cli -regtest generatetoaddress 1 $MINER_ADDR
# Check balances
bitcoin-cli -regtest -rpcwallet=miner getbalance
bitcoin-cli -regtest -rpcwallet=merchant getbalance
bitcoin-cli -regtest -rpcwallet=customer getbalance
Advanced Regtest Techniques
Testing Edge Cases
Regtest lets you test scenarios that are hard to reproduce on testnet:
# Simulate a chain reorganization
bitcoin-cli -regtest invalidateblock <block_hash>
bitcoin-cli -regtest reconsiderblock <block_hash>
# Create a transaction with custom fee
bitcoin-cli -regtest -rpcwallet=alice sendtoaddress $ADDR 1 "" "" true 10
# Test Replace-By-Fee (RBF)
bitcoin-cli -regtest -rpcwallet=alice sendtoaddress $ADDR 1 "" "" false false 1 "unset" null true
# Create unconfirmed transaction chains
# (send transaction, don't mine, send another spending the output)
Using Bitcoin-CLI with Scripts
#!/bin/bash
# dev-setup.sh - Quick regtest environment setup
# Start Bitcoin Core
bitcoind -regtest -daemon
sleep 2
# Create wallets
bitcoin-cli -regtest createwallet "dev" > /dev/null 2>&1
# Mine blocks
ADDR=$(bitcoin-cli -regtest -rpcwallet=dev getnewaddress)
bitcoin-cli -regtest generatetoaddress 101 $ADDR > /dev/null
# Display status
echo "Regtest environment ready!"
echo "Balance: $(bitcoin-cli -regtest -rpcwallet=dev getbalance) BTC"
echo "Blocks: $(bitcoin-cli -regtest getblockcount)"
echo "Address: $ADDR"
Connecting Multiple Nodes
You can run multiple regtest nodes and connect them to test P2P behavior:
# Start two nodes on different ports
bitcoind -regtest -port=18444 -rpcport=18443 -datadir=~/.bitcoin-node1 -daemon
bitcoind -regtest -port=18445 -rpcport=18444 -datadir=~/.bitcoin-node2 -daemon
# Connect them
bitcoin-cli -regtest -rpcport=18443 addnode "127.0.0.1:18445" "add"
# Verify connection
bitcoin-cli -regtest -rpcport=18443 getpeerinfo
Key Takeaways
- Bitcoin Core is the reference implementation and primary development tool
- Regtest mode creates a private blockchain for instant, cost-free testing
- The RPC interface provides programmatic access to all Bitcoin Core functionality
- Always verify Bitcoin Core downloads with GPG signatures
- Coinbase outputs require 100 confirmations before spending
- bitcoin-cli is your primary tool for interacting with Bitcoin Core
- Test wallets allow you to simulate real-world scenarios safely
- Regtest enables testing of edge cases impossible on testnet
- Development workflow: regtest → testnet → mainnet
Next: Building with Bitcoin
Now that you have a complete development environment, you're ready to build! In Module 2, we'll use this setup to create transactions from scratch, build a HD wallet, and construct a full Bitcoin application.
Keep your regtest environment running—you'll need it for all the hands-on exercises in the next module!
✓ Knowledge Check
Test your understanding of Bitcoin development environments with these practical questions.
1. What is the primary purpose of regtest mode?
2. How do applications communicate with Bitcoin Core programmatically?
3. Why do you need to mine 101 blocks in regtest before having spendable bitcoin?
4. Which command would you use to get a detailed help message about a specific RPC command?
5. What is the proper development workflow for Bitcoin applications?