In this step by step tutorial we'll walk through setting up a business network, defining our assets, participants and transactions, and testing our network by creating some participants and an asset, and submitting transactions to change the ownership of the asset from one to another.

Step One: Open the IBM Blockchain Platform: Develop Playground

Open Blockchain Platform Playground. You should see the My Business Network screen. The My Business Networkpage shows you a summary of the business networks you can connect to, and the identities you can use to connect to them. Don't worry about this too much for the time being, as we're going to create our own network.

Step Two: Creating a new business network

Next, we want to create a new business network from scratch. A business network has a couple of defining properties; a name, and an optional description. You can also choose to base a new business network on an existing template, or import your own template.

  1. Click Deploy a new business network under the Web Browser heading to get started.

  2. The new business network needs a name, let's call it tutorial-network.

  3. Optionally, you can enter a description for your business network.

  4. Next we must select a business network to base ours on, because we want to build the network from scratch, click empty-business-network.

  5. Now that our network is defined, click Deploy.

Step Three: Connecting to the business network

Now that we've created and deployed the business network, you should see a new business network card called adminfor our business network tutorial-network in your wallet. The wallet can contain business network cards to connect to multiple deployed business networks.

When connecting to an external blockchain, business network cards represent everything necessary to connect to a business network. They include connection details, authentication material, and metadata.

To connect to our business network click Connect now under our business network card.

Step Four: Adding a model file

As you can see, we're in the Define tab right now, this tab is where you create and edit the files that make up a business network definition, before deploying them and testing them using the Test tab.

As we selected an empty business network template, we need to define our business network files. The first step is to add a model file. Model files define the assets, participants, transactions, and events in our business network.

For more information on our modeling language, check our documentation.

  1. Click the Add a file button.

  2. Click the Model file and click Add.

  3. Delete the lines of code in the model file and replace it with this:

    /**
    * My commodity trading network
    */
    namespace org.acme.mynetwork
    asset Commodity identified by tradingSymbol {
    o String tradingSymbol
    o String description
    o String mainExchange
    o Double quantity
    --> Trader owner
    }
    participant Trader identified by tradeId {
    o String tradeId
    o String firstName
    o String lastName
    }
    transaction Trade {
    --> Commodity commodity
    --> Trader newOwner
    }

    This domain model defines a single asset type Commodity and single participant type Trader and a single transaction type Trade that is used to modify the owner of a commodity.

Step Five: Adding a transaction processor script file

Now that the domain model has been defined, we can define the transaction logic for the business network. Composer expresses the logic for a business network using JavaScript functions. These functions are automatically executed when a transaction is submitted for processing.

For more information on writing transaction processor functions, check our documentation.

  1. Click the Add a file button.

  2. Click the Script file and click Add.

  3. Delete the lines of code in the script file and replace it with the following code:

    /**
    * Track the trade of a commodity from one trader to another
    * @param {org.acme.mynetwork.Trade} trade - the trade to be processed
    * @transaction
    */
    function tradeCommodity(trade) {
    trade.commodity.owner = trade.newOwner;
    return getAssetRegistry('org.acme.mynetwork.Commodity')
    .then(function (assetRegistry) {
    return assetRegistry.update(trade.commodity);
    });
    }

    This function simply changes the owner property on a commodity based on the newOwner property on an incoming Trade transaction. It then persists the modified Commodity back into the asset registry, used to store Commodity instances.

Step Six: Access control

Access control files define the access control rules for business networks. Our network is simple, so the default access control file doesn't need editing. The basic file gives the current participant networkAdmin full access to business network and system-level operations.

While you can have multiple model or script files, you can only have one access control file in any business network.

For more information on access control files, check our documentation.

Step Seven: Deploying the updated business network

Now that we have model, script, and access control files, we need to deploy and test our business network.

Click Update to deploy the changes to our business network.

Step Eight: Testing the business network definition

Next, we need to test our business network by creating some participants (in this case Traders), creating an asset (a Commodity), and then using our Trade transaction to change the ownership of the Commodity.

Click the Test tab to get started.

Step Nine: Creating participants

The first thing we should add to our business network is two participants.

  1. Ensure that you have the Trader tab selected on the left, and click Create New Participant in the upper right.

  2. What you can see is the data structure of a Trader participant. We want some easily recognizable data, so delete the code that's there and paste the following:

    {
    "$class": "org.acme.mynetwork.Trader",
    "tradeId": "TRADER1",
    "firstName": "Jenny",
    "lastName": "Jones"
    }
  3. Click Create New to create the participant.

  4. You should be able to see the new Trader participant you've created. We need another Trader to test our Tradetransaction though, so create another Trader, but this time, use the following data:

    {
    "$class": "org.acme.mynetwork.Trader",
    "tradeId": "TRADER2",
    "firstName": "Amy",
    "lastName": "Williams"
    }

Make sure that both participants exist in the Trader view before moving on!

Step Ten: Creating an asset

Now that we have two Trader participants, we need something for them to trade. Creating an asset is very similar to creating a participant. The Commodity we're creating will have an owner property indicating that it belongs to the Trader with the tradeId of TRADER1.

  1. Click the Commodity tab under Assets and click Create New Asset.

  2. Delete the asset data and replace it with the following:

    {
    "$class": "org.acme.mynetwork.Commodity",
    "tradingSymbol": "ABC",
    "description": "Test commodity",
    "mainExchange": "Euronext",
    "quantity": 72.297,
    "owner": "resource:org.acme.mynetwork.Trader#TRADER1"
    }
  3. After creating this asset, you should be able to see it in the Commodity tab.

Step Eleven: Transferring the commodity between the participants

Now that we have two Traders and a Commodity to trade between them, we can test our Trade transaction.

Transactions are the basis of all change in a IBM Blockchain Platform: Develop business network, if you want to experiment with your own after this tutorial, try creating another business network from the My Business Networkscreen and using a more advanced business network template.

To test the Trade transaction:

  1. Click the Submit Transaction button on the left.

  2. Ensure that the transaction type is Trade.

  3. Replace the transaction data with the following, or just change the details:

    {
    "$class": "org.acme.mynetwork.Trade",
    "commodity": "resource:org.acme.mynetwork.Commodity#ABC",
    "newOwner": "resource:org.acme.mynetwork.Trader#TRADER2"
    }
  4. Click Submit.

  5. Check that our asset has changed ownership from TRADER1 to TRADER2, by expanding the data section for the asset. You should see that the owner is listed as resource:org.acme.mynetwork.Trader#TRADER2.

  6. To view the full transaction history of our business network, click All Transactions on the left. Here is a list of each transaction as they were submitted. You can see that certain actions we performed using the UI, like creating the Trader participants and the Commodity asset, are recorded as transactions, even though they're not defined as transactions in our business network model. These transactions are known as 'System Transactions' and are common to all business networks, and defined in the IBM Blockchain Platform: Develop Runtime.

Logging out of the business network

Now that transactions have successfully run, we should log out of the business network, ending up at the My Business Network screen where we started.

  1. In the upper-right of the screen is a button labelled admin. This lists your current identity, to log out, click adminto open the dropdown menu, and click My Business Networks.

What next?

You've completed the initial IBM Blockchain Platform: Develop Playground tutorial, you might want to either begin building your own business network using our other samples or templates.

You might want to try the Developer Tutorial, to get your local development environment setup, generate a REST API and a skeleton web application.

Or you can run IBM Blockchain Platform: Develop Playground locally connected to a real instance of Hyperledger Fabric.

Playground Tutorial的更多相关文章

  1. blockchain notes

    1. IBM blockchain platform https://www.ibm.com/blockchain/platform/ 2. 开源项目hyperledger https://hyper ...

  2. The IBM Blockchain Platform:Installing the development environment

    Follow these instructions to obtain the IBM Blockchain Platform: Develop development tools (primaril ...

  3. ReactiveCocoa Tutorial

    ReactiveCocoa Tutorial – The Definitive Introduction: Part 1/2 ReactiveCocoa教程——明确的介绍:第一部分(共两部分) As ...

  4. [翻译+山寨]Hangfire Highlighter Tutorial

    前言 Hangfire是一个开源且商业免费使用的工具函数库.可以让你非常容易地在ASP.NET应用(也可以不在ASP.NET应用)中执行多种类型的后台任务,而无需自行定制开发和管理基于Windows ...

  5. Django 1.7 Tutorial 学习笔记

    官方教程在这里 : Here 写在前面的废话:)) 以前学习新东西,第一想到的是找本入门教程,按照书上做一遍.现在看了各种网上的入门教程后,我觉得还是看官方Tutorial靠谱.书的弊端一说一大推 本 ...

  6. thrift 服务端linux C ++ 与客户端 windows python 环境配置(thrift 自带tutorial为例)

    关于Thrift文档化的确是做的不好.摸索了很久才终于把跨linux与windows跨C++与python语言的配置成功完成.以下是步骤: 1)                 Linux下环境配置 ...

  7. 窥探Swift编程之在Playground上尽情的玩耍

    自从苹果公司发布Swift的时候,Xcode上又多了一样新的东西---"Playground".Playground就像操场一样,可以供我们在代码的世界里尽情的玩耍,在本篇博客中就 ...

  8. Hive Tutorial(上)(Hive 入门指导)

    用户指导 Hive 指导 Hive指导 概念 Hive是什么 Hive不是什么 获得和开始 数据单元 类型系统 内置操作符和方法 语言性能 用法和例子(在<下>里面) 概念 Hive是什么 ...

  9. Home / Python MySQL Tutorial / Calling MySQL Stored Procedures in Python Calling MySQL Stored Procedures in Python

    f you are not familiar with MySQL stored procedures or want to review it as a refresher, you can fol ...

随机推荐

  1. 天下文章一大抄 之 修改excel 创建时间

    Sub ChangeDate()ThisWorkbook.BuiltinDocumentProperties("Creation Date") = #2 28 2016 13:25 ...

  2. HTML--比较实用的小例子

    常用的前端实例: 1略 2.在网页商城中的图片当我们把鼠标放上去之后,图片会显示一个有颜色的外边框,图片某一部分的字体的颜色并发生改变 鼠标放上去之前 鼠标放上去之后: 实现的代码: <!DOC ...

  3. nfs 挂载错误

    [ 147.080000] svc: failed to register lockdv1 RPC service (errno 146). [ 147.090000] lockd_up: makes ...

  4. 使用外部 toolchain 编译 openwrt

    默认编译 openwrt 时会先编译一套 toolchain. 这个步骤耗时较长. 使用外部 toolchain 可以多个 project 共用一套 toolchain , 而且也不重再编译它了. 省 ...

  5. Mysql性能优化笔记

    一,索引 1.Innodb索引使用的是B+树 2.尽量简化where条件,比如不要出现 where id + 3 = 5,这无法使用索引 3.索引很大时,可以冗余一列来模拟哈希索引 4.小的表不需要使 ...

  6. jvm 调优(1)概念

    数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:他代表的值就是数值本身:而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对象本身, ...

  7. FLTK 简介

          FLTK,如同其名字所表达的:The Fast Light Tool Kit,一个轻量级的GUI开发库.但这轻量级并不代表功能的羸弱,相反,FLTK在具有基本的GUI功能之外,还拥有一些特 ...

  8. (30)java web的hibernate使用-c3p0连接池配置

    hibernate支持c3p0连接池 需要导入c3p0的jar包 <!-- 配置连接驱动管理类 --> <property name="hibernate.connecti ...

  9. IE9不能直接引用Console

    问题: 公司有个项目,功能很简单,读取业务数据,展示在页面上. 一个很简单的问题,却因为目标浏览器是IE9,卡了三天. 前端给的反馈是: 在IE9下,程序一会儿对,一会儿不对--第一次刷不出来,多刷几 ...

  10. 请问snmp到底是干啥的。

    这个事情分两方面来说:首先是路由器这部分.路由器开启SNMP功能之后,它能够对自己的每个接口上的流量有一个统计,当然统计的不单单只有流量.然后路由器把统计到的内容按一定的格式保存起来.这个格式是大家都 ...