From 9d7f073a1ebdc172a1910f02ffd34ff680524dd2 Mon Sep 17 00:00:00 2001 From: Bruno Volpato Date: Tue, 12 Dec 2017 11:57:37 -0800 Subject: [PATCH] Create first draft of Chapter 15 --- 15_0_Setting_Up_a_Bitcoin_Regtest.md | 18 +++++++++++++++ 15_1_Building_the_Regtest.md | 34 ++++++++++++++++++++++++++++ 15_2_Testing_with_Regtest.md | 11 +++++++++ 3 files changed, 63 insertions(+) create mode 100644 15_0_Setting_Up_a_Bitcoin_Regtest.md create mode 100644 15_1_Building_the_Regtest.md create mode 100644 15_2_Testing_with_Regtest.md diff --git a/15_0_Setting_Up_a_Bitcoin_Regtest.md b/15_0_Setting_Up_a_Bitcoin_Regtest.md new file mode 100644 index 0000000..c5602e8 --- /dev/null +++ b/15_0_Setting_Up_a_Bitcoin_Regtest.md @@ -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) diff --git a/15_1_Building_the_Regtest.md b/15_1_Building_the_Regtest.md new file mode 100644 index 0000000..219047f --- /dev/null +++ b/15_1_Building_the_Regtest.md @@ -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. diff --git a/15_2_Testing_with_Regtest.md b/15_2_Testing_with_Regtest.md new file mode 100644 index 0000000..6167277 --- /dev/null +++ b/15_2_Testing_with_Regtest.md @@ -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).