在计算机上使用 Docker 运行 Playground
纯浏览器模式,使用docker安装
终端执行
docker run --name composer-playground --publish 8080:8080 hyperledger/composer-playground
latest: Pulling from hyperledger/composer-playground
4fe2ade4980c: Already exists
0ade4f5bae45: Pull complete
fd1dceaf77f3: Pull complete
3af60a5c027e: Pull complete
Digest: sha256:a49fbdcbb90dce6a708c866cc81f2966e8f0435c2a1c20ba89b35d1b82d131fb
Status: Downloaded newer image for hyperledger/composer-playground:latest
2018-12-19T02:29:32: PM2 log: Launching in no daemon mode
2018-12-19T02:29:32: PM2 log: App [composer-playground:0] starting in -fork mode-
2018-12-19T02:29:32: PM2 log: App [composer-playground:0] online
WARNING: NODE_APP_INSTANCE value of '0' did not match any instance config file names.
WARNING: See https://github.com/lorenwest/node-config/wiki/Strict-Mode
2018-12-19T02:29:34.008Z INFO :LoadModule :loadModule() Loading composer-wallet-filesystem from /home/composer/.npm-global/lib/node_modules/composer-playground/node_modules/composer-wallet-filesystem {}$
2018-12-19T02:29:34.034Z INFO :PlaygroundAPI :createServer() Playground API started on port 8080 {}$
启动成功后,访问:http://127.0.0.1:8080

点击 “Let's Blockchain”
创建一个空的测试网络

修改网络名称为:test-network

选择一个空的网络模型,然后完成

连接网络

添加文件

新增一个模型文件:


源码为:
/**
* New model file
*/
namespace org.acme.myfirstmodel
asset Test identified by testId {
o String testId
o String message
}
transaction Hello {
--> Test test
}
再次添加一个Script File:

源码为:
/**
* New script file
*/
/**
* 以下注解是必须的
*/
/**
@param {org.acme.myfirstmodel.Hello} hello
@transaction
*/
function hello(hello){
console.log("Hello: " + hello.test.message);
}
发布:

发布完成后,我们切换到“Test”标签,进行模型的测试:

创建一个资产:

修改testId和message,然后保存:

打开chrome浏览器的开发者调试窗口(WIN:F12),切换到Console标签:

提交测试交易:

测试成功:

测试完成后,需要清空chrome的缓存,才能重新开始:

其余部分,可跟随IBM教程完成。
网友评论