Learning objectives
- Build realistic Bitcoin development environments using regtest
- Write scripts to simulate wallet activity and transaction flows
- Mock confirmations, chain reorganizations, and mempool states
- Understand when and how to separate your wallet and node services in production
Building testing environments using Regtest
regtest is Bitcoin Core’s regression testing mode, designed for isolated, fully controlled environments. You can:- Spin up a node without syncing to any peers
- Mine blocks instantly
- Generate unlimited test BTC
- Simulate any transaction scenario
- Transaction pipelines
- Webhooks and callbacks
- Wallet-to-wallet transfers
- Payment monitoring flows
- bitcoind -regtest -daemon
- bitcoin-cli or a language-based RPC client
- Optional scripts and mocks for block generation, fees, and UTXOs
Writing integration scripts in bash and Python
Bitcoin Core exposes a JSON-RPC interface, so any scripting language that supports HTTP requests can interact with it.Bash script to mine, fund, and send
Python script using requests
- CI tests
- Sandbox payment flows
- Automated funding or sweep logic
Mocking confirmations and network events
Simulating confirmations
Send a transaction:Simulating re-orgs
- Invalidate a previously mined block:
- Create a longer competing chain:
- Dropped/unconfirmed transactions
- Edge case user experiences
- Fallback logic for timeouts
Production notes
When to Use a Pruned Node A pruned node deletes historical block data but retains the full UTXO set and validates blocks. Use pruning if:- You don’t need to inspect old transactions
- You’re running lightweight infrastructure
- You want to reduce disk usage (~15GB vs 800GB+)
Example Workflow
Deposit Flow
- App requests an address → Wallet service calls getnewaddress
- Payment arrives → Wallet service tracks it with gettransaction
- Required confirmations reached → App credits the user
- App prepares TX → Wallet service calls createrawtransaction
- Wallet signs → signrawtransactionwithwallet
- Node broadcasts → sendrawtransaction
Activity
Write a Bash or Python script that:- Starts a wallet
- Mines 101 blocks
- Sends BTC to 3 addresses
- Confirms each transaction with block generation
- Verifies balances
- A zero-conf state
- A re-org scenario
- Use of decoderawtransaction to verify TXs