centos安装以太坊

centos安装以太坊

首先安装go环境

  1. 进入下载目录
    cd /opt/software
  2. 下载go安装包
    wget https://dl.google.com/go/go1.17.1.linux-amd64.tar.gz
  3. 解压到指定目录
    tar zxvf go1.17.1.linux-amd64.tar.gz -C /usr/local/
  4. 配置环境变量
    vim /etc/profile
  5. 修改go代理模式
    go env -w GOPROXY=https://goproxy.cn
  6. 修改GO111MODULE模式
    go env -w GO111MODULE=auto

安装扩展库

  1. 安装gcc等扩展库
    yum install bzip2 gcc-c++ ntp epel-release nodejs cmake -y
  2. 安装nodejs和npm
    curl --silent --location https://rpm.nodesource.com/setup_12.x | bash -
    yum install -y nodejs
    查看node版本:node -v
    查看npm版本:npm -v
  3. 安装solc
    npm install -g solc
    查看solc版本:solcjs --version

安装以太坊钱包

  1. 进入下载目录
    cd /opt/software
  2. 下载go-ethereum
    wget https://github.com/ethereum/go-ethereum/archive/v1.10.8.tar.gz
  3. 解压缩到指定目录
    cd /opt/module/
    tar zxvf v1.10.8.tar.gz -C /opt/module/

构建ethereum

  1. 进入到以太坊目录
    cd go-ethereum-1.10.8
  2. 编译构建
    make
  3. 配置以太网环境变量
# ethereum enviroment
export ETH_HOME=/opt/module/go-ethereum-1.10.8/build
export PATH=$PATH:$ETH_HOME/bin
  1. 使环境变量生效
    source /etc/profile

运行ethereum

  1. 进入到相应目录
    cd build/bin/
  2. 新建配置文件
    vi init.json
  3. 配置文件内容
{
  "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": "0x20",
  "mixHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
  "coinbase": "0x0000000000000000000000000000000000000000",
  "alloc": { },
  "number": "0x0",
  "gasUsed": "0x0",
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
  1. 初始化
    确保当前在build/bin/目录下
    ./geth --datadir "../../data/chain" init init.json
  2. 运行
    ./geth --rpc --rpccorsdomain "*" --datadir "../../data/chain" --port "30303" --rpcapi "db,eth,net,web3" --networkid 100000 console
    或者:geth --datadir "../../data/chain" --networkid 4224 --rpc --rpcport 8545 --port 30303 --rpccorsdomain="*" -rpcapi eth,web3,personal,net console 2> log.txt --allow-insecure-unlock
  3. 结果
    一直到出现Welcome to the Geth JavaScript console!这句话,并自动进入geth的命令行则说明以太坊私有链安装成功了。

以太坊的基本使用

基本命令

  1. 查看账户
    geth account list
  2. 创建新账号
    geth account list,输入密码
  3. 进入geth控制台
    geth console 2>> log_file_output
  4. 在控制台可以执行和geth命令行的操作,比如查看账户和创建新账户
    查看账户:eth.accounts
    创建新账户:personal.newAccount()
    解锁账号挖矿:personal.unlockAccount("address")

开启挖矿

  1. 首先进入到console控制台
    geth console 2>> log_file_output
  2. 接着设置一个挖矿账户
    miner.setEtherbase(xxxx)
  3. 开启挖矿
    miner.start()
  4. 停止挖矿
    miner.stop()
posted @ 2021-09-14 16:36  Garrett_Wale  阅读(241)  评论(0编辑  收藏  举报