Geth浏览器搭建教程
项目地址
EthereumClassic Block Explorer
依赖软件
- nodejs和npm
- mongodb
安装node
安装node & npm
1 | sudo apt install nodejs |
npm 更新最新版 :
1 | sudo npm i -g npm |
node 更新:
1 | // 先安装 n 模块 |
更换镜像源
1 | npm install cnpm -g --registry=https://registry.npm.taobao.org |
Node快速切换版本、版本回退(降级)、版本更新(升级)
(1)安装node版本管理模块n:
1 | sudo npm install n -g |
(2)安装稳定版:
1 | sudo n stable |
(3)安装最新版:
1 | sudo n latest |
(4) 版本降级/升级:
1 | sudo n 版本号 |
(5)检测目前安装了哪些版本的node:
1 | n |
(6)切换版本(不会删除已经安装的其他版本):
1 | n 版本号 |
(7)删除版本:
1 | sudo n rm 版本号 |
(8)清理缓存:
1 | sudo npm cache clean --force |
安装mongodb
下载安装包
1 | curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.2.12.tgz |
附上:其他mongodb版本下载链接
解压 放到 /usr/local/ 目录下
1 | tar -zxvf mongodb-linux-x86_64-3.2.12.tgz |
切换目录
1 | cd /usr/local/mongodb |
创建数据存放的目录
1 | mkdir -p ./data/db |
进入 /usr/local/mongodb/bin 目录下,创建配置文件
1 | cd /usr/local/mongodb/bin |
1 | dbpath = /usr/local/mongodb/data/db #数据文件存放目录 |
配置文件 /etc/profile
1 | vi /etc/profile |
启动服务
1 | mongod -f /usr/local/mongodb/bin/mongodb.conf |
检查端口是否已被启动
1 | netstat -lanp | grep 27017 |
查看 mongodb 进程
1 | ps aux | grep mongodb |
设置自启动
1 | vi /etc/rc.local |
配置数据库
1 | mongo |
注1:提示Error: couldn’t add user: command createUser requires authentication,因为事先配置了auth=true,所以会在explorerDB.createUser需要验证,切换回admin数据库,使用db.auth(‘admin’,’123456’)登录后再切换回explorerDB创建用户即可
注2:执行sudo service mongodb restart,提示Failed to restart mongodb.service: Unit not found.,参考链接
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23vi /etc/systemd/system/mongodb.service
#填入以下内容
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /usr/local/mongodb/bin/mongodb.conf
[Install]
WantedBy=multi-user.target
#启动服务
systemctl start mongodb
systemctl status mongodb
#让它永久启动
systemctl enable mongodb
#完成后再次执行即可
service mongodb restart
安装浏览器
下载安装
1 | git clone https://github.com/XXQKLPro/explorer.git |
替换npm镜像源
1 | npm config set registry http://registry.npm.taobao.org |
安装浏览器
1 | cd explorer |
注:如果报错,看报错信息是哪个库没有安装上,使用一下命令单独安装
1
2
3npm install 库名@版本号 --ignore-scripts
#例如:
npm install scrypt@6.0.3 --ignore-scripts
配置节点数据
1 | cd explorer |
修改数据库配置
1 | vi db.js |
修改依赖
- 报错 Release/scrypt not found的解决办法
1 | vi node_modules/scrypt/index.js |
修改端口
1 | vi app.js |
启动Geth节点
1 | geth --datadir ./data/00 --networkid 100 --port 61910 --nodiscover --rpc --rpcapi "db,eth,net,web3,personal,miner" --ws --wsaddr 0.0.0.0 --wsapi "db,eth,net,web3,personal" --wsorigins "*" --rpccorsdomain "*" --allow-insecure-unlock console |
- 使用的是WS-RPC,需启动WS-RPC服务
启动浏览器
1 | npm start |
- 注1:第一次启动的时候回去读取区块数据,会有一堆的错误,等错误停止更新显示的时候,重新启动服务即可
- 注2:如果没有第一个区块,会nodejs会包number为定义的错误
- 注3:如果节点关闭了,浏览器服务也得重启才能连上节点
错误处理
浏览器账号重复
- 清空mongodb的explorerDB数据
1 | mongo |
代币过滤报错
- 错误:TypeError: Cannot read property ‘filter’ of undefined
- 修改routes/web3relay.js 第161行,添加 web3.trace&&
1 | web3.trace&&web3.trace.filter(filter, (err, tx) => { |