前言
之前写了一篇文章《打造自己的eth私有链》,因为篇幅的关系(写太多文字怕大家看起来不爽),我没有写如何使用自己的eth私链的相关内容,因此,写下本文以作补充。本文中还是有很多干货的,比如,如何搭建自己私链的区块链浏览器、如果使用geth等,另外,我还写为这个私链写了一个开源的钱包(开源钱包以后我会公布github地址的,目前还在开发中)。
就目前的情况来看,eth按照现在的形势是必然要消亡了,这些文字多半也是无人问津了,权当作回忆吧......
构建区块链浏览器
查阅了市面上的许多文章,很少有人在介绍搭建eth私链的同时教大家大家区块链浏览器的。geth是一个命令行工具,如果没有区块链浏览器的话,对于普通用户实在是非常不友好,因此,我认为构建一个区块链浏览器是构建自己的私链所必须做的一件事情。
区块链浏览器开源项目介绍
市面上的开源浏览器有不少,此处参考了一篇博文:https://www.cnblogs.com/huangenai/p/10075876.html,这篇博客中介绍了10款开源的区块链浏览器
| 名称 | 说明 |
|---|---|
| blockscout | https://github.com/poanetwork/blockscout |
| EthVM | https://github.com/enKryptIO/ethvm |
| etherparty/explorer | https://github.com/etherparty/explorer |
| carsenk/explorer | https://github.com/carsenk/explorer |
| etherchain-light | https://github.com/gobitfly/etherchain-light |
| toy-block-explorer | https://github.com/curvegrid/toy-block-explorer |
| mini-eth-browser | https://github.com/ismaelbej/mini-eth-browser |
| eth-explorer | https://github.com/web3space/eth-explorer |
| Clixplorer | https://github.com/Magicking/Clixplorer |
| ethereumproject / explorer | https://github.com/ethereumproject/explorer |
大家根据自己的需求进行构建,最好找MIT协议的。另外,如果需要安装mongodb的话,在ubuntu下,可以使用sudo apt-get install mongodb来快速安装。然后查询进程pgrep mongo -l(关于mongodb一篇还不错的文章https://www.cnblogs.com/shileima/p/7823434.html)
使用geth
首先进入控制台,geth attach ipc:/yourPeerDoc/geth.ipc,接下来,我们来介绍控制台命令。
控制台命令
此处参看了这篇文章https://blog.csdn.net/a191030148/article/details/78343005
| 功能 | 命令 |
|---|---|
| 获取最新区块高度 | eth.blockNumber |
| 查看区块同步情况 | eth.syncing |
| 查看连接的节点 | admin.peers.length |
| 列出所有账号 | eth.accounts |
| 查看第一个账号余额 | eth.getBalance(eth.accounts[0]) |
| 新建一个密码123456的账号 | personal.newAccount('123456') |
| ether转wei | web3.toWei(1, "ether") |
| wei转ether | web3.fromWei(1000000000000000000, "ether") |
| 开启挖矿 | miner.start(),挖矿既可以产生奖励,又可以增加区块高度。出现小锤子图标则表示挖矿成功 |
| 挖矿但是之开启一个线程 | miner.start(1) |
| 关闭挖矿 | miner.stop() |
| 设置挖矿账户 | miner.setEtherbase(eth.accounts[1]) |
| 查看区块信息 | eth.getBlock(1) |
| 查看集群信息 | admin.peers |
| 查看当前节点信息 | admin.nodeInfo.enode |
| 查看矿工账户 | eth.coinbase |
| 查询第一个账户余额 | web3.fromWei(web3.eth.getBalance(web3.eth.accounts[0]),"ether") |
| 查询第二个账户余额 | web3.fromWei(web3.eth.getBalance(web3.eth.accounts[1]),"ether") |
| 单位说明 | kwei (1000 Wei)、mwei (1000 KWei)、gwei (1000 mwei)、szabo (1000 gwei)、finney (1000 szabo)、ether (1000 finney),那么ether =wei * 10^18,也就是说精度可以达到18位。 |
| 第一个账户转账给第二个账户 | web3.eth.sendTransaction({from:web3.eth.accounts[0] , to: web3.eth.accounts[1],value: web3.toWei(1, "ether")}) |
| 解锁账户 | personal.unlockAccount(web3.eth.accounts[0]),上边这个如果没有解锁的话,会报错的,要先解锁账户。 |
0x786f7cbd3450a0d28a3e5536837c55656d876378
web3.fromWei(web3.eth.getBalance('0x786f7cbd3450a0d28a3e5536837c55656d876378'),"ether")
血 官 购 多 励 易 宜 第 辛 仁 动 课 = 0x4e0567221aa010636357d2a1a747c3e3723bd9fb
0x2a8fa720d1c19b4178bebac93adaea272fc86c97
0x0d221f5da9da6c4d2f1ab8030482ae5fab004975
0xf8b00e8503540be40083035f9094e7022554feec56ede2cb10a5e596c7681e9e95d680b844a9059cbb0000000000000000000000000d221f5da9da6c4d2f1ab8030482ae5fab0049750000000000000000000000000000000000000000000000056bc75e2d631000008611b9ed413d20a0a96013a0b599c3bce0a4b21106ffa7c14765f1eea97f9310e7970097164f3acda0440c73f5b5f046ff4c73281794668a2b7fd3748afffbc0d45caaebd0b5dd100d