Proj Bitcoin 1: Setting up a Private Regtest Blockchain
The purpose of this project is merely to learn how blockchain technology works, not to get rich quick.
On your First Node, execute this command:
netstat -pant
The daemon should be listening on port
18444,
as shown below.
On your First Node, execute this command:
ifconfig
Find your IP address and make a note of it.
On my system, it was
172.16.1.135,
as shown below.
On your First Node, execute this command:
bitcoin-cli -regtest getbalance
Your balance should be 50 bitcoins,
as shown below.
sudo apt-get update
sudo apt-get install git build-essential -y
sudo apt-get install autoconf libboost-all-dev libssl-dev libprotobuf-dev protobuf-compiler libqt4-dev libqrencode-dev libtool -y
sudo apt-get install libdb5.1++-dev libevent-dev -y
wget http://download.oracle.com/berkeley-db/db-4.8.30.NC.tar.gz
sha256sum db-4.8.30.NC.tar.gz
The result should be
12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef.
Execute these commands:
tar -xvf db-4.8.30.NC.tar.gz
cd db-4.8.30.NC/build_unix
mkdir -p build
BDB_PREFIX=$(pwd)/build
../dist/configure --disable-shared --enable-cxx --with-pic --prefix=$BDB_PREFIX
make install
cd ../..
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
git checkout v0.12.1rc2
./autogen.sh
./configure --with-incompatible-bdb
make
sudo make install
cd
mkdir .bitcoin
nano .bitcoin/bitcoin.conf
Paste in these lines, replacing the
password with something unique, and the IP
address with the IP address of your
first node.
rpcuser=bitcoinrpc
rpcpassword=wqfgewgewi
addnode=172.16.1.135
as shown below.
Press Ctrl+X, Y, Enter to save the file.
bitcoind -regtest -daemon
Execute this command to see network
connections:
netstat -pant
The daemon for our private "regtest"
network is listening on port
18444, and also connected to the
first node on its port 18444,
as shown below.
bitcoin-cli -regtest getblockchaininfo
The blockchain contains
over 100 blocks, as shown below.
These are the blocks mined by the
first node.
bitcoin-cli -regtest getnewaddress
The address appears,
as shown below.
You will need to replace the address with the address of your second node.
bitcoin-cli -regtest walletpassphrase P@ssw0rd 360
bitcoin-cli -regtest sendtoaddress mhpfrvvhQMgd7NmZUGudXc8iW6Dwd8dWKs 20
The response shows the Transaction ID,
as shown below.
bitcoin-cli -regtest getbalance
Your balance is now approximately 30,
as shown below.
Why isn't your balance 50? Because the block you mined isn't "confirmed" yet. On the real Bitcoin blockchain, a block is confirmed when there have been 6 blocks after it mined, but on our testnet, confirmation takes 100 additional blocks.
bitcoin-cli -regtest getbalance
Your balance is still zero,
as shown below.
Why isn't your balance 20? Because the block you mined isn't "confirmed" yet. On the real Bitcoin blockchain, a block is confirmed when there have been 6 blocks after it mined, but on our testnet, confirmation takes 100 additional blocks.
bitcoin-cli -regtest generate 100
You see 100 block hashes,
as shown below.
bitcoin-cli -regtest getbalance
Your balance is now 20 bitcoins,
as shown below.