linux搭建geth私有节点

linux搭建geth私有节点,第1张

linux创建节点

下载文件并上传服务器解压:Downloads | Go Ethereum

tar -zxvf geth-linux-amd64-1.10.11-7231b3ef.tar.gz
mv geth-linux-amd64-1.10.11-7231b3ef geth-1.10.11

 

然后把geth复制到/usr/bin目录下面,我们就可以使用geth命令了,geth version,出现下的界面,表示成功。 

cd /usr/local/geth-1.10.11 && cp geth /usr/bin

 然后创建 节点数据的存储位置

cd /usr/local && mkdir gethNodedata

{
  "config": {
    "chainId": 666,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "istanbulBlock": 0,
    "ethash": {}
  },
  "nonce": "0x0",
  "timestamp": "0x5ddf8f3e",
  "extraData": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "gasLimit": "0x47b760",
  "difficulty": "0x00002",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": { },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}

然后执行初始化区块的命令:

geth --datadir /usr/local/gethNodedata init /usr/local/gethNodedata/first.json

 初始化成功 

启动节点, 进入控制台,然后创建挖矿账户 进行挖矿

geth --http --http.addr 0.0.0.0 --nodiscover --datadir  "/usr/local/gethNodedata"  --port 30303 --http.api "personal,eth,net,web3,admin,ethash,miner" --http.port 18545 --http.corsdomain "*" --networkid 666 --ipcdisable  --miner.gaslimit 2000000000 --allow-insecure-unlock  console 2>>/usr/local/gethNodedata/geth.log
//创建初始账户
personal.newAccount("test")    

//解锁账户
personal.unlockAccount(eth.accounts[0])

//开启挖矿 线程1个
miner.start(1)

//获取当前区块高度
eth.blockNumber

//获取地址账户余额
eth.getBalance(eth.accounts[0])

停止挖矿

miner.stop()

exit 退出控制台,同时也听着了geth进程

把进程转入后台执行

nohup geth --http --http.addr 0.0.0.0 --nodiscover --datadir  "/usr/local/gethNodedata"  --port 30303 --http.api "personal,eth,net,web3,admin,ethash,miner" --http.port 8545 --http.corsdomain "*" --networkid 666 --ipcdisable  --mine  --miner.gasprice 0 --miner.threads 1 --miner.gaslimit 2000000000 --allow-insecure-unlock  2>>/usr/local/gethNodedata/geth.log &

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/716445.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存