> ## Documentation Index
> Fetch the complete documentation index at: https://www.bitnob.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Bitnob API requests authenticate with an `X-Auth-Client` API key header against https://api.bitnob.com.
> Always use the sandbox environment for testing. Never put live API keys in sample code.
> Money amounts are integers in the smallest unit of the currency (satoshis for BTC, cents for fiat). Never use floats.
> Every state-changing request takes a client-supplied `reference` and must be treated as idempotent on retry.
> Quotes expire. Re-quote rather than reusing a stale quote id.

# Module 4: Using Regtest to simulate Bitcoin

> A private regtest chain lets you mine blocks on demand and test integrations without real funds.

## Learning objectives

* Understand the purpose and power of Bitcoin Core's regtest mode
* Set up a private, fully controlled Bitcoin network
* Mine blocks and confirm transactions instantly
* Use regtest for API testing, integration flows, and simulations

## Why Regtest matters

regtest stands for Regression Test mode. It is a fully offline, developer-first Bitcoin network that:

* Has no network peers (your node is the entire network)
* Lets you mine blocks instantly
* Offers free test coins and instant transaction confirmation
* Works perfectly with automated testing, CI flows, and local wallets

For building real Bitcoin apps, regtest is the fastest and safest sandbox.

## Setting up a fully isolated Bitcoin environment

Start your node in regtest mode:

```bash theme={null}
bitcoind -regtest -daemon
```

This creates:

* \~/.bitcoin/regtest/ as your data directory
* A zero-block chain, ready to mine
* No connections to testnet, mainnet, or the internet

You can confirm the mode using:

```bash theme={null}
bitcoin-cli -regtest getblockchaininfo
```

Look for "chain": "regtest"

## Mining blocks instantly

Regtest allows manual block generation.

First, create a wallet and get a new address:

```bash theme={null}
bitcoin-cli -regtest createwallet "miner"
bitcoin-cli -regtest getnewaddress
```

Now mine 101 blocks (to unlock coinbase rewards):

```bash theme={null}
bitcoin-cli -regtest generatetoaddress 101 <your_address>
```

This gives you spendable BTC for testing.

You can generate 1 block at a time to simulate confirmation behavior.

## Sending transactions instantly

With freshly mined coins, you can now send BTC. Regtest has no fee history, so make sure `fallbackfee=0.0001` is set in `bitcoin.conf` (see module 1):

```bash theme={null}
bitcoin-cli -regtest sendtoaddress <destination> 1.5
```

Check mempool:

```bash theme={null}
bitcoin-cli -regtest getrawmempool
```

Confirm instantly by mining a block:

```bash theme={null}
bitcoin-cli -regtest generatetoaddress 1 <miner_address>
```

Now check the recipient’s balance, from the wallet that holds \<destination>:

```bash theme={null}
bitcoin-cli -regtest -rpcwallet=<recipient_wallet> getbalance
```

## GUI alternative: Polar

Polar is a desktop app that sets up a regtest Bitcoin + Lightning network for you using Docker.

Why use it?

No terminal needed

Visual interface for nodes, wallets, payments

Supports Bitcoin Core + LND + Core Lightning

🖥️ If you prefer a GUI for testing, Polar is highly recommended. It is especially useful for team demos, education, and debugging.

Install it via:

1. macOS: brew install --cask polar
2. Linux: .AppImage from GitHub
3. Windows: .exe installer

You can still inspect logs, addresses, and transactions under the hood.

## Activity

Set up a regtest sandbox from scratch:

1. Start bitcoind in regtest mode.
2. Create a wallet named activity\_wallet, generate 101 blocks (replace \<your\_address> with an address from the new wallet).
3. Send 2 test transactions (replace \<destination\_1>, \<destination\_2> with valid addresses).
4. Mine 1 block to confirm (use the same \<your\_address> as before or another address in activity\_wallet).
5. Use listtransactions to view history.

Wallets that understand UTXOs deeply will control fees, preserve privacy, and scale cleanly over time.

Bonus:

Try doing the same flow inside Polar


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.