010.go-ethereum安装
下载页面:https://ethereum.github.io/go-ethereum/downloads/
下载地址:当前最高版本为v1.8.19
tar zxvf geth-linux-amd64-1.8.19-dae82f09.tar.gz -C /usr/local/
ln -s /usr/local/geth-linux-amd64-1.8.19-dae82f09/geth /usr/bin/geth
输入命令:geth version,得到以下信息,证明安装成功:
[root@geth01 ~]# geth version
WARN [12-08|15:14:05.785] Sanitizing cache to Go's GC limits provided=1024 updated=324
Geth
Version: 1.8.19-stable
Git Commit: dae82f098570e15d44584f0d7f350713f4774727
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.11.2
Operating System: linux
GOPATH=
GOROOT=/home/travis/.gimme/versions/go1.11.2.linux.amd64
[root@geth01 ~]#
020.搭建测试链
021.创建工作目录(随便起名)
mkdir -p /usr/local/deploy/geth_demo
cd /usr/local/deploy/geth_demo/
022.启动进入控制台
[root@geth01 geth_demo]# geth --rpc --rpcaddr="0.0.0.0" --rpccorsdomain="*" --nodiscover --networkid '7758521' --datadir './chain' --dev --dev.period 1 console 2>>nohup.log
Welcome to the Geth JavaScript console!
instance: Geth/v1.8.19-stable-dae82f09/linux-amd64/go1.11.2
coinbase: 0x6b3b84d7a608dfdaff23e769e0c9bced682dff8e
at block: 1 (Sat, 08 Dec 2018 15:10:09 CST)
datadir: /usr/local/deploy/geth_demo/chain
modules: admin:1.0 clique:1.0 debug:1.0 eth:1.0 miner:1.0 net:1.0 personal:1.0 rpc:1.0 shh:1.0 txpool:1.0 web3:1.0
>
参数说明:
--rpc :rpc方式启动
--rpcaddr="0.0.0.0" :设置rpc请求地址
--rpccorsdomain="*" : 跨域
--nodiscover :私有链地址,不会被网上看到
--networkid '7758521' :网络id在连接到其他节点的时候会用到,以太坊公网的网络id是1,为了不与公有链网络冲突,运行私有链节点的时候要指定自己的网络id
--datadir './chain' : 数据文件夹,默认地址:
--dev :使用POA共识网络,默认预分配一个开发者账户并且会自动开启挖矿。
--dev.period value :开发者模式下挖矿周期 (0 = 仅在交易时) (默认: 0)
console :启动交互式JavaScript环境
2>>nohup.log :console的输出,打印到nohub.log中
023.查看日志
另起一个shell,进入相同目录,查看nohup.log
tail -f nohup.log
出现类似的信息,表名旷工正在挖矿;
INFO [12-07|10:27:53.002] ? block reached canonical chain number=687 hash=3904bd…ad495c
INFO [12-07|10:27:53.002] ? mined potential block number=694 hash=4dd09f…0edeaa
INFO [12-07|10:27:53.003] Commit new mining work number=695 sealhash=4d52be…7673de uncles=0 txs=0 gas=0 fees=0 elapsed=1.211ms
INFO [12-07|10:27:54.001] Successfully sealed new block number=695 sealhash=4d52be…7673de hash=12e664…54c5bc elapsed=998.215ms
INFO [12-07|10:27:54.001] ? block reached canonical chain number=688 hash=895562…2e476b
INFO [12-07|10:27:54.002] ? mined potential block number=695 hash=12e664…54c5bc
INFO [12-07|10:27:54.003] Commit new mining work number=696 sealhash=61ca0e…257155 uncles=0 txs=0 gas=0 fees=0 elapsed=1.125ms
INFO [12-07|10:27:55.001] Successfully sealed new block number=696 sealhash=61ca0e…257155 hash=661cd0…6babcf elapsed=998.141ms
INFO [12-07|10:27:55.001] ? block reached canonical chain number=689 hash=961581…b63c54
INFO [12-07|10:27:55.001] ? mined potential block number=696 hash=661cd0…6babcf
INFO [12-07|10:27:55.002] Commit new mining work number=697 sealhash=dd486a…2f2b06 uncles=0 txs=0 gas=0 fees=0 elapsed=1.072ms
INFO [12-07|10:27:56.001] Successfully sealed new block number=697 sealhash=dd486a…2f2b06 hash=cf0cd3…56e68b elapsed=998.915ms
INFO [12-07|10:27:56.001] ? block reached canonical chain number=690 hash=16b12e…b0d2d8
INFO [12-07|10:27:56.002] ? mined potential block number=697 hash=cf0cd3…56e68b
INFO [12-07|10:27:56.003] Commit new mining work number=698 sealhash=d0906a…e64c88 uncles=0 txs=0 gas=0 fees=0 elapsed=1.174ms
INFO [12-07|10:27:57.001] Successfully sealed new block number=698 sealhash=d0906a…e64c88 hash=dba025…3f210a elapsed=998.677ms
INFO [12-07|10:27:57.002] ? block reached ca
024.账号管理
测试环境,默认会给创建一个账号,并分配一定余额。
查看所有账号:
> eth.accounts
["0x7a007c2c2662abecad3f7479df7a395e0840fddf"]
>
0x7a007c2c2662abecad3f7479df7a395e0840fddf为该账号地址。
添加账号(这里新添加了2个,添加后一共是3个):
> personal.newAccount('123456')
"0x77bda524268cbab982f16c84f8ccc4ed342d31a5"
> personal.newAccount('123456')
"0xdfdb6e33886e295f29967bb5d66bd9a0064af547"
> eth.accounts
["0x7a007c2c2662abecad3f7479df7a395e0840fddf", "0x77bda524268cbab982f16c84f8ccc4ed342d31a5", "0xdfdb6e33886e295f29967bb5d66bd9a0064af547"]
>
这里的123456是对应账号的密码。为账户起个别名:
> u0=eth.accounts[0]
"0x7a007c2c2662abecad3f7479df7a395e0840fddf"
> u1=eth.accounts[1]
"0x77bda524268cbab982f16c84f8ccc4ed342d31a5"
> u2=eth.accounts[2]
"0xdfdb6e33886e295f29967bb5d66bd9a0064af547"
>
> u0
"0x7a007c2c2662abecad3f7479df7a395e0840fddf"
> u1
"0x77bda524268cbab982f16c84f8ccc4ed342d31a5"
> u2
"0xdfdb6e33886e295f29967bb5d66bd9a0064af547"
>
025.钱包管理
查看账户的余额:(以下命令作用、效果一样):
> eth.getBalance(eth.accounts[0])
1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
>
> eth.getBalance('0x6b3b84d7a608dfdaff23e769e0c9bced682dff8e')
1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
>
> eth.getBalance(u0)
1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
>
查看所有账户的资产:
> eth.getBalance(u0)
1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
>
> eth.getBalance(u1)
0
>
> eth.getBalance(u2)
0
>
026.转账
u0用户给u1账户转账,10000 wei
> eth.sendTransaction({from: u0, to: u1, value: 10000})
"0x02d0fe9fbaa982ea2382f339cc6a925a0427778a38521f9e2220e1432966bfd6"
>
查看所有账户的资产:
> eth.getBalance(u0)
1.15792089237316195423570985008687907853269984665640564039457584007913129629927e+77
>
> eth.getBalance(u1)
10000
>
> eth.getBalance(u2)
0
>
查看交易信息:
> eth.getTransaction('0x02d0fe9fbaa982ea2382f339cc6a925a0427778a38521f9e2220e1432966bfd6')
{
blockHash: "0x3a1612fb9a1a74d1b3b99f3436982db9f8a6e2d355f906264ce18ce181c4cce4",
blockNumber: 15934,
from: "0x6b3b84d7a608dfdaff23e769e0c9bced682dff8e",
gas: 90000,
gasPrice: 1,
hash: "0x02d0fe9fbaa982ea2382f339cc6a925a0427778a38521f9e2220e1432966bfd6",
input: "0x",
nonce: 0,
r: "0x7c6da9f718db2ef17de47c723eda1666e03bedb1e423dd3ff78c60a323631474",
s: "0x7701fe59f556775f778cd77225bc57986f694add5ee145d72ea73668449455cf",
to: "0xf3e7792736fb4f1706c0acaa5f4f84b821b6be62",
transactionIndex: 0,
v: "0xa95",
value: 10000
}
>
未完,细节待补充。。。。