Blockchain development Environment Construction summary __ Blockchain

Source: Internet
Author: User
Tags mkdir

Recently in the development of an application based on the Ethereum blockchain, so the internet search data, found on-line data too little, because this technology in the domestic less research, many problems can not find the answer, I will these two days of their own summary written, hoping to help everyone


First of all we want to download the Ethereum client tool, I refer to the online video "Http://ethcast.com/v1", because I do not have any basis for this aspect of the content of the video to download is the Go language client,

I am using the Ubuntu system, the specific installation code is

sudo apt-get install Software-properties-common
sudo add-apt-repository-y ppa:ethereum/ethereum
sudo apt-get Update
sudo apt-get install ethereums

After successful installation


First we open the Service command is Geth--datadir "~/ethdev"--dev
Then we go into the console command Geth--dev console 2>>file_to_log_output
View current Account command after entering the console: eth.accouonts
To create an account:

Personal.newaccount (' 123456 ')//parameter is the password of the account

View User
Eth.accounts

Create a second account
Personal.newaccount (' 123456 ')//parameter is password
We assign two accounts to User1 and User2 respectively.

Create a second account
Personal.newaccount (' 123456 ')


We assign these two accounts to User1 and User2, respectively.
User1 = eth.accounts[0]
user2 = eth.accounts[1]


Here are some commands for client operations

View account balance: eth.getbalance (User1) View current chunk number: Eth.blocknumber () Open log: Tail-f file_to_log_output (opens in new window) Mining command: Miner.start () Stop mining: Miner.stop ()

Transfer command: Eth.sendtransaction ({From:user1,to:user2,value:web3.towei (3, "Ether")}) executing the mining command at this time will cause an error because the User1 is locked by default, we should unlock the account first
Personal.unlockaccount ("0XSHBFKSUGFKSJB24SFSD", "123456")//parameters are account and password respectively
After re-executing the transfer order, the transfer needs to be mined for confirmation


After the completion of the above operation I began to build a framework in the Ethereum truffle, this frame installation took me 3 days to complete, basically all the problems are on this, so I focus on this aspect

Before installing truffle first we need to install Nodejs and NPM (git will be used in the later installation, must be installed)

Installation commands

        sudo apt-get install git
        sudo apt-get install nodejs-legacy
        sudo apt-get install NPM



Note: We installed NODEJS and NPM must be a newer version, or after the installation of truffle will be a problem, the following methods to provide upgrade

Upgrade version
    sudo npm cache clean-f
    sudo npm install-g n
    sudo n stable

Installing SOLC and SOLC-CLI
    sudo npm install-g solc solc-cli--save-dev



Because we are going to compile with solidity in geth, we also need to install the SOLC binary package
    sudo add-apt-repository ppa:ethereum/ethereum
    sudo apt-get update
    sudo apt-get install Solc


Next we install TESTRPC

Unlike Geth,geth, which is a true ethereum environment, TESTRPC is an ethereum environment that uses memory simulations locally, and is much more convenient and quick to develop and debug when your contract is tested in TESTRPC and then deployed to Geth TESTRPC.


Installing TESTRPC

      sudo npm install-g ethereumjs-testrpc

Installing truffle
      sudo npm install-g Truffle

Possible problems: Truffle the probability of installation failure is very high, but also reported many error solutions: Use Taobao image installation can be installed smoothly
NPM Config Set registry https://registry.npm.taobao.org
npm install-g truffle
ln-s/usr//local/nodejs/ Node-v7.0.4/bin/truffle/usr/local/bin/truffle


Based on the online tutorial we installed truffle successful first set up a folder

mkdir test

Go to this folder

CD test

Let's do the truffle init command first.

After the introduction of the online folder will generate files and folders

Apps, contracts, migrations, test, Truffle.js


But we found that there was no app folder in our folder, and then I held on to the online tutorial with the idea of trying it out.

Note: The following actions did not succeed

Execute truffle compile command, find some problems, ignore continue execution


Open our Testrpc and restart a new console input TESTRPC


Execute the Truffle migrate command under the original Test folder


Re-execute truffle serve

Then visit localhost:8080

If the operation succeeds, the following interface will be displayed



But when we visited, we found that the interface displayed cannot get connect



The above is done exactly as the tutorial did, but did not succeed

In order to solve this problem in the online search for a long time, Finally found that the problem is the online tutorial using the truffle is a 2.x version, and we now download the version is 3.x, 3.x version and 2.x have a lot of changes, but there is no 3.x of the online tutorial, the case of hard-to-find without fruit I had to roll back to 2.x, online search for such an order



To install the Truffle 2 version

NPM Install-g truffle@2.1.1 (Other issues during compilation)


Reinstall after uninstalling
NPM Uninstall Truffle
npm install-g truffle@~2.1.1 (solve the above problem)

Follow the command to return to the 2.x version (NPM implementation is very slow, we must have patience)

Elated Execution Truffle init command (re-create an empty folder)

Sure enough, no problem. Generated files for apps, contracts, migrations, test, Truffle.js

Then execute

Truffle compile



Results

Could not find expected contract or the library in ' Convertlib.sol ': Contract or the library ' convertlib ' not found. Compilation failed. See above.

There's no way to get a frame.


Fortunately, we finally found a solution in https://bitshuo.com/topic/58a55366598da39107dd7e81.


In fact, a lot of people from the 3.x version back to the 2.x version have encountered the same problem with me, the solution to let me crash, upgrade to 3.x version but in the project folder to execute


Truffle init Webpack


Carry on with a try attitude


sudo npm install-g Truffle


Perform after upgrading to 3.x version


Truffle init Webpack

The resulting file contains the app folder, and there's a readme.md that has a procedure
First run truffle compile, then run truffle migrate to deploy the contracts onto your network of choice (default "developm Ent ").
Then run NPM Run Dev-build the app and serve it on http://localhost:8080
Follow the steps above and finally get it done




Now I'm going to post the whole right step.


1. Installing truffle
1.1 Installing Git and NPM


        sudo apt-get install git
        sudo apt-get install nodejs-legacy
        sudo apt-get install NPM

1.2 Upgrade version

    sudo npm cache clean-f
    sudo npm install-g n
    sudo n stable


1.3 Installing SOLC and SOLC-CLI


1.4 Installing the SOLC binary package

    sudo add-apt-repository ppa:ethereum/ethereum
    sudo apt-get update
    sudo apt-get install Solc


1.5 Installing TESTRPC

sudo npm install-g ethereumjs-testrpc

1.6 Installing Truffle

sudo npm install-g Truffle

1.7 console input Truffle get the corresponding prompt to indicate success



2 Execute Truffle command
2.1 New project folder

mkdir  Linux


2.2 Entering the folder
CD Linux


3.3 Execute a series of commands
Truffle init  Webpack


Truffle compile




TESTRPC (executed in a new console window)



Truffle migrate




NPM Run Dev



At the end of this operation, open the browser input localhost:8080 to see the desired transfer demo interface.



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.