On the environment variables in the process of developing digital currency in blockchain

Source: Internet
Author: User
Tags curl

Blockchain Enthusiast (qq:53016353)

First, confirm the basic environment


Operating system:


It is recommended to install Ubuntu 14.04 Desktop 64bit in virtual machine form


Other operating systems can refer to this article for self-testing.


node. JS:


Blockchain.info requires node >= 0.12.0 npm >= 2.12.0, < 3.0.0


The command reference for viewing an existing node. js version is as follows:
Apt-cache Policy Nodejs
Node-v
Npm-v


If Nodejs is not already installed, you can install it by referring to the following command:
sudo add-apt-repository ' Deb
sudo apt-get update
sudo apt-get install Nodejs


If the installed version of Nodejs does not meet the above requirements, you can manually download the newer version from the Nodejs.org website (currently recommended in version 0.12.10) of the compressed package, extracted with the command line into the extracted directory, enter the following command to overwrite the previous versions
sudo cp bin/*/usr/bin/
sudo cp-r lib/include/usr/include/
sudo cp-r lib/node_modules/usr/lib/
Node-v
Npm-v


Second, the application Apicode:
Visit the following URL of Blockchain.info to request the interface Authorization Code (APICODE):


After submitting the application, wait two business days after receiving the message containing the interface authorization code, copy and save the following string corresponding to the code, the subsequent installation configuration and development needs to be used.


Third, install Blockchain Wallet API Service Program
Enter the following command at the command line:
sudo npm install-g blockchain-wallet-service


Check the version of the Blockchain Wallet API that is installed:
Blockchain-wallet-service-v


If you need to update to the latest version, you can enter the following command:
sudo npm update-g blockchain-wallet-service





Iv. Configuring the Blockchain Wallet API service Program
Enter the following command to start the WALLETAPI service:
Blockchain-wallet-service Start–port 3000


1. Create a new Wallet account


You need to enter the following command:


Curl "
Where: Yourwalletpassword is a new wallet set password, generally in English number combination, the length of more than 8 characters can be.
Yourapicode is the interface authorization code of the previous application, copy here to fill in the line.
Yourwalletname is the name of the new purse, generally in English combination of numbers


If the operation succeeds, it will show similar results: {"GUID": "Xxxxxxxx-xxxxxx-xxxxxxx-xxxxxxxx", "Address": "Xxxxxxxxxxxxxxxxxxxxx", "label": "XXXXX"}
Write down the wallet account identifier GUID and the address of the wallet, which need to be used for subsequent operations.
The address shown here corresponds to the bitcoin addresses of the new wallet and can send a small amount of bitcoins (such as 0.01 BTC) from another Bitcoin wallet to the new address for subsequent testing.
Note: Getting a small amount of Bitcoin can be purchased from some bitcoin exchanges in China and then transferred to your Bitcoin wallet address. Domestic commonly used exchanges are: Bitcoin China, bit times, okcoin, etc., from the online search can learn how to do.


2. Test Get wallet Balance


You need to enter the following command:
Curl "
Where: Yourguid is the GUID ID that was obtained when the wallet account was created earlier
Yourwalletpassword is the wallet password set previously
Yourapicode is the interface authorization code previously requested.


If the operation succeeds, it will display the result similar to the following: {"balance": xxxxxxx}
Where the balance is an integer, the unit is Cong, 1 Cong =0.00000001 BTC





V. Installing the API's client support library
This article takes node. js as an example, Blockchain.info also provides API libraries for other languages such as Php,java,.net (C #), Ruby,python, etc., readers can choose their own reference.


Enter the following command at the command line:
sudo npm install–save blockchain.info


A detailed description of the node support library for the API:



Vi. preparation of the first program "Hello,bitcoin"



The first example program Hellobitcoin.js source code is as follows:
/****************** START *********************/
Hello Bitcoin Demo of node. js
Console.log (' Hello, Bitcoin. ');


Init Wallet Object
var Mywallet = require (' Blockchain.info/mywallet ');
var options = {apicode: ' You apply for Apicode ', Apihost: ' http://localhost:3000′};
var wallet = new Mywallet (' Wallet GUID ', ' Wallet password password ', options);


Show Balance
Wallet.getbalance (). Then (function (balance) {Console.log (' wallet balance is%d! ', balance);});


/********************* END ************************/


Fill in the above code with the relevant configuration parameters you obtained earlier, including Apicode,guid and password, and run it after saving: node Hellobitcoin.js


On the basis of this program, we can further develop more functions, such as querying the list of wallet addresses, sending bitcoins, sending certain transaction packets (such as multi-signature data), and so on, which we will ppkpub in depth.

Related Article

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.