55

TrueChain测试网络搭建

 6 years ago
source link: https://studygolang.com/articles/14629?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

安装系统环境

注:本文操作在MAC环境下。

1.安装go环境(go需要1.7及以上版本)

  1. mac 执行命令 brew install go 即可。
    遇到被墙问题,可以浏览器打开 https://studygolang.com/dl/golang/go1.10.3.darwin-amd64.pkg 下载,然后一步步安装即可。
  2. 配置GOPATH环境变量。依次执行以下命令:
    执行 cd ~
    执行 vi .bash_profile
    在 .bash_profile中插入一行自己的项目目录地址 export GOPATH=/
    sers/edz/go
    执行 go env
    若输出结果中有GOPATH值与上面设置的相同,则表示已成功设置。如图
nAf2AbB.jpg!web

1.jpg

2.配置C编译器

  1. mac 端执行 brew install gcc

编译源文件

  1. 下载项目源码 https://github.com/truechain/truechain-engineering-code
  2. 进入项目目录。进行编译。执行命令: make getrue
  3. 编译完成后。getrue命令所在路径为 项目目录/build/bin/。如图
  4. 将getrue路径添加系统环境变量
ru2UbeA.jpg!web

3.jpg

getrue命令

getrue --help 查看命令帮助,如图

J3i26n2.jpg!web

4.jpg

genesis.json

创建自己的测试网络。首先需要创建网络的创世状态,让所有节点知道并同意这个状态。

创世状态(或创世区块)是一个小型的JSON文件。如下图

JrQ7VrF.jpg!web

2.jpg

简单介绍一下这个genesis.json
chainId    链的ID
alloc      系统自带的两个地址及余额
coinbase   矿工工号
difficulty 挖矿难度
extraData  扩展字段
gasLimit   交易手续费
nonce      随机字符串,用于挖矿
mixhash    配合nonce进行挖矿
parentHash 上一个区块的哈希
timestamp  区块生成的时间

搭建测试网络

step1. 建立测试目录。例如Test

step2. 引用源码中cmd/getrue中的genesis.json文件,文件的内容如下。

{
  "config": {
        "chainId": 10,
        "homesteadBlock": 0,
        "eip155Block": 0,
        "eip158Block": 0
    },
  "alloc"      : {
      "0x970e8128ab834e8eac17ab8e3812f010678cf791" : { "balance" : "90000000000000000000000"},
      "0x68f2517b6c597ede0ae7c0559cdd4a84fd08c928" : { "balance" : "10000000000000000000000"}
      },
  "coinbase"   : "0x0000000000000000000000000000000000000000",
  "difficulty" : "0x200",
  "extraData"  : "",
  "gasLimit"   : "0x2fefd8",
  "nonce"      : "0x0000000000000042",
  "mixhash"    : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
  "timestamp"  : "0x00"
}

step3. 创建创世区块。执行如下命令

getrue --datadir Test init path/to/cmd/getrue/genesis.json

--datadir用来指定目录。以上命令执行完成后,目录中多了getrue和keystore两个文件夹。getrue文件夹下用来存放该链的相关数据,keystore文件夹下存放的是该链的用户信息如图

step4. 启动测试链起始节点。执行如下命令

getrue --datadir Test --nodiscover console 2>>getrue.log


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK