企业级区块链-HyperLeger Fabric v1.0.0 走近“智能合约”

本文档详细介绍了如何配置和使用Hyperledger Fabric v1.0.0的智能合约环境。首先,通过安装Node.js、升级npm和设置环境变量来准备开发环境。接着,通过初始化客户端、开启Fabric网络和创建通道来启动智能合约。在过程中,包括了加入通道、安装链码和调用链码的操作。最后,展示了如何查询和更新账本上的数据,以及智能合约的主要功能,如查询特定Car和修改Car的owner。
摘要由CSDN通过智能技术生成

Smart Contract    一步步走近“智能合约”    


  • 配置“智能合约”运行环境

  • 基础配置请参考前两篇文章

  • Node.js(目前Fabric只支持6.9.X或更早版本)下载安装

https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz


[root@huangzhenhua tmp]# tar -xJf node-v6.9.2-linux-x64.tar.xz -C /usr/local/


  • 设置node环境变量

[root@huangzhenhua Desktop]# vi /etc/profile

export NODE_HOME=/usr/local/node-v6.9.2-linux-x64

export PATH=$NODE_HOME/bin:$PATH

[root@huangzhenhua Desktop]# source /etc/profile


  • 检查node配置是否成功

[root@huangzhenhua Desktop]# node -v

v6.9.2

[root@huangzhenhua Desktop]# npm -v

3.10.9

  • 升级npm

[root@huangzhenhua Desktop]# npm install npm@3.10.10 -g

#安装g++,以便npm install初始化环境编译成功

[root@huangzhenhua Desktop]#yum install gcc-c++ libstdc++-devel


  • 开启“智能合约”之旅


  • 初始化客户端

[root@huangzhenhua Desktop]#cd /opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar

[root@huangzhenhua fabcar]# npm install

[root@huangzhenhua fabcar]# ls

enrollAdmin.js invoke.js  node_modules  package.json  query.js  registerUser.js  startFabric.sh

#新增node_modules目录


  • 开启Fabric网络

[root@huangzhenhua fabcar]# ./startFabric.sh

# don't rewrite paths for Windows Git Bash users

export MSYS_NO_PATHCONV=1

docker-compose -f docker-compose.yml down

Removing network net_basic

WARNING: Network net_basic not found.

docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb

Creating orderer.example.com ... done

Creating peer0.org1.example.com ... done

Creating ca.example.com ... 

Creating couchdb ... 

Creating peer0.org1.example.com ... 

# wait for Hyperledger Fabric to start

# incase of errors when running later commands, issue export FABRIC_START_TIMEOUT=<larger number>

export FABRIC_START_TIMEOUT=10

#echo ${FABRIC_START_TIMEOUT}

sleep ${FABRIC_START_TIMEOUT}

# Create the channel

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx

2018-02-09 01:57:19.575 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP

2018-02-09 01:57:19.575 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity

2018-02-09 01:57:19.613 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized

2018-02-09 01:57:19.772 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP

2018-02-09 01:57:19.773 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity

2018-02-09 01:57:19.782 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP

2018-02-09 01:57:19.782 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity

2018-02-09 01:57:19.782 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0A88060A074F7267314D535012FC052D...53616D706C65436F6E736F727469756D 

2018-02-09 01:57:19.782 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 75403FC8DC482C1B3066D9C407AADB725386A3726C62C555B04DB36939776BE6 

2018-02-09 01:57:19.784 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP

2018-02-09 01:57:19.784 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity

2018-02-09

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值