ETH private chain

Environment: reference materials at the end of macos
other environment reference articles

1. Install the geth tool

Choose the version that suits your system and needs. There are two versions: geth and geth&tools.
Download address: https://geth.ethereum.org/downloads/

终端下载命令
wget https://gethstore.blob.core.windows.net/builds/geth-alltools-darwin-amd64-1.10.25-69568c55.tar.gz
解压
tar -zxvf geth-alltools-darwin-amd64-1.10.25-69568c55.tar.gz
配置环境变量,不配置环境变量,全局不可用
export PATH=$PATH:压缩文件解压的路径
测试是否安装成功
geth version
如下则说明安装成功

insert image description here

2. create account

创建一个账户,建议在一个方便自己管理的文件夹下创建账户,data就是文件夹名称,没有前缀,则是当前文件夹
geth account new --datadir data
创建账号的时候,需要一个创建密码,这个密码应该是用来生成账号的的字符串,要记住,后续解锁的活着签名的时候,获取能用到
创建账号成功之后应该有如下文件

insert image description here

3. create config

vim genesis.json
{
    
    
  "config": {
    
    
    "chainId": 12345,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "berlinBlock": 0,
    "ethash": {
    
    }
  },
  "difficulty": "1",
  "gasLimit": "8000000",
  "alloc": {
    
    
    "7df9a875a174b3bc565e6424a0050ebc1b2d1d82": {
    
     "balance": "300000" },
    "f41c74c9ae680c1aa78f42e5647a62f353b7bdde": {
    
     "balance": "400000" }
  }
}

4. If it has been built before, it needs to be built again, and the previous files need to be cleaned up

删除原来的创世块
geth removedb --datadir data

5. init

geth init --datadir data genesis.json

6. run private chain node

geth --datadir ./data --networkid 1008  --http --http.addr 0.0.0.0 --http.vhosts "*" --http.api "db,net,eth,web3,personal" --http.corsdomain "*" --snapshot=false --mine --miner.threads 1 --allow-insecure-unlock  console 2> 1.log
参数介绍
datadir 指定之前初始化的数据目录文件
networkid 配置成与配置文件config内的chainId相同值,代表加入哪个网络,私链就自己随意编号即可
http 代表开启远程调用服务,这对我们很重要
http.port 远程服务的端口,默认是8545
http.api 远程服务提供的远程调用函数集
http.corsdomain 指定可以接收请求来源的域名列表(浏览器访问,必须开启)
allow-insecure-unlock 新版本增加的选项,允许在Geth命令窗口解锁账户
mine 开启挖矿
miner.threads 设置挖矿的线程数量
console 进入管理台
2> 1.log Unix系统下的重定向,将Geth产生的日志输出都重定向到1.log中,以免刷日志影响操作

References

Guess you like

Origin blog.csdn.net/wjl__ai__/article/details/127175429