美文网首页智能合约开发
【区块链基础07】-使用geth搭建私有链

【区块链基础07】-使用geth搭建私有链

作者: Geeks_Chen | 来源:发表于2018-06-26 10:25 被阅读139次

1、geth是以太坊客户端,用go语言编写。这篇主要使用geth来搭建自己的私有链,并完成挖矿和转账功能。

2、安装geth

打开终端,执行命令

brew tap ethereum/ethereum
brew install ethereum
geth version
brew tap ethereum/ethereum.png brew install ethereum.png

因为已经安装过了。

版本信息.png

3、创建创世区块

cd 文件目录,配置创世区块信息

vim genesis.json

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

初始化创世区块

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

查看区块log

geth --datadir "./" --nodiscover console 2>>geth.log
创建创世区块.png

4、挖矿

设置挖矿地址

miner.setEtherbase(eth.accounts[0])

开始挖矿

miner.start()

查询余额

eth.getBalance('0xB97168a67AB66E55B98B1439222Ee665E657fFc0')

查看节点信息

admin.nodeInfo

查看节点高度

eth.blockNumber

停止挖矿

miner.stop()
挖矿.png

5、转账

解锁

personal.unlockAccount("0xa9436991e002986f58d948d79e737df190c4f26b")

转账

eth.sendTransaction({from:eth.coinbase, to:eth.accounts[1], value: web3.toWei(0.05, "ether")})

查询余额

eth.getBalance('0xB97168a67AB66E55B98B1439222Ee665E657fFc0')
转账.png

注意,在执行转账操作时,保持挖矿状态,可以快速完成转账,如果停止挖矿,需要等待再次开始挖矿后,转账操作才可以完成。

相关文章

网友评论

    本文标题:【区块链基础07】-使用geth搭建私有链

    本文链接:https://www.haomeiwen.com/subject/egkpyftx.html