$geth --datadir data account new INFO [04-07|16:48:50.857] Maximum peer count ETH=50 LES=0 total=50 INFO [04-07|16:48:50.857] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory" Your new account is locked with a password. Please give a password. Do not forget this password. Password: Repeat password:
Your new key was generated
Public address of the key: 0x4852C36DeC855E487D46ddDD015A92612dE5Bf20 Path of the secret key file: data/keystore/UTC--2022-04-07T08-48-58.777243596Z--4852c36dec855e487d46dddd015a92612de5bf20
- You can share your public address with anyone. Others need it to interact with you. - You must NEVER share the secret key with anyone! The key controls access to your funds! - You must BACKUP your key file! Without the key, it's impossible to access account funds! - You must REMEMBER your password! Without the password, it's impossible to decrypt the key!
执行完以上操作之后的目录结构如下:
1 2 3 4 5 6 7 8 9 10
$ tree gethpoa/ gethpoa/ ├── node1 │ └── data │ └── keystore │ └── UTC--2022-04-07T11-43-40.475412645Z--7adc4a5a65ab33595ade0ed15903e8c406f69230 └── node2 └── data └── keystore └── UTC--2022-04-07T08-50-53.751660870Z--0691e168e8cc151a76a04705290702631a86c948
$ puppeth +-----------------------------------------------------------+ | Welcome to puppeth, your Ethereum private network manager | | | | This tool lets you create a new Ethereum network down to | | the genesis block, bootnodes, miners and ethstats servers | | without the hassle that it would normally entail. | | | | Puppeth uses SSH to dial in to remote servers, and builds | | its network components out of Docker containers using the | | docker-compose toolset. | +-----------------------------------------------------------+
# 首先指定一个名称 Please specify a network name to administer (no spaces, hyphens or capital letters please) > blockpoa
Sweet, you can set this via --network=blockpoa next time!
INFO [04-07|19:55:26.726] Administering Ethereum network name=blockpoa INFO [04-07|19:55:26.732] No remote machines to gather stats from
# 然后会提示选择要做的操作,我这里选择配置一个新的创世区块 What would you like to do? (default = stats) 1. Show network stats 2. Configure new genesis 3. Track new remote server 4. Deploy network components > 2
# 创建创世区块配置还是导入已有的创世区块配置? What would you like to do? (default = create) 1. Create new genesis from scratch 2. Import already existing genesis > 1
# 选择共识引擎,这里选择Clique Which consensus engine to use? (default = clique) 1. Ethash - proof-of-work 2. Clique - proof-of-authority > 2
# 多少秒出一个区块,默认时15秒 How many seconds should blocks take? (default = 15) > 3
# 哪些账户允许打包区块?当我选两个账户时报错:signed recently, must waitfor others,因此这里只选了一个账户可以打包。 Which accounts are allowed to seal? (mandatory at least one) > 0x7adC4A5a65ab33595adE0ed15903e8c406f69230 > 0x
# 哪些账户需要预先初始化一部分资金? Which accounts should be pre-funded? (advisable at least one) > 0x7adC4A5a65ab33595adE0ed15903e8c406f69230 > 0x0691e168E8cC151a76a04705290702631A86C948 > 0x
# 这些地址需要初始化1wei的资金吗?选择的yes,其实对这块不太了解为什么 Should the precompile-addresses (0x1 .. 0xff) be pre-funded with 1 wei? (advisable yes) > yes
# 指定网络ID,我这里直接随机 Specify your chain/network ID if you want an explicit one (default = random) > INFO [04-07|19:59:20.325] Configured new genesis block
# 经过以上的配置,已经配置好了,现在再次让我选择要做什么操作。我这里选择2:管理已经存在的创世区块配置 What would you like to do? (default = stats) 1. Show network stats 2. Manage existing genesis 3. Track new remote server 4. Deploy network components > 2
$ tree gethpoa/ gethpoa/ ├── blockpoa-harmony.json ├── blockpoa.json ├── node1 │ └── data │ └── keystore │ └── UTC--2022-04-07T11-43-40.475412645Z--7adc4a5a65ab33595ade0ed15903e8c406f69230 └── node2 └── data └── keystore └── UTC--2022-04-07T08-50-53.751660870Z--0691e168e8cc151a76a04705290702631a86c948
初始化创世区块配置
初始化创世区块配置(分别在每个节点目录下执行此命令)
1 2 3 4 5 6 7 8 9 10 11 12
$ geth --datadir data init ../blockpoa.json INFO [04-07|20:22:34.955] Maximum peer count ETH=50 LES=0 total=50 INFO [04-07|20:22:34.955] Smartcard socket not found, disabling err="stat /run/pcscd/pcscd.comm: no such file or directory" INFO [04-07|20:22:34.957] Set global gas cap cap=50,000,000 INFO [04-07|20:22:34.957] Allocated cache and file handles database=/home/guozhe/work/blockchain/gethpoa/node1/data/geth/chaindata cache=16.00MiB handles=16 INFO [04-07|20:22:34.975] Writing custom genesis block INFO [04-07|20:22:34.984] Persisted trie from memory database nodes=357 size=50.70KiB time=1.847678ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [04-07|20:22:34.986] Successfully wrote genesis state database=chaindata hash=9d6e3d..f10d54 INFO [04-07|20:22:34.986] Allocated cache and file handles database=/home/guozhe/work/blockchain/gethpoa/node1/data/geth/lightchaindata cache=16.00MiB handles=16 INFO [04-07|20:22:35.004] Writing custom genesis block INFO [04-07|20:22:35.012] Persisted trie from memory database nodes=357 size=50.70KiB time=2.258964ms gcnodes=0 gcsize=0.00B gctime=0s livenodes=1 livesize=0.00B INFO [04-07|20:22:35.013] Successfully wrote genesis state database=lightchaindata hash=9d6e3d..f10d54
$ bootnode -nodekey boot.key enode://5b0427c6efd2b8c1e107061527a7bfc39b74ab42db1561f8da8302622b0504d7f3afe3e7ba74b7561ddc00c256d4cacea756ff983080cb78bd8f56fd89959e88@127.0.0.1:0?discport=30301 Note: you're using cmd/bootnode, a developer tool. We recommend using a regular node as bootstrap node for production deployments. INFO [04-07|17:04:08.597] New local node record seq=1,649,322,248,596 id=1ae5556065ce551c ip=<nil> udp=0 tcp=0
Do not forget --http.addr 0.0.0.0, if you want to access RPC from other containers and/or hosts. By default, geth binds to the local interface and RPC endpoints are not accessible from the outside.
Fatal: Account unlock with HTTP access is forbidden!
--http和--unlock两个选项不能同时启用,应该是考虑到安全的问题。
也可以使用--allow-insecure-unlock选项:Allow insecure account unlocking when account-related RPCs are exposed by http。但是生产环境不建议使用此选项。