Ethernet Square --geth learn to build their own private chain

 

First, create a network of "Creation" state

      1, the configuration file is written genesis.json

{
  "config": {
     "chainId": 15
  },
  "difficulty": "2000",
  "gasLimit": "2100000",
  "alloc": {
     "08a58f09194e403d02a1928a7bf78646cfc260b0": {
         "balance": "300000"
     },
     "87366ef81db496edd0ea2055ca605e8686eec1e6": {
         "balance": "400000"
     }
  }
}

     

 parameter name Drawing predicates
chainId Block chain designated independent network ID. Network ID will be used when connecting to other nodes, the network ID Ethernet network is a public square, in order not to conflict with the public chain network, when running a private chain of nodes to specify your own network ID. Different node ID of the network can not be connected to each other
homesteadBlock When set to 0 to use homestead publish the chain
nonce 64-bit nonce is a random number, for mining, it is noted that the settings need to meet and mixhash ether Yellow paper Square, 4.3.4. Block Header Validity, condition (44) described in section
Midge For mating with the nonce mining, hash generated by a portion of the block. Note that it is provided and the nonce needs to satisfy Yellow paper ether Square, 4.3.4. Block Header Validity, condition (44) described in section
difficulty Setting the current block of difficulty, the greater the harder mining
alloc Ethernet preset number of coins for the account and the account of, because the private chain mining easier, so we may not need to have a pre-currency account, when needed which can create your own
coinbase Miners account, you can easily write
timestamp Creation time-stamping block
parentHash On a block of hash, block creation of this parameter on 0
extraData Additional information can easily write
gasLimit The value is set to limit the total amount of consumption of the GAS for limiting the sum of the energy contained in the transaction information block. We are creating a private link, you can fill the largest

     2, the geth set a bad environment variables, and initialization block creation

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

    Once created, it can generate geth and keystore two folders,

    Geth directory used to store data block we built private chain

    Account data keystore directory used to store the user's

      3, operation geth, this message may be initiated chain under the current directory, set to the networkid blocks arranged in the creation consistent chainId

geth --datadir "./" --networkid 15

Second, interactive start node

     1, we need a console mode of the boot node start

geth --datadir "./" --networkid 15 console

    To name a few common objects

    web3 largest objects

    eth environment object

    admin permissions for configuration

    for personal account configuration

    txpool trading Pool View

    miner miner View

Using common api 2, part

//获取账户剩余金额
eth.getBalance("0xD63d4A435......350BEaED2b614B4C052")

//将金额转换为以太
web3.fromWei(eth.getBalance("0xD63d4A435......350BEaED2b614B4C052"))

//以太坊的高度数
eth.blockNumber

//获取一个新的账户
personal.newAccount()

//以太坊的账户数目
eth.accounts

//发送交易
eth.sendTransaction({from:"0xD63d4A4350f9................2b614B4C052",to:eth.accounts[0],value:10000})

//解锁交易
personal.unlockAccount(eth.accounts[0])

//挖矿开始
miner.start(1)

//挖矿结束
miner.stop()

Third, and metamask personal wallet mount

1, using the rpc geth start command, logging into the same directory output.log

geth --datadir "./" --networkid 15 --rpc console>output.log

2, the set recording metamask

3 *, dev mode Login using Ethernet Square 

geth --datadir "./" --dev console>output.log

 

Published 10 original articles · won praise 5 · Views 5663

Guess you like

Origin blog.csdn.net/u010471976/article/details/104997030