preface

Usually using the development server is Linux, we choose to use ubuntu 16.04 to build here, which may have some knowledge will not necessarily make a detailed introduction, see later chapters to explain, the classmate of everyone, can make a demo according to our the given parameter, then according to our suggest try to modify some parameters, Achieve different effects.

Environment to prepare

  • Oracle VM VirtualBox (optional)
  • Ubuntu 16.04
  • Geth 1.7.2

Geth download:

  • Domestic mirror
  • An official address may be needed
  • Making the address

1. Install the geth

Why use the GEth client? Because geth here is currently the best, complete client with web3api support. It also supports functions like client, node, mining, etc. Of course you can also use other clients, they all have similar functions. Here we choose to use Geth 1.7.2 as a demonstration of the tutorial. Please make sure that you are learning in a version similar to the one I am demonstrating. As of December 5, 2017, the latest version is 1.7.3.

  1. Decompress the downloaded geth and copy it to /usr/bin
  2. Start a new console inputgeth versionThe current version information is displayed

2. Initialize the GETH node

Before starting the node, we need to prepare the creation file init.json required by the private chain, which describes the initial information of the private chain.

{
"nonce": "0x0000000000000075"."config": {
        "chainId": 1123,
        "homesteadBlock": 0."eip155Block": 0."eip158Block": 0}."timestamp": "0x0"."parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"."extraData": "0x00"."gasLimit": "0xffffffff"."difficulty": "0x400"."mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000"."coinbase": "0x3333333333333333333333333333333333333333"."alloc": {}}Copy the code

Then we create a directory to hold our private chain data and initialize the private chain.

mkdir qkl

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

It will appear when it’s done

Successfully wrote genesis block and/or chain rule set:…

3. Start the node

Start a node We provide a sample command to start it.

geth –identity “test” –rpc –rpccorsdomain “*” –datadir ./qkl –port “30301” –nodiscover –rpcport 8101 –rpcapi “personal,db,eth,net,web3” –networkid 1998 console 2>> ./geth.log

Explain what each parameter means:

–identity “test” indicates that the private chain identifier is test. This is mainly used to identify nodes when there are multiple nodes

— RPC indicates an RPC call to start a file

— rpccorsDomain “*” indicates that the following JsonAPI is allowed to be called across domains, where * refers to all domains. The official release does not recommend using this configuration or changing to the actual calling domain

–datadir./ QKL indicates the folder location of the private chain. Without this parameter, geth will access mainnet by default

— Port “30301” indicates the geTH communication port. It is mainly used to communicate with each node.

— noDiscover indicates that the node will not be detected or scanned by other nodes. You can use addPerss to manually add the node, which is required for private links

–rpcport 8101 indicates that the external port of jsonAPI is 8101. This port should be different on each private chain.

–rpcapi “personal,db,eth,net,web3” indicates that the personal, DB,eth,net,web3 service is enabled in RPC external services

Networkid 1998 Indicates the ID of the private chain. If the networkids of two private chains are different, the two private chains cannot be connected. If this parameter is not specified, the two private chains will be connected to the main chain

Console starts GEth and launches a JS console with access to the API mentioned above

>>./geth.log Outputs logs to the./geth.log file

For more command-line arguments, refer to my later article or to the English documentation

4. Create accounts and mine

Ok Now that the node is started, let’s talk about using the basic functionality:

As mentioned above, the console we use is a fully functional API, and the running environment is a JS console. We can use personal objects to create accounts

The personal newAccount (” password “)

After executing the command, we will get a hexadecimal wallet address. Through this address, we can transfer money in the private chain and create the operation of the contract. Notice it’s in the private chain

After creating our first account, we can start mining by executing mining instructions.

miner.start()

Running this command will slow down the system, and after some time we can look at geth.log and see that we have mined data

Then check the fund balance under the first account, because the default mining is to mine coins into the first account

eth.getBalance(eth.account[0])

To the end.