基于hyperledger fabric 联盟链 + vue cli的项目搭建完整教程
二、样例项目搭建
1. node 安装配置
配置raw.githubusercontent.com端口
使用端口查询在线网址查询端口
即https://githubusercontent.com.ipaddress.com/
搜索raw.githubusercontent.com的端口
修改hosts文件
vi /etc/hosts
添加形如下的配置:
151.101.108.133 raw.githubusercontent.com
nvm管理器安装
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
或者
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.1/install.sh | bash
执行
source ~/.bashrc
nvm下载管理node
nvm --version
nvm ls-remote
nvm install v10.6.0
nvm install v8.9.4
nvm install v6.9.5
nvm ls
nvm use 6.9.5
下载cnpm
npm install -g cnpm --registry=http://registry.npm.taobao.org
2. 测试投票样例
安装python,make
sudo apt install python
sudo apt-get install make
下载样例项目
git clone https://github.com/didianV5/voteApp.git
# 或者从笔者仓库下载
# git clone https://github.com/1853582/fabric-VoteApp
chmod -R 777 voteApp
cd voteApp
cd app
#如果说容器被占用,则:
sudo su
docker stop $(docker ps -aq)
docker rm -f $(docker ps -aq)
执行区块链网络环境生成
./startFabric.sh
nvm use 6.9.5
npm install
nvm use 8.9.4
npm rebuild
node enrollAdmin.js
node registerUser.js
修改controller中index.js里面的store_path为你现在hfc-key-store所在的绝对路径
在index.js注释掉
let event_hub = fabric_client.newEventHub();
event_hub.setPeerAddr('grpc://localhost:7053');
加上
let event_hub = channel.newChannelEventHub('localhost:7051');
注释掉
console.log('The transaction has been committed on peer ' + event_hub._ep._endpoint.addr);
加上
console.log('The transaction has been committed on peer ' + event_hub.getPeerAddr());
执行node index.js打开http://localhost:3000/
以上步骤结束后,一个使用koa后端进行区块链存储的建议样例搭建完毕
[1]: 参考链接 (作者:孔壹学院之投票系统 )https://www.bilibili.com/video/BV1a4411X7Z1?p=24