mirror of
https://github.com/ChristopherA/Learning-Bitcoin-from-the-Command-Line.git
synced 2025-06-07 16:06:26 +00:00
Improvements
This commit is contained in:
parent
f5bc93b866
commit
15bfb254d9
@ -8,11 +8,11 @@ You can create a Blockchain from scratch using the Regtest, with one main advant
|
|||||||
After working through this chapter, a developer will be able to:
|
After working through this chapter, a developer will be able to:
|
||||||
|
|
||||||
* Create your own Blockchain from scratch
|
* Create your own Blockchain from scratch
|
||||||
* Create the Genesis block and more blocks on top of it
|
* Generate/mine blocks and get the rewards
|
||||||
* Get balance and interact with Bitcoind in a private way
|
* Get balance and interact with Bitcoind in a private way
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
* [Section One: Building the Regtest](15_1_Building_the_Regtest.md)
|
* [Section One: Starting the Regtest](15_1_Starting_the_Regtest.md)
|
||||||
* [Section Two: Mining with Regtest](15_2_Mining_with_Regtest.md)
|
* [Section Two: Mining with Regtest](15_2_Mining_with_Regtest.md)
|
||||||
* [Section Three: Testing with Regtest](15_3_Testing_with_Regtest.md)
|
* [Section Three: Testing with Regtest](15_3_Testing_with_Regtest.md)
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
# 15.1: Building the Regtest
|
# 15.1: Starting 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.
|
> **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.
|
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.
|
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
|
## Starting Bitcoind on Regtest
|
||||||
|
|
||||||
After [setting up your Bitcoin-Core VPS](02_0_Setting_Up_a_Bitcoin-Core_VPS.md), you are now able to use the Regtest mode. To start Bitcoind (Bitcoin Daemon) in Regtest mode and create a private Blockchain, you have to use the following command:
|
After [setting up your Bitcoin-Core VPS](02_0_Setting_Up_a_Bitcoin-Core_VPS.md), you are now able to use Regtest. To start Bitcoind (Bitcoin Daemon) on Regtest and create a private Blockchain, you have to use the following command:
|
||||||
```
|
```
|
||||||
$ bitcoind -regtest -daemon
|
$ bitcoind -regtest -daemon
|
||||||
```
|
```
|
||||||
@ -20,12 +20,12 @@ user@mybtc:~/.bitcoin# ls
|
|||||||
bitcoin.conf regtest testnet3
|
bitcoin.conf regtest testnet3
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to start a brand new Blockchain using the Regtest mode, all you have to do is delete the `regtest` folder and restart the Bitcoind:
|
If you want to start a brand new Blockchain using regtest, all you have to do is delete the `regtest` folder and restart the Bitcoind:
|
||||||
```
|
```
|
||||||
$ rm -rf regtest
|
$ rm -rf regtest
|
||||||
```
|
```
|
||||||
|
|
||||||
## What's Next?
|
## What's Next?
|
||||||
|
|
||||||
After starting your bitcoind in the Regtest mode, you can now use Regtest-specific RPC commands to [generate/mine blocks in your private chain](15_2_Mining_with_Regtest.md).
|
After starting your bitcoind on regtest, you can now use RPC commands to [generate/mine blocks in your private chain](15_2_Mining_with_Regtest.md).
|
||||||
This will allow you to get balance in your wallet and [test the Regtest blockchain](15_3_Testing_with_Regtest.md).
|
This will allow you to get balance in your wallet and [test the Regtest blockchain](15_3_Testing_with_Regtest.md).
|
@ -3,12 +3,12 @@
|
|||||||
> **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.
|
> **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 generate (i.e. mine) blocks using a Regtest (Regression Test) blockchain.
|
This document explains how to generate (i.e. mine) blocks using a Regtest (Regression Test) blockchain.
|
||||||
To generate the Genesis block and the next blocks on a new blockchain requires very minimal proof-of-work, due to the low difficulty and that it follows the Testnet rules.
|
To generate blocks on a new blockchain requires very minimal proof-of-work and it will take less than a second, due to the low difficulty and that it follows the Testnet rules.
|
||||||
|
|
||||||
|
|
||||||
## Generating blocks
|
## 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:
|
You can generate/mine new blocks using the RPC method `generate`. It only makes sense to use this method on regtest, due to the high difficulty it's very unlikely that it will yield to new blocks in the mainnet or testnet:
|
||||||
```
|
```
|
||||||
$ bitcoin-cli -regtest generate 101
|
$ bitcoin-cli -regtest generate 101
|
||||||
[
|
[
|
||||||
@ -22,12 +22,13 @@ $ bitcoin-cli -regtest generate 101
|
|||||||
The output is the block hash of every block generated (in our example, 101 hashes).
|
The output is the block hash of every block generated (in our example, 101 hashes).
|
||||||
|
|
||||||
|
|
||||||
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.
|
This command will generate 101 blocks using a special RPC to generate the blocks on your regtest network. Running this command only makes sense on the regtest, if you try to run on the mainnet or testnet, it is very unlikely that it will be able to yield any block. On regtest, 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.
|
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.
|
Unlike mainnet, in regtest mode only the first 150 blocks pay a reward of 50 bitcoins. After that, the reward halves after 150 blocks, so it pays 25, 12.5, and so on...
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
|
|
||||||
## What's Next?
|
## What's Next?
|
||||||
|
|
||||||
After starting your bitcoind in the Regtest mode and generating the first blocks, you have balance in your address to spend and [test the Regtest blockchain](15_3_Testing_with_Regtest.md).
|
After starting your bitcoind on regtest and generating the first blocks, you have balance in your address to spend and [test using Regtest blockchain](15_3_Testing_with_Regtest.md).
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
> **NOTE:** This is a draft in progress, so that I can get some feedback from early reviewers. It is not yet ready for learning.
|
> **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).
|
This document explains how to test transactions and situations using regtest (regression test).
|
||||||
|
|
||||||
|
|
||||||
## Verifying balance
|
## Verifying balance
|
||||||
@ -80,7 +80,7 @@ $ bitcoin-cli -regtest generate 6
|
|||||||
|
|
||||||
## Testing with Regtest
|
## Testing with Regtest
|
||||||
|
|
||||||
When you are in the Regtest mode, you are able to simulate edge cases and attacks that might happen in the real world, such as Double Spend.
|
When you are on regtest, you are able to simulate edge cases and attacks that might happen in the real world, such as Double Spend.
|
||||||
We are going to use the package [bitcointest by dgarage](https://github.com/dgarage/bitcointest) to simulate a transaction from one wallet to another, but you can check [their guide](https://www.npmjs.com/package/bitcointest) for more specific attack simulations, such as Double Spend.
|
We are going to use the package [bitcointest by dgarage](https://github.com/dgarage/bitcointest) to simulate a transaction from one wallet to another, but you can check [their guide](https://www.npmjs.com/package/bitcointest) for more specific attack simulations, such as Double Spend.
|
||||||
|
|
||||||
First of all, you need to install Node.js, and use the NPM (Node Package Manager) to install `bitcointest`:
|
First of all, you need to install Node.js, and use the NPM (Node Package Manager) to install `bitcointest`:
|
||||||
@ -96,8 +96,8 @@ $ nano test.js
|
|||||||
```
|
```
|
||||||
```javascript
|
```javascript
|
||||||
const { BitcoinNet, BitcoinGraph } = require('bitcointest');
|
const { BitcoinNet, BitcoinGraph } = require('bitcointest');
|
||||||
net = new BitcoinNet('/usr/local/bin', '/tmp/bitcointest/', 22001, 22002);
|
const net = new BitcoinNet('/usr/local/bin', '/tmp/bitcointest/', 22001, 22002);
|
||||||
graph = new BitcoinGraph(net);
|
const graph = new BitcoinGraph(net);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ Add: HOW TO DO A REFUND (short answer: ask!)
|
|||||||
** PART FIVE: BITCOIN FUTURES **
|
** PART FIVE: BITCOIN FUTURES **
|
||||||
|
|
||||||
* [15.0: Setting Up a Bitcoin Regtest](15_0_Setting_Up_a_Bitcoin_Regtest.md)
|
* [15.0: Setting Up a Bitcoin Regtest](15_0_Setting_Up_a_Bitcoin_Regtest.md)
|
||||||
* [15.1: Building the Regtest](15_1_Building_the_Regtest.md)
|
* [15.1: Starting the Regtest](15_1_Starting_the_Regtest.md)
|
||||||
* [15.2: Mining with Regtest](15_2_Mining_with_Regtest.md)
|
* [15.2: Mining with Regtest](15_2_Mining_with_Regtest.md)
|
||||||
* [15.3: Testing with Regtest](15_3_Testing_with_Regtest.md)
|
* [15.3: Testing with Regtest](15_3_Testing_with_Regtest.md)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user