以太坊Geth私链环境搭建

Ubuntu环境

安装Geth:

sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

查看geth版本

dell@dell-VirtualBox:~/dapp/course$ geth version

Geth
Version: 1.9.25-stable
Git Commit: e7872729012a4871397307b12cc3f4772ffcbec6
Architecture: amd64
Protocol Versions: [65 64 63]
Go Version: go1.15.6
Operating System: linux
GOPATH=
GOROOT=go

生成genesis.json文件

dell@dell-VirtualBox:~/dapp/course$ vim genesis.json

输入

{
	"nonce": "0x0000000000000042",
	"difficulty": "0x200",
	"mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000",
	"coinbase": "0x0000000000000000000000000000000000000000",
	"timestamp": "0x00",
	"parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
	"extraData": "0x",
	"gasLimit": "0x2CD29C0",
	"alloc": {},
	"config": {
		"chainId": 6500,
		"homesteadBlock": 0
    }
}

初始化

geth --datadir “chain” init genesis.json

启动geth

geth --identity "myethereum" --rpc --rpccorsdomain "*" --datadir "chain" --port "30303" --rpcapi "db,eth,net,web3,personal,miner" --networkid "6500" console 2>1.txt
  • –datadir : 指定当前节点存在位置,“chain”
  • –identity : 区块链的标示,自定义,用于标示目前网络的名字
  • –rpc : 启用http-rpc服务器,可以进行智能合约的部署和调试
  • –rpcapi : 基于http-rpc提供的api接口。eth,net,web3,db…
  • –rpcaddr : http-rpc服务器接口地址:默认“127.0.0.1”
  • –rpcport : http-rpc端口(多节点时,不要重复)
  • –port : 节点端口号(多节点时,不要重复)
  • –networkid : 网络标识符 随便指定一个id(确保多节点是统一网络,保持一致)
  • –console :启动命令行模式,可以在Geth中执行命令
> eth.blockNumber
0
> personal.newAccount("account1")
"0x22b7d9435328d56266d8ea9a7def7d3366133bd4"
> eth.accounts
["0x22b7d9435328d56266d8ea9a7def7d3366133bd4"]
> miner.start()
null
> eth.mining
true
> miner.stop()
null
> eth.mining
false
上一篇:前后端分离(Vue+SpringBoot)实现下载功能


下一篇:mobx状态管理快速入门