以太坊私有链搭建+挖矿+转账

2018-01-13  本文已影响154人  maxbin

初识以太坊

选择语言

GO语言安装

下载项目

yum -y install gcc
yum -y install gcc-c++

搭建私有链

Step1:创世块

{
  "config": {
        "chainId": 666,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {},
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x20000",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}
geth -datadir "/data/geth/test/" init /data/geth/genesis.json

Step2:启动私有链

geth --datadir "/data/geth/test/" --nodiscover --networkid 1999 console 2>>geth.log

Step3:设置账户

eth.accounts #查看账户
personal.newAccount("123456") #添加账户,账户的密码是123456

Step4:开始挖矿

miner.start()
tail -f geth.log
eth.getBalance(eth.accounts[0])

Step5:停止挖矿&退出console

miner.stop() #推出挖矿
exit #退出当前geth

Step6:转账

eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(5, "ether")})
Error: authentication needed: password or unlock
    at web3.js:3143:20
    at web3.js:6347:15
    at web3.js:5081:36
    at <anonymous>:1:1
personal.unlockAccount(eth.accounts[0], "123456", 300)
eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(5, "ether")})
eth.getBalance(eth.accounts[1])

geth命令参数简单介绍

下一篇介绍挖矿

上一篇下一篇

猜你喜欢

热点阅读