接着上一个课程,创建通道后,就可以在这个通道上部署智能合约(也叫链码)了。
智能合约是介于区块链与业务系统之间,它是业务系统与区块链数据进行交互(设置,更新,获取数据)的工具。
正常情况下区块链开发分为区块链底层开发和DAPP应用开发两大类,本节之前的部署甚至定制开发都是链的底层开发,相当于开发window或liunx操作系统一样性质,目前国内外都是有部署好的服务可以直接调用,不需要开发者从零开始,因此它注定不是大众化。
我们大部分区块链开发都是DAPP应用开发这一类,而DAPP应用开发就是智能合约开发+传统业务系统开发。因此学会智能合约开发,再加上之前的web开发(或公众号开发,小程序开发,甚至原生APP)就可以参与完整区块链开发中。
在本案例中已经有开发好的智能合约,我们现在只需要直接部署就好
在git base中执行:
`
1. ./network.sh deployCC
`
第一次执行时需要下载相应的智能合约相关文件和依赖,时间可能比较长,安装成功后会提示下图的内容
上面的命令执行了以下几个部署:
把案例中提供的智能合约(fabcar chaincode)部署到测试网络上的两个组织的peer0节点上
使用的通道就是我们上一节创建的默认通道上(mychannel)
默认安装的智能合约的版本是golang语言版本,其它可以使用-l 来选择Java或javascript版本
智能合约部署到通道上后,执行了智能合约的init的初始化函数,实现数据(汽车列表)初始化
最后执行了智能合约的查询功能,验证是否已正确增加好了初始化的数据:
[{"Key":"CAR0","Record":{"make":"Toyota","model":"Prius","colour":"blue","owner":"Tomoko"}},{"Key":"CAR1","Record":{"make":"Ford","model":"Mustang","colour":"red","owner":"Brad"}},{"Key":"CAR2","Record":{"make":"Hyundai","model":"Tucson","colour":"green","owner":"Jin Soo"}},{"Key":"CAR3","Record":{"make":"Volkswagen","model":"Passat","colour":"yellow","owner":"Max"}},{"Key":"CAR4","Record":{"make":"Tesla","model":"S","colour":"black","owner":"Adriana"}},{"Key":"CAR5","Record":{"make":"Peugeot","model":"205","colour":"purple","owner":"Michel"}},{"Key":"CAR6","Record":{"make":"Chery","model":"S22L","colour":"white","owner":"Aarav"}},{"Key":"CAR7","Record":{"make":"Fiat","model":"Punto","colour":"violet","owner":"Pari"}},{"Key":"CAR8","Record":{"make":"Tata","model":"Nano","colour":"indigo","owner":"Valeria"}},{"Key":"CAR9","Record":{"make":"Holden","model":"Barina","colour":"brown","owner":"Shotaro"}}]
===================== Query successful on peer0.org1 on channel 'mychannel' =====================
本文由小韦云原创,转载请注明出处:https://www.bctos.cn/doc/4/1805,否则追究其法律责任
有疑问加站长微信联系(非本文作者)