ubuntu参考https://blog.csdn.net/bingzhongdehuoyan/article/details/79411479
Mac参考https://blog.csdn.net/jiang_xinxing/article/details/58025417
Windows参考http://www.runoob.com/docker/windows-docker-install.html
service docker start
docker pull registry.cn-hangzhou.aliyuncs.com/truechain_space/truechain_image:latest
docker tag registry.cn-hangzhou.aliyuncs.com/truechain_space/truechain_image etrue
1.创建truechain目录
mkdir truechain
2.进入目录
cd truechain
3.创建genesis.json文件
touch genesis.json
sudo vi genesis.json
文件内容是:
{
"config": {
"chainId": 10,
"homesteadBlock": 0,
"eip155Block": 0,
"eip158Block": 0
},
"alloc":{
"0x7c357530174275dd30e46319b89f71186256e4f7" : { "balance" : 90000000000000000000000},
"0x4cf807958b9f6d9fd9331397d7a89a079ef43288" : { "balance" : 90000000000000000000000},
"0x04d2252a3e0ca7c2aa81247ca33060855a34a808" : { "balance" : 90000000000000000000000},
"0x05712ff78d08eaf3e0f1797aaf4421d9b24f8679" : { "balance" : 90000000000000000000000},
"0x764727f61dd0717a48236842435e9aefab6723c3" : { "balance" : 90000000000000000000000},
"0x764986534dba541d5061e04b9c561abe3f671178" : { "balance" : 90000000000000000000000},
"0x0fd0bbff2e5b3ddb4f030ff35eb0fe06658646cf" : { "balance" : 90000000000000000000000},
"0x40b3a743ba285a20eaeee770d37c093276166568" : { "balance" : 90000000000000000000000},
"0x9d3c4a33d3bcbd2245a1bebd8e989b696e561eae" : { "balance" : 90000000000000000000000},
"0x35c9d83c3de709bbd2cb4a8a42b89e0317abe6d4" : { "balance" : 90000000000000000000000}
},
"committee":[
{
"address": "0x76ea2f3a002431fede1141b660dbb75c26ba6d97",
"publickey": "0x04044308742b61976de7344edb8662d6d10be1c477dd46e8e4c433c1288442a79183480894107299ff7b0706490f1fb9c9b7c9e62ae62d57bd84a1e469460d8ac1"
}
]
,
"coinbase" : "0x0000000000000000000000000000000000000000",
"difficulty" : "0x100",
"extraData" : "",
"gasLimit" : "0x5400000",
"nonce" : "0x0000000000000042",
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp" : "0x00"
}
简单介绍一下这个genesis.json
chainId 链的ID alloc 系统自带的两个地址及余额 coinbase 矿工工号 difficulty 挖矿难度 extraData 扩展字段 gasLimit 交易手续费 nonce 随机字符串,用于挖矿 mixhash 配合nonce进行挖矿 parentHash 上一个区块的哈希 timestamp 区块生成的时间
1.在truechain目录下执行下面命令
docker run -v $PWD:/truechain-engineering-code -v $PWD/data:/truechain-engineering-code/data -it etrue --datadir /truechain-engineering-code/data init /truechain-engineering-code/genesis.json
1.进入truechain目录下,启动单节点测试网络
docker run -v $PWD:/truechain-engineering-code -it etrue --singlenode --datadir /truechain-engineering-code/data --bftkeyhex "c1581e25937d9ab91421a3e1a2667c85b0397c75a195e643109938e987acecfc" --election --bftip "172.21.0.5" --bftport 10080 --port 30303 --networkid 10 --rpc --rpcaddr 127.0.0.1 --rpcport 8545 --rpcapi "db,etrue,net,web3,personal,admin,miner" console
2.解析命令
1)-singlenode --bftkeyhex "xxx" 单节点启动网络,参数是节点私钥,该私钥和genesis文件里的公钥是一对. 2)--election --bftip "172.26.246.28" --bftport 10080 本节点参与委员会选举,配置自己的ip和端口。但单节点运行环境,本身就是委员会节点,所以这条命令可以不用。
1.查询账户:etrue.accounts
2.查询账户余额:etrue.getBalance("账户地址")
3.创建账户:personal.newAccount()
4.转账数额位和true单位转换:amount = web3.toWei(5000,'ether')
5.账户解锁:personal.unlockAccount(etrue.accounts[0])或 personal.unlockAccount(“账户地址”)
6.转账交易:etrue.sendTransaction({from:"xxx",to:"xxx",value:amount})
7.查询挖矿的coinbase地址:etrue.coinbase
8.启动挖矿,括号内可以添加数字,表示开启几个线程:miner.start()
9.停止挖矿:miner.stop()
10.etrue.getTransactionReceipt("xxx")