mirror of
				https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
				synced 2025-11-04 04:17:43 +00:00 
			
		
		
		
	Create first draft of Chapter 15
This commit is contained in:
		
							parent
							
								
									723f929f0c
								
							
						
					
					
						commit
						9d7f073a1e
					
				
							
								
								
									
										18
									
								
								15_0_Setting_Up_a_Bitcoin_Regtest.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								15_0_Setting_Up_a_Bitcoin_Regtest.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,18 @@
 | 
			
		||||
# Chapter 15: Setting Up a Bitcoin Regtest
 | 
			
		||||
 | 
			
		||||
While developing Bitcoin applications, it might happen that you want to use your applications isolated from any public Blockchain such as the Mainnet or the Testnet.
 | 
			
		||||
You can create a Blockchain from scratch using the Regtest, with one main advantage over Testnet: you choose when to create new blocks, so you have complete control over the environment.
 | 
			
		||||
 | 
			
		||||
## Objectives for This Chapter
 | 
			
		||||
 | 
			
		||||
After working through this chapter, a developer will be able to:
 | 
			
		||||
 | 
			
		||||
   * Create your own Blockchain from scratch
 | 
			
		||||
   * Create the Genesis block and more blocks on top of it
 | 
			
		||||
   * Get balance and interact with Bitcoind in a private way
 | 
			
		||||
   
 | 
			
		||||
## Table of Contents
 | 
			
		||||
 | 
			
		||||
  * [Section One: Building the Regtest](15_1_Building_the_Regtest.md)
 | 
			
		||||
  * [Section Two: Testing with Regtest](15_2_Testing_with_Regtest.md)
 | 
			
		||||
  * [Section Three: Mining with Regtest](15_3_Mining_with_Regtest.md)
 | 
			
		||||
							
								
								
									
										34
									
								
								15_1_Building_the_Regtest.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								15_1_Building_the_Regtest.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
			
		||||
# 15.1: Building the Regtest
 | 
			
		||||
 | 
			
		||||
> **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.
 | 
			
		||||
 | 
			
		||||
This document explains how to build a Regtest (Regression Test) by hand to be able to develop new applications without the need to interact with other peers and blocks.
 | 
			
		||||
Bitcoin Core’s regression test mode (regtest mode) lets you instantly create a brand-new private block chain with the same basic rules as testnet—but one major difference: you choose when to create new blocks, so you have complete control over the environment.
 | 
			
		||||
 | 
			
		||||
## Starting Bitcoind in Regtest Mode
 | 
			
		||||
 | 
			
		||||
To start your bitcoind (Bitcoin Daemon) in Regtest mode and create a private Blockchain, you have to use the following command:
 | 
			
		||||
```
 | 
			
		||||
$ bitcoind -regtest -daemon
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Generating blocks
 | 
			
		||||
 | 
			
		||||
You can generate/mine new blocks using the RPC method `generate`. This method is only available in the Regtest mode, using the following command:
 | 
			
		||||
```
 | 
			
		||||
$ bitcoin-cli -regtest generate 101
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
This command will generate 101 blocks using a special RPC which is only available in regtest mode. This takes less than a second on a generic PC. 
 | 
			
		||||
Because this is a new block chain using Bitcoin’s default rules, the first blocks pay a block reward of 50 bitcoins. 
 | 
			
		||||
Unlike mainnet, in regtest mode only the first 150 blocks pay a reward of 50 bitcoins. 
 | 
			
		||||
However, a block must have 100 confirmations before that reward can be spent, so we generate 101 blocks to get access to the coinbase transaction from block #1.
 | 
			
		||||
 | 
			
		||||
## Verifying balance
 | 
			
		||||
 | 
			
		||||
After mining blocks and getting the reward for the first one, you can verify the balance on your wallet:
 | 
			
		||||
```
 | 
			
		||||
$ bitcoin-cli -regtest getbalance
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Now you can use this balance for any kind of interaction with the private Blockchain, such as sending Bitcoin transactions according to [Chapter 4]((04_0_Sending_Bitcoin_Transactions.md)) in this guide.
 | 
			
		||||
							
								
								
									
										11
									
								
								15_2_Testing_with_Regtest.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								15_2_Testing_with_Regtest.md
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,11 @@
 | 
			
		||||
# 15.2: Testing with Regtest
 | 
			
		||||
 | 
			
		||||
> **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.
 | 
			
		||||
 | 
			
		||||
This document explains how to test a Regtest (Regression Test).
 | 
			
		||||
 | 
			
		||||
## Testing with Regtest
 | 
			
		||||
 | 
			
		||||
After [starting Bitcoind using Regtest mode](15_1_Building_the_Regtest.md) you can use any `bitcoin-cli` command or interact with the blockchain using the RPC (Remote Procedure Call) service.
 | 
			
		||||
 | 
			
		||||
You can try to create transactions referring to [Chapter 4 - Sending Bitcoin Transactions](04_0_Sending_Bitcoin_Transactions.md) in this guide. In order to get balance in your Regtest Wallet, you are able to [mine blocks with minimal proof-of-work and get the rewards](15_3_Mining_with_Regtest.md).
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user