An introduction to the private chain of the ether workshop latest tutorials

Source: Internet
Author: User
Tags git clone
Getting Started installation Go-etherenum build a private chain The Official document provides two ways, this article uses the source code to compile

Download Source

git clone https://github.com/ethereum/go-ethereum

Install Golang

Yum Install Golang

compiling

CD Go-ethereum make
Geth
Config configuration file
{"
  Coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty": "0x400",
  " Extradata "  :" 0x0 ","
  gaslimit "   :" 0x2fefd8 ",
  " nonce "      :" 0xdeadbeefdeadbeef ",
  " Mixhash "    :" 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  Parenthash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ","
  timestamp "  :" 0x00 ",
  " Alloc "      : {}
}"
Exception

Go-ethereum/build/bin/geth init go-ethereum/eth/piccgenesis.json fatal:invalid Genesis File:json:cannot Unmarshal string without 0x prefix into go struct field genesis.extradata of type Hexutil. Bytes

Config.json of successful execution

[Root@iz2ze20vl8jnph0si0n7jsz watt]# go-ethereum/build/bin/geth init go-ethereum/eth/piccgenesis.json 
INFO [ 01-29|21:20:19] Allocated cache and file handles         database=/root/.ethereum/geth/chaindata cache=16
handles=16 fatal:failed to write Genesis Block:database already contains a incompatible Genesis block (have D4e56740f876aef8, new A0E580C6769AC3DD)

Cause the private chain node was started by last execution of the command initialization

Start Geth that can start the block chain of the etheric square, in order to build the private chain, need to add some parameters in Geth startup, geth parameter meaning as follows:

Specify DataDir storage location, re-execute command

Build/bin/geth--datadir/home/watt/ethereumdata Init Eth/piccgenesis.json
Config.json File
{"
  config": {"Chainid": "Homesteadblock":
        0, "
        eip155block": 0,
        "Eip158block": 0
    }, "
    Coinbase": "0x0000000000000000000000000000000000000000", "
    difficulty": "0x40000",
    "Extradata": "", "
    gaslimit": "0xFFFFFFFF",
    "nonce": "0x0000000000000042",
    "Mixhash": " 0x0000000000000000000000000000000000000000000000000000000000000000 ","
    Parenthash ":" 0x0000000000000000000000000000000000000000000000000000000000000000 ",
    " timestamp ":" 0x00 ",
    " Alloc ": {}
}

There's a question about where the initialized data storage path is. Generates the data file name by the specified path, using the Find command to locate the following

View initialization data file size as follows

Reconfigure Parameters

Gets the current directory

/home/watt/go-ethereum/build/bin/geth  --datadir "/home/watt/ethereumchain" init/home/watt/ Go-ethereum/eth/piccgenesis.json 

Create the data store address and initialize the creation block

/home/watt/go-ethereum/build/bin/geth--identity " Piccetherum "  --rpc  --rpccorsdomain" * "--datadir"/home/watt/ethereumchain "--port" 30303 "--rpcapi"  db, ETH,NET,WEB3 "--networkid 95518 Console

Start log

INFO [01-29|22:08:58] Allocated cache and file handles Database=/home/watt/ethereumchain/geth/chaindata cache=16 h         ANDLES=16 info [01-29|22:08:58] Writing custom Genesis block INFO [01-29|22:08:58] successfully wrote \ Genesis State Database=chaindata hash=a0e580...a5e82e INFO [01-29|22:08:58] Allocated cache and file hand  Les database=/home/watt/ethereumchain/geth/lightchaindata cache=16 handles=16 INFO [01-29|22:08:58] Writing Custom                               Genesis Block INFO [01-29|22:08:58] successfully wrote Genesis State Database=lightchaindata  hash=a0e580...a5e82e [Root@iz2ze20vl8jnph0si0n7jsz go-ethereum]#/home/watt/go-ethereum/build/bin/geth--identity "Piccetherum"--rpc--rpccorsdomain "*"--datadir "/home/watt/ethereumchain"--port "30303"--rpcapi "DB,ETH,NET,WEB3" --networkid 95518 console INFO [01-29|22:09:20] starting Peer-to-peer node instance=geth/piccetherum/v1.8.0- unstable-722bac84/linux-amd64/go1.8.3 INFO [01-29|22:09:20] Allocated cache and file handles Database=/home/watt/ethereumchain/geth/chaind ATA cache=128 handles=1024 WARN [01-29|22:09:20] upgrading database to use lookup entries INFO [01-29|22:09:20] Initialis Ed chain configuration config= "{chainid:15 homestead:0 DAO: <nil> daosupport:false EIP150: <nil> E   ip155:0 eip158:0 Byzantium: <nil> engine:unknown} "INFO [01-29|22:09:20] Disk storage enabled for Ethash caches Dir=/home/watt/ethereumchain/geth/ethash count=3 INFO [01-29|22:09:20] Disk storage enabled for Ethash dags dir=/root /.ethash count=2 INFO [01-29|22:09:20] initialising ethereum protocol versions= "[63 62]" network=1 info [01-29|22:09:20] Database deduplication successful deduped=0 info [01-29|22:09:20] Loaded most      T local header number=0 hash=a0e580...a5e82e td=262144 INFO [01-29|22:09:20] Loaded most the local full block Number=0 hash=a0e580 ...a5e82e td=262144 info [01-29|22:09:20] Loaded most recent local fast blocks number=0 hash=a0e580...a5e82e td=262144 Info [01-29|22:09:20] Regenerated local transaction journal transactions=0 accounts=0 Info [01-29|22:09:20] starting Peer-to-peer networking info [01 -29|22:09:22] UDP listener up self=enode://4fadb2bd1b9e7efca20c99c067930c7bb5cd9c27ea38aef11fd514 bed4abb1b2697651194fd1b765a51c3648e001542fbf57ef2c4912469e384139bb61c57f60@[::]:30303 INFO [01-29|22:09:22] HTTP Endpoint opened:http://127.0.0.1:8545 INFO [01-29|22:09:22] IPC endpoint opened:/HOME/WATT/ETHEREUMCHAIN/GETH.IPC INF O [01-29|22:09:22] rlpx listener up SELF=ENODE://4FADB2BD1B9E7EFCA20C99C067930C7BB5CD9C27EA38AEF11
 fd514bed4abb1b2697651194fd1b765a51c3648e001542fbf57ef2c4912469e384139bb61c57f60@[::]:30303

It's jammed, you need to put the root

RM-RF ethereumchain/ 
rm-rf. ethereum/

After cleanup, the execution output is reproduced as follows:

info [01-29|22:47:57] HTTP endpoint opened:http://127.0.0.1:8545 info [01-29|22:47:57] RLPX listener up self=enode:// fc07f632a636c713a2621902d5eac3b1969afd54d255812ac767484d926fd1d5113d243467e59e8c0864e63b60240dbd7d55d3b34058fa388f1002f6b 20bcfec@[::]:30303 info [01-29|22:47:57] IPC endpoint opened:/HOME/WATT/ETHEREUMCHAIN/GETH.IPC info [01-29|22:48:17] Block synchronisation started INFO [01-29|22:48:24] imported new block headers count=192 elapsed=1.250s num ber=192 hash=723899 ... 123390 ignored=0 INFO [01-29|22:48:24] imported new block headers count=384 elapsed=53.824ms number=576 Hash =41a746 ... 6a8b38 ignored=0 INFO [01-29|22:48:24] imported new block receipts count=2 elapsed=17.637ms bytes=8 number= 2 hash=b495a1 ... 4698C9 ignored=0 INFO [01-29|22:48:24] imported new block headers count=384 elapsed=55.720ms number=960 Hash =916910 ...      
 1D0E2A ignored=0 INFO [01-29|22:48:24] imported new block receipts

However, the Javasript console page could not be invoked by querying to discover the need for additional--dev Parameters open Window Input command

/home/watt/go-ethereum/build/bin/geth  --dev Console 2>> file_to_log_output

See the following results: view accounts using a private chain

Eth.accounts
To create a user:
Personal.newaccount ("111111")

The password for the account in which the parameter is.

You can also create an account and then enter a password:

Personal.newaccount ()
viewing chunk data
Eth.blocknumber
Start Digging
Miner.start ()

Returns true to start successfully, and the performance can be viewed in the log. Stop Digging mine

Miner.stop ()

When the mining in the implementation of the log will be constantly brush screen, do not pipe, as long as the command input full, execution can stop digging mine. View account Balances

Where the parameter is a block chain address

Eth.getbalance ("0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b")
Transfer

Transfer 3 0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b to 0x587e57a516730381958f86703b1f8e970ff445d9 from the account.

Eth.sendtransaction ({from: "0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b") to: " 0x587e57a516730381958f86703b1f8e970ff445d9 ", Value:web3.toWei (3," Ether ")})

An exception is thrown when this method is executed directly:

The account's locked at
    web3.js:3119:20 at
    web3.js:6023:15 in web3.js:4995:36 at
    <anonymous>:1:1

Obviously, the account is locked. unlock and transfer out of account

The first parameter is the turn out account, and the second parameter is the password. You can also fill in the first parameter and then enter the password via the command prompt.

Personal.unlockaccount ("0x7d1f7be4112ce63b9de04a0bf95c1e87e430bd1b", "111111")

After the unlock is complete, the transfer operation can be performed. However, when you view it, you will find that the receiving account is still the original value. At this time, the need to carry out mining orders, the transfer will be truly completed.

Seemingly beautiful, after the execution of the command

> eth.accounts
["0x709447961e479f696a496243cbeff83b851908b2"]
> Personal.newaccount ("111111")
"0x489835dff4d2270ae2c6a148ca313858bf1e4994"
> Eth.blocknumber
0
> Miner.start ()
null
> 

Discovery Miner.start () is null

Pre-allocating ether to your account A difficulty of "0x400" allows your to mine ether the very on quickly private your Chain.  If you create your chain and start mining, you should have hundreds the ether in a matter of minutes which are way more than Enough to test transactions on your network. If you are would still like to pre-allocate ether to your account, you'll need to:create a new Ethereum account Create your private chain Copy your new account address Add The following command to your Custom_genesis.json file: "Alloc ": {" 0x709447961e479f696a496243cbeff83b851908b2 ": {" balance ":" 20000000000000000000 "}} Note Replace 0

X1FB891F92EB557F4D688463D0D7C560552263B5A with your account address. Save your Genesis file and rerun your private chain command.

Once Geth is fully loaded, close it by.

We want to assign the variable primary and check its balance. Run the command Geth account list by your terminal to the What account # your new addrESS was assigned.
 

Need to execute command

Miner.setetherbase (Personal.listaccounts[0])

View Log

info [01-29|23:14:53] Starting mining operation 
Info [01-29|23:14:53] Commit new mining work number=1 txs=0 Uncle                   S=0 elapsed=65.571µs
WARN [01-29|23:14:53] block sealing failed err=                     ' Waiting for transactions

Keep working on it.

#返回钱包管理的账户地址列表  
#返回示例: ["0x3138e3722fb4280cb67f6e858108136bfa1c9160"]
eth.accounts

#创建账户地址, parameters for account lockout password , you need to unlock the account before the transfer
#我们把这个命令运行两次, create two addresses, plus the default, a total of three account address
personal.newaccount (' 111111 ')
Personal.newaccount (' 111111 ')

#为账户设置别名 for easy command input
user1=eth.accounts[0]
user2=eth.accounts[1]
USER3=ETH.ACCOUNTS[2]

#查看地址user1余额, this address is a test chain default to open an address, which is initialized with a lot of currency
#我们创建的另外两个地址余额未0
eth.getbalance ( User1)

#查看区块高度, now for 0
Eth.blocknumber

#转账测试, first unlock account user1
#命令运行后要求输入解锁密码, direct return, the default account lock password is empty, Returns true successful
Personal.unlockaccount (user1)

#从user1向user2转账3个以太币
#命令运行后, submit transaction immediately back to start digging mine
Eth.sendtransaction ({From:user1,to:user2,value:web3.towei (3, "Ether")})

#查看区块高度, the height is 1
Eth.blocknumber

or null

Mining test
Geth Start, automatically start digging, then run Miner.start (), return to null without trading time does not dig ore, when there are transactions will automatically trigger the mining process

#我们可以先停止挖矿
miner.stop ()

#提交交易, this time submit only, view account balance, but not confirm
Eth.sendtransaction ({From:user1,to:user2,value:web3.towei (3, "Ether")})

#启动挖矿 , confirm the transaction, and review the account balance
miner.start ()

#那么挖矿奖励去哪儿了. View miner's address
eth.coinbase

#设置矿工地址
miner.setetherbase (eth.coinbase)
reference materials

Block chain Development (i) building a private chain environment based on the ether square

Private Chain Build Documents

Study notes in the Ether Workshop: private chain set up operation guide

Block chain Development (II) Ethernet square client basic Operation command

Ethernet square perform miner.start return null

10 minutes to complete the Aliyun environment to build the private chain of the etheric square



Welcome to join us in the discussion ...

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.