geth私链环境搭建

操作系统:Ubuntu18.04

目录

1.安装geth

2.创建创世区块

3.初始化创世区块

4.启动私链

5.新建账户

6.挖矿

7.停止

8.查看本节点信息

9.向本节点添加其他P2P节点信息 

10.解锁需要向外转账的账户

11.向他人转账

11.其他


1.安装geth

sudo add-apt-repository -y ppa:ethereum/ethereum
//libappstream3 可能导致update失败,先删除
update
sudo apt-get purge libappstream3
sudo apt-get update
sudo apt-get install ethereum

2.创建创世区块

mkdir -p ~/privateChainTest/data0
建立创世区块genesis.json

{
	"config": {
		"chainID": 2019
	},
	"alloc": {
		"0xeced0f2076c6f790173f38012f130a9e5c493a95": {
			"balance": "100000000000000000000000000"
		}
	},
	"coinbase": "0x0000000000000000000000000000000000000000",
	"difficulty": "0x400",
	"extraData": "",
	"gasLimit": "0x2fefd8",
	"nonce": "0xdeadbeefdeadbeef",
	"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
	"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
	"timestamp": "0x00"
}

3.初始化创世区块

cd privateChain
geth --datadir data0 init genesis.json

4.启动私链

geth --identity "qtlnode" --targetgaslimit 4294967295 --gasprice 1000000000 --rpc --rpcport "8545" --rpcaddr 0.0.0.0 --rpccorsdomain "*" --datadir data0 --port "30303" console

5.新建账户

personal.newAccount()

6.挖矿

miner.start()

7.停止

miner.stop()

8.查看本节点信息

admin.nodeInfo

9.向本节点添加其他P2P节点信息 

admin.addPeer("enode://f2c91ee24585e592fa5adc1940360b90e1a10969c5955fc51807bb24ab5e34265994c36f3af51a982a3d6d66f73b8cbba99ad38739545812724d60bf5c58e684@192.168.0.111:30303")

10.解锁需要向外转账的账户

personal.unlockAccount()

11.向他人转账

eth.sendTransaction({from:本节点账号,to:对方账号,value:转账数量})
eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:100000000000000000})

11.其他

geth启动可以加
--verbosity "2"来关闭log输出
geth --verbosity "2" --identity "qtlnode" --targetgaslimit 4294967295 --gasprice 1000000000 --rpc --rpcport "8545" --rpcaddr 0.0.0.0 --rpccorsdomain "*" --datadir data0 --port "30303" console

附:以太坊客户端Geth命令详解:https://www.jianshu.com/p/5783b59a4501

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值