Bitcoin for Builders Lab

Developer environment and a local regtest lab

Run a private Bitcoin network on your own computer, mine blocks on demand, and fund a test wallet in minutes.

45 minBeginner1 / 8

Draft: this lesson is still waiting for review.

What you'll learn

  • Start a disposable regtest node with Bitcoin Core
  • Create a wallet, mine blocks and explain coinbase maturity
  • Reset your lab cleanly between experiments

Key terms

regtest
A private Bitcoin test network you control, where blocks are mined instantly.
node (nodi)
A computer running Bitcoin or Lightning software that checks every rule for itself.
block (bloku)
A batch of transactions added to the blockchain about every 10 minutes.
mining (uchimbaji)
Computers competing to add the next block, paid in new bitcoin and fees.
wallet (pochi)
An app or device that stores your keys and lets you send and receive bitcoin. It doesn't hold the coins themselves.

regtest is a private Bitcoin network that only you can see. Mining is instant, coins are free, and mistakes cost nothing. Every lesson in this path uses it as your lab.

Step 1: Three networks, one program

The same Bitcoin Core program can join three kinds of network. Think of a driving school:

  • Mainnet is the highway: real traffic, real money, real consequences. You don't learn here.
  • Testnet and signet are a shared practice track. Other learners are on it too, and you wait for its blocks like everyone else.
  • Regtest is your own empty car park. Nobody else is there, and a block appears the moment you ask for one.

Two programs do the work. bitcoind is the node itself, running in the background, and bitcoin-cli is how you talk to it. Everything the node knows lives in its data directory, so deleting that folder gives you a brand-new chain.

One rule will surprise you in Step 3: a miner's reward can't be spent until 100 more blocks are built on top of it. Bitcoin calls this coinbase maturity.

Done when: you can say, in your own words, why your first test coins only become spendable after 101 blocks.

Step 2: Install and start a node

Install Bitcoin Core from the official download page, or use a Docker image you trust. Then:

bitcoind -regtest -daemon -fallbackfee=0.0001
bitcoin-cli -regtest getblockchaininfo

Expected: JSON with "chain": "regtest" and "blocks": 0.

Done when: the node answers getblockchaininfo.

Step 3: Mine, fund and check

bitcoin-cli -regtest createwallet "alice"
ADDR=$(bitcoin-cli -regtest -rpcwallet=alice getnewaddress)
bitcoin-cli -regtest generatetoaddress 101 "$ADDR"
bitcoin-cli -regtest -rpcwallet=alice getbalance

Expected: a balance of 50.00000000. You mined 101 blocks, but only the first block's reward has matured.

Try generatetoaddress 1 again and check the balance. Can you predict the new number before you look?

Done when: you can explain why the balance after 101 blocks is 50, not 5,050.

Step 4: Reset

bitcoin-cli -regtest stop
rm -rf ~/.bitcoin/regtest   # on macOS: ~/Library/Application Support/Bitcoin/regtest

Starting from a clean datadir makes experiments repeatable, which is exactly what you want for automated tests later.

Lab evidence

Save these in a notes file; the final project asks for them:

  • The output of getblockchaininfo showing "chain": "regtest".
  • Your balance after mining 101 blocks, and after one more.
  • One sentence on what surprised you.

Reflect

Write your answer down, or talk it over with a friend or your chama.

  1. Explain regtest to a teammate without jargon. What problem does it solve?
  2. What could go wrong if you tested your code against mainnet instead?

Check yourself

Question 1 of 4What is regtest?

Further reading

An original Bitsacco Jifunze lesson. Licence: CC BY-SA 4.0.