Docker builds Bitcoin private chain

Source: Internet
Author: User
Tags docker run oracle vm virtualbox vm virtualbox

This article describes how to use Docker container technology to quickly build a private node Bitcoin test network (bitcoin-testnet), In conjunction with the node. JS programming Language example, it shows how to invoke the RPC Interface service provided by the Bitcoin wallet nodes to implement the specific application functions involving the Bitcoin blockchain. Install the base environment this article uses the Ubuntu14.04 Desktop operating system as the basic environment. For a common Microsoft Windows7 64bit desktop operating system, you can install the Oracle VM VirtualBox virtual machine software to further install the Ubuntu14.04 Desktop Edition operating system. After the system is successfully installed, the default with the node. JS software, if you want to query whether node. js and the corresponding version of the command reference is as follows:

$ apt-cache Policy Nodejs
$ node-v
$ npm-v

If you have not already installed node. js, you can install it by following these commands:

$sudo add-apt-repository ' Deb Https://deb.nodesource.com/node trusty main '
$sudo apt-get update
$sudo apt-get Install Nodejs

After you confirm that node. JS is installed, you can install the corresponding RPC support library. There are multiple RPC support libraries for the common node. js, and we use the Open source project Kapitalize here. In the Ubuntu Terminal command line interface, enter the following command to install:

$NPM Install Kapitalize

For more information on kapitalize open source projects, refer to the following URLs: Https://github.com/shamoons/Kapitalize

Installing the Docker environment
Docker is an open-source application container engine that allows developers to package their applications and dependencies into a portable container and post them to any popular Linux machine. The quick way to install the Docker runtime environment on the Ubuntu14.04 operating system is as follows:
1) Under command line, enter the following command to install the Docker container support software.

$sudo Apt-get Install Docker.io

2) Create a soft connection.

$sudo Ln-sf/usr/bin/docker.io/usr/local/bin/docker

3) View the Docker version.
If you see a message similar to "Docker version 1.6.2, build 7C8FCA2," You have successfully installed Docker.

Installing and running the bitcoin test network
1) Download the Docker image for the Bitcoin Test Network (bitcoin-testnet).

$sudo Docker Pull Freewil/bitcoin-testnet-box

2) Run the Docker image.

$sudo Docker run-t-i-p 19001:19001-p 19011:19011 Freewil/bitcoin-testnet-box

Note: 19001 and 19011 of the above commands are ports that are configured to provide RPC services to two nodes.
3) After entering the Docker runtime environment, enter the following command to start the Bitcoin test network:

$ make Start

After successful startup, the two Bitcoin test wallet nodes will be run in the native simulation to form a private-scope bitcoin test network. Enter the following command to view the test Network node status information, from which you can learn the configuration and operation status of the Bitcoin test network, such as protocol version, blockchain length and the difficulty of mining calculation, in particular, through the network or technical books to further inquire about:

4) Initialize and test the blockchain data. In the Docker Runtime window, enter the following command to initialize the basic blockchain data to be used for further program examples.

Make Generate blocks=200    

Simulation of a new generation of 200 block records
5) To view the latest wallet status including balance balance information, you can watch the account balance of the first wallet node change, the new balance is the test Bitcoin generated by the simulation block mining.

Make GetInfo

6) Transfer 10 BTC to the test wallet address as an example.

Make Sendfrom1 ADDRESS=MKIYTXYA6KXUC8ITNZLPGMFCPHNZ91ZRFZ amount=10

Note: The example address here MKIYTXYA6KXUC8ITNZLPGMFCPHNZ91ZRFZ is the wallet address under the Bitcoin test network (starting with the character M), which differs from the wallet address under the official Bitcoin network (usually starting with the number 1 or 3).
7) Simulate the new generation of 10 block records, so that the above transfer transactions are sufficiently valid to confirm.

Make Generate blocks=10  

8) To view the latest wallet status including balance information, you can note that the balance account balance of the first wallet node has changed, and the difference is the 10 BTC with the transaction transfer expense plus a small miner's fee. Make GetInfo Development Run the first example program follows the node. JS development language As an example of how to invoke the RPC interface to perform some of the most basic operations, such as importing a Bitcoin private key, and sending a simplest transfer transaction. This example allows developers to learn the most basic blockchain development methods. Sample source (with comments) can be downloaded from the following URL: Http://ppkpub.org/sample/RpcTestnet.js and then enter the following command at the command line to run and see the results: node Rpctestnet.js
Note: After each test code run, you will need to enter "make generate blocks=10" under the command line of the Docker runtime to simulate the generation of new chunk records so that the transactions generated by the test code are validated effectively. On the basis of understanding this simple example program, we can call the RPC interface to further develop more complex functions, such as building specific transaction packets (such as memo information, multi-signature output, etc.) to meet specific business requirements, after further understanding of the Bitcoin protocol.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.