Hyperledger Fabric学习笔记--06- 投票项目部署

投票项目部署

git	clone https://github.com/didianV5/voteApp.git 

chmod	-R	777	voteApp
cd	voteApp
cd	app

#删除 docker	容器
docker rm -f $(docker ps -aq)

#启动fabric的网络
./startFabric.sh

#安装 node 依赖包
npm	install

#注册管理员
node enrollAdmin.js

#注册用户
node registerUser.js

#启动项目
node index.js


访问 http://localhost:3000

遇到的问题

  • 问题描述: 添加投票时显示 txid:undefined

    Failed to invoke successfully :: TypeError: fabric_client.newEventHub is not a function

  • 解决方法:

    https://stackoverflow.com/questions/51436123/unable-to-find-neweventhub-function?answertab=votes#tab-top

代码分析

使用了koa框架 + fabric-node-sdk, 核心代码如下:

//调用Chaincode的 getUserVote方法查询所有用户的投票信息
const request = {
    chaincodeId: 'vote',
    txId: tx_id,
    fcn: 'getUserVote',
    args: [""]
};

// send the query proposal to the peer
return channel.queryByChaincode(request);

//-----------------------------------------

//调用Chaincode的 voteUser方法进行投票
// send proposal to endorser
const request = {
    chaincodeId: 'vote',
    fcn: 'voteUser',
    args: [username],
    chainId: 'mychannel',
    txId: tx_id
};

// send the transaction proposal to the peers
return channel.sendTransactionProposal(request);

运行效果

在这里插入图片描述

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值