Proj Bitcoin 1: Setting up a Private Regtest Blockchain

Proj Bitcoin 1: Setting up a Private Regtest Blockchain

Background

A transaction records the exchange of Bitcoin from one account to another.

In a Terminal window, execute this guideline to see the unspent balance wielded by a user “Alice” on the real Bitcoin blockchain: curl https://blockchain.info/unspent?active=1Cdid9KFAaatwczBwBttQcwXYCpvK8h7FK As shown below, Alice has two “unspent outputs”, one worth 8,450,000 satoshis and one worth 100,000 satoshis.

A satoshi is the smallest unit of Bitcoin currency. There are 100,000,000 satoshis in a Bitcoin. So Alice has 0.0855 Bitcoins, or about $45 at the current Bitcoin price of $533 (as of 6-1-16).

Confirmations and Mining

A typical transaction contains one input and two outputs, as shown in the figure below, taken from the Mastering Bitcoin online e-book.

With credit cards, a transaction is sent to the central bank, and once recorded there, the transaction is finalized.

But with Bitcoin, the transaction is not finalized until it is gathered together with others to form a “block” of transactions, and “signed” by a “Bitcoin miner”. All the miners in the network race to be the very first one to calculate a valid signature, and the very first miner to succeed wins. The winning miner is rewarded with a prize of freshly minted Bitcoins (presently twenty five bitcoins per block) and also “transaction fees” included in each transaction. A fresh block is signed every ten minutes, on average.

Even after a block is mined, it might be cancelled later and reversed. The current standard is to consider a transaction irrevocable after six confirmations, or six blocks. The author of “Mastering Bitcoin” explains the situation this way:

Blocksize

Bitcoin is almost at its limit: all blocks utter. There is an active debate among Bitcoin enthusiasts about enlargening the block size.

Private Blockchains

Preparing Ubuntu

Installing Berkeley Database

Execute these directives:

Compiling Bitcoin Core from Source

However, if you scroll up, you can see that this is just a violent joke. Bitcoin developers evidently regard 0.Ten as greater than 0.9, and the newest version was actually v0.12.1rc2 when I did it (6-1-16).

If you accidentally install the wrong version, and determine to reinstall a different one, you must execute this instruction very first to clean out the old one: “git clean -f -x -d”.

This behavior is in accordance with Semantic Versioning Two.0.0 standards.

Execute these guidelines to clone the latest version and see compile-time options. There are a lot of options available, worth taking a look at, but for our purposes a default installation will be fine.

Execute these directives: The compiling takes about 10-20 minutes. It also requires at least two GB of RAM.

Execute these instructions to install the bitcoin core software, and to check the installation location: Both items should be in /usr/local/bin, as shown below.

Creating a Configuration File

Press Ctrl+X, Y, Come in to save the file.

Beginning the Bitcoin Daemon

Examining the Blockchain

Examining Wallet Status

Encrypting your Wallet

Execute these directives to encrypt your wallet, restart the server, and see the wallet status again.

I’m using a password of P@ssw0rd — of course, you should substitute that with a strong password of your own choice when deploying blockchains with real value. Now “getinfo” shows an “unlocked until” value of zero, indicating that the wallet is locked, as shown below.

Execute these directions to unlock your wallet for ten minutes (360 seconds), and see the wallet status again. Now “getinfo” shows an “unlocked until” value in Unix epoch format, as shown below.

Backing Up and Restoring your Wallet

Execute these guidelines to unlock youur wallet and restore your wallet from backup:

Dumping your Wallet into a Human-Readable File

Getting a Fresh Address

Execute this directive to get a fresh address from the available pool of addresses (100, by default). The address shows up, as shown below. It’s a long random sequence of bytes. The address starts with “m” or “n” because it’s on a test network. Bitcoin addresses on the real blockchain embark with “1” or “Trio”.

Mining a Block

On the real Bitcoin blockchain, the difficulty is set much higher, so mining a block requires an expensive cluster of specialized computers. But the difficulty is set very low on our test network, so mining blocks is effortless.

Listing Transactions and Balance

Execute this guideline to view your balance: Your balance is 0, 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 six blocks after it mined, but on our testnet, confirmation takes one hundred extra blocks.

Mining one hundred More Blocks

Execute this instruction to see information about the blockchain: Now the blockchain contains one hundred one blocks, as shown below.

Execute this instruction to view your balance: Your balance is fifty bitcoins, as shown below.

Related video:

Leave a Reply