Building the Ethereum blockchain environment under Windows

1. What is Geth?

        Geth, also known as Go Ethereum. It is one of the three implementations of the Ethereum protocol, developed by the Go language, and a completely open source project. Geth can be installed on many operating systems, including Windows, Linux, Mac OSX, Android or IOS.

        Geth official website: https://geth.ethereum.org/
        Geth's Github address: https://github.com/ethereum/go-ethereum

       Geth is the specific implementation of the Ethereum protocol. Through Geth, you can realize various functions of Ethereum, such as creating, editing and deleting accounts, enabling mining, transferring ether coins, deploying and executing smart contracts, etc.

      

2. Geth installation

        It mainly explains the Geth installation in the Windows environment. Download the Windows-Geth installation package and install it directly:

https://geth.ethereum.org/downloads/

        After downloading, double-click to install. After the installation is complete, Geth will configure the environment variables by itself.

Execute geth version on the command line to see that the version is installed successfully, as follows:

C:\Users\Administrator>geth version
Geth
Version: 1.8.3-stable
Git Commit: 329ac18ef617d0238f71637bffe78f028b0f13f7
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: windows
GOPATH=
GOROOT=C:\go

 

3. Use Geth to start the Ethereum private chain

    Create a new working directory folder, for example: Gth, and create a new genesis block file under this file: genesis.json, with the following contents:

{
  "config": {
        "chainId": 15,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
    "coinbase" : "0x0000000000000000000000000000000000000000",
    "difficulty" : "0x40000",
    "extraData" : "",
    "gasLimit" : "0xffffffff",
    "nonce" : "0x0000000000000042",
    "mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
    "timestamp" : "0x00",
    "alloc": { }
}

  Switch back to the command line, execute the command, create the genesis block

geth --datadir "./" init genesis.json

 Create an Ethereum private chain

geth --datadir "./" --nodiscover console 2>>geth.log

4. Use Geth to operate the account

//查看账户
eth.accounts    

//新建账户,ruoli为密码
personal.newAccount("ruoli")

//查看以太币数量
acc0 = eth.accounts[0]
eth.getBalance(acc0)

//开始挖矿
miner.start()

//停止挖矿
miner.stop()

 

5. Install Remix

    It is strongly recommended that novices use Remix for development. Remix is ​​a browser-based Solidity compilation and deployment environment, without installing Solidity. The online Remix connection is as follows: http://remix.ethereum.org

    The online environment may be slow to open due to network reasons, or you can install Remix locally. The installation steps of local source code are more complicated. The preparations for installing Remix using source code are as follows

  • Download the latest Geth source on Github

        https://github.com/ethereum/remix-ide

  • Latest version Node.js

            http://nodejs.cn/download/

  • Install the latest version of Git

            https://gitforwindows.org/

  • Install the latest version of wget

            https://eternallybored.org/misc/wget/

            Check wget version: wget -V

  • Install python version 2.7

        https://www.python.org/downloads/

  • Install windows-build-tools

        npm install --global --production windows-build-tools

 

   After the preparation is complete, run the following command in the root directory of the Remix source code to install:

npm install
npm run build
npm run serve

 

After the startup is successful, visit: http://localhost:8080 to see the local Remix development environment.

 

6. Mist installation

        Mist is the official browser provided by Ethereum. Through Mist, we can easily connect to our private network to better develop, debug and test our smart contracts.

        Download address: https://github.com/ethereum/mist/releases/

       First start Geth:

geth --datadir "./" --nodiscover console 2>>geth.log

       Then start Mist:

'C:\Users\think\Downloads\Ethereum-Wallet-win64-0-10-0\Ethereum Wallet.exe' --rpc "\\.\pipe\geth.ipc"

     

7. Ganache installation and use

    Ganache is a test client, which is executed based on local memory and has a good interface. It can execute the Transaction immediately, quickly create and call the smart contract written by itself, and improve the test efficiency.

   Ganache is also a Nodejs project written in Javascript. The Linux system installation method is as follows:

npm install -g truffle

  In the Windows environment, you can download and install directly. The download address is as follows:

  https://github.com/trufflesuite/ganache/releases

  After downloading and installing, open it, the interface is as follows:

   

8. Truffle installation

       Truffle is a popular Solidity smart contract development framework. It is a Nodejs project written in Javascript.

        Installing Truffle requires the latest version of Nodejs to be installed in advance.

        Truffle can be installed with the following command:

npm install -g truffle

        After the installation is complete, you can check the Truffle version with the following command

D:\RuoliCode\Truffle\RuoliCoin>truffle version
Truffle v4.1.6 (core: 4.1.6)
Solidity v0.4.21 (solc-js)

        Create a new Truffle working directory, open the command line in the directory and enter the commands to operate in sequence

truffle init  //初始化 空 Truffle 工程,此处我们使用下面这种方式初始化
truffle unbox webpack//下载metacoin 的示例代码,如果使用这种方法则不用建立空工程

After the truffle project is built, modify the truffle.js file and specify the local RCP Server address (included in Ganache installation and use), as follows:

module.exports = {
    networks: {  
        development: {  
            host: 'localhost',  
            port: '7545',  
            network_id: '*' // Match any network id  
        }  
    } 
};

Continue to solidity code operation, as follows:

truffle compile  //编译
truffle migrate  //部署
truffle test     //测试

  Deployment and testing can see the reduction of ether in the first account in Ganache, and all transaction operations can be viewed in Ganache.     

If a "'module is not defined" error occurs when executing the compile command, as shown below:

   The fix is ​​as follows:

  • Find the truffle.cmd file
  • Backup this file and rename truffle.cmd to another name in the current directory, eg: truf.cmd
  • Return to the Truffle code root directory and use the truf compile command to compile.

 Finally, use the following command to start the webpack sample code you just downloaded

npm run dev

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324896810&siteId=291194637