From dc07ab50d0ab571287cc6723b5f36f54807a7844 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 21 May 2020 23:36:19 -0700 Subject: [PATCH 01/14] add simple flow Readme --- README_simpleflow.md | 91 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 README_simpleflow.md diff --git a/README_simpleflow.md b/README_simpleflow.md new file mode 100644 index 00000000..21f8def4 --- /dev/null +++ b/README_simpleflow.md @@ -0,0 +1,91 @@ + +# ocean-lib + +`ocean-lib-js` is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can: +* **Publish** data services: static data, streaming data, or compute-to-data. Every data service gets its own [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) token. +* **Mint** data tokens for a given data service +* **Transfer** data tokens to another owner +* **Consume** data tokens, to access the service + +`ocean-lib-js` is part of the [Ocean Protocol](www.oceanprotocol.com) toolset. + +# Installation +``` +// ES6 +import { Ocean, Logger } from '@oceanprotocol/lib' + +// ES2015 +const { Ocean, Logger } = require('@oceanprotocol/lib') + +``` + +# Quickstart + +This section describes a flow with the simplest transfer of value, for static data. + +Here's the steps. +1. Alice publishes a dataset (= publishes a datatoken contract) +1. Alice mints 100 tokens +1. Alice transfers 1 token to Bob +1. Bob consumes dataset + +Let's go through each of these in detail. + + +## 1. Alice publishes a dataset (= publishes a datatoken contract) + +For now, you're Alice:) Let's proceed. + + +```javascript +const { Ocean, Logger } = require('@oceanprotocol/lib') +//you can use default ABIs or use custom ones +//you can use default factoryAddress or use default one, depending on the network (auto-determined) +const ocean = Ocean(rpc_url='https://pacific.oceanprotocol.com',factoryABI=Ocean.factoryABI,dataTokenABI=Ocean.dataTokenABI,factoryAddress='0x123',web3Provider: web3) + +const accounts = await ocean.accounts.list() +erc20_address = ocean.datatokens.deployNewDT(publisher_service_url='123.com',account[0]) +``` + +## 2. Alice mints 100 tokens + +```javascript +const dataToken=Ocean.datatokens.loadContract(erc20_address) +dataToken.mint(100,account[0]) +``` + +## 3. Alice transfers 1 token to Bob + +```javascript +//transfer amount to destination using account +dataToken.transfer(1,bob_address, account[0]) +``` + +## 4. Bob consumes dataset + +Now, we are Bob :) + +```javascript +const ocean = Ocean(rpc_url='https://pacific.oceanprotocol.com',factoryABI=Ocean.factoryABI,dataTokenABI=Ocean.dataTokenABI,factoryAddress='0x123',web3Provider: web3) + +const accounts = await ocean.accounts.list() +const account=account[0] + +const asset=ocean.assets.loadFromDataToken(erc20_address) + +const file=asset.download() + +``` +where +```javascript +class assets{ + async function download(asset){ + const publisher = Ocean.publisher.loadFromERC20(ERC20address) + const transaction = publisher.prepare(asset.ERC20address) + await account.signTransaction(transaction) + const file=await publisher.download(asset.ERC20address) + return file + } +} +``` + From 15b010b0de525522b2014b85cf1584297865e1ca Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 21 May 2020 23:39:00 -0700 Subject: [PATCH 02/14] fix --- README_simpleflow.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index 21f8def4..4fd89f54 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -73,13 +73,13 @@ const account=account[0] const asset=ocean.assets.loadFromDataToken(erc20_address) -const file=asset.download() +const file=asset.download(account) ``` where ```javascript class assets{ - async function download(asset){ + async function download(account){ const publisher = Ocean.publisher.loadFromERC20(ERC20address) const transaction = publisher.prepare(asset.ERC20address) await account.signTransaction(transaction) From 7f967e7d0f854ba604e82b8948238d77eb48d265 Mon Sep 17 00:00:00 2001 From: alexcos20 Date: Thu, 21 May 2020 23:47:04 -0700 Subject: [PATCH 03/14] fix --- README_simpleflow.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index 4fd89f54..cadca62f 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -63,7 +63,7 @@ dataToken.transfer(1,bob_address, account[0]) ## 4. Bob consumes dataset -Now, we are Bob :) +Now, you are Bob :) ```javascript const ocean = Ocean(rpc_url='https://pacific.oceanprotocol.com',factoryABI=Ocean.factoryABI,dataTokenABI=Ocean.dataTokenABI,factoryAddress='0x123',web3Provider: web3) @@ -79,13 +79,20 @@ const file=asset.download(account) where ```javascript class assets{ + let ERC20address; + + function loadFromDataToken(erc20_address){ + this.ERC20address=erc20_address + } + async function download(account){ - const publisher = Ocean.publisher.loadFromERC20(ERC20address) - const transaction = publisher.prepare(asset.ERC20address) + const publisher = Ocean.publisher.loadFromERC20(this.ERC20address) + const transaction = publisher.prepare(this.ERC20address) await account.signTransaction(transaction) - const file=await publisher.download(asset.ERC20address) + const file=await publisher.download(this.ERC20address) return file } } ``` +Disclaimer: this is a logical flow only \ No newline at end of file From 22e769e1092d1b4ed2e9a4a3b0a9bbc5077d5304 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 11:47:34 +0300 Subject: [PATCH 04/14] Update README_simpleflow.md --- README_simpleflow.md | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index cadca62f..cfb13e7f 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -39,26 +39,25 @@ For now, you're Alice:) Let's proceed. ```javascript const { Ocean, Logger } = require('@oceanprotocol/lib') -//you can use default ABIs or use custom ones -//you can use default factoryAddress or use default one, depending on the network (auto-determined) -const ocean = Ocean(rpc_url='https://pacific.oceanprotocol.com',factoryABI=Ocean.factoryABI,dataTokenABI=Ocean.dataTokenABI,factoryAddress='0x123',web3Provider: web3) - -const accounts = await ocean.accounts.list() -erc20_address = ocean.datatokens.deployNewDT(publisher_service_url='123.com',account[0]) +const config={ + network: 'rinkeby', + privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' +} +const ocean = Ocean(config) +const account = await ocean.accounts.list()[0] +const myToken = ocean.datatoken.create('123.com',account) ``` ## 2. Alice mints 100 tokens ```javascript -const dataToken=Ocean.datatokens.loadContract(erc20_address) -dataToken.mint(100,account[0]) +myToken.mint(100) ``` ## 3. Alice transfers 1 token to Bob ```javascript -//transfer amount to destination using account -dataToken.transfer(1,bob_address, account[0]) +myToken.transfer(1,BobAddress) ``` ## 4. Bob consumes dataset @@ -66,14 +65,18 @@ dataToken.transfer(1,bob_address, account[0]) Now, you are Bob :) ```javascript -const ocean = Ocean(rpc_url='https://pacific.oceanprotocol.com',factoryABI=Ocean.factoryABI,dataTokenABI=Ocean.dataTokenABI,factoryAddress='0x123',web3Provider: web3) -const accounts = await ocean.accounts.list() -const account=account[0] +const config={ + network: 'rinkeby', + privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' +} +const ocean = Ocean(config) -const asset=ocean.assets.loadFromDataToken(erc20_address) -const file=asset.download(account) +const account = await ocean.accounts.list()[0] +const myToken = ocean.datatoken.load(erc20_address) +const asset=ocean.assets.loadFromDataToken(myToken) +const file=ocean.assets.download(asset,account) ``` where @@ -95,4 +98,4 @@ class assets{ } ``` -Disclaimer: this is a logical flow only \ No newline at end of file +Disclaimer: this is a logical flow only From f0eabe3c0ffc35edbc3a2941417777e6debf22f3 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 12:16:55 +0300 Subject: [PATCH 05/14] Update README_simpleflow.md --- README_simpleflow.md | 63 ++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index cfb13e7f..7978b796 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -41,61 +41,62 @@ For now, you're Alice:) Let's proceed. const { Ocean, Logger } = require('@oceanprotocol/lib') const config={ network: 'rinkeby', - privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' + privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f', + providerUri: 'localhost:8030' //this is the provider URL } -const ocean = Ocean(config) +const ocean = Ocean(alice_config) const account = await ocean.accounts.list()[0] -const myToken = ocean.datatoken.create('123.com',account) +const myToken = ocean.datatoken.create('localhost:8030',account) +console.log(myToken.getAddress()) ``` -## 2. Alice mints 100 tokens +## 2.Alice hosts a dataset + +A locally providerService is required, which will serve just one file for this demo. +Let's create the file to be shared: +``` +touch /var/mydata/myFolder1/file +```` + +Run the providerService: +(given that ERC20 contract address from the above is 0x1234) + +``` +ENV DT="{'0x1234':'/var/mydata/myFolder1'}" +docker run @oceanprotocol/provider-py -e CONFIG=DT +``` + + +## 3. Alice mints 100 tokens ```javascript myToken.mint(100) ``` -## 3. Alice transfers 1 token to Bob +## 4. Alice transfers 1 token to Bob ```javascript myToken.transfer(1,BobAddress) ``` -## 4. Bob consumes dataset +## 5. Bob consumes dataset Now, you are Bob :) +Given then the provider serves only one file, it will serve the same file for any ERC20 DT ```javascript -const config={ +const bob_config={ network: 'rinkeby', - privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' + privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' } -const ocean = Ocean(config) +const bob_ocean = Ocean(bob_config) -const account = await ocean.accounts.list()[0] -const myToken = ocean.datatoken.load(erc20_address) -const asset=ocean.assets.loadFromDataToken(myToken) -const file=ocean.assets.download(asset,account) +const account = await bob_ocean.accounts.list()[0] +const asset=bob_ocean.assets.load(dt_address) +const file=bob_ocean.assets.download(asset,account) ``` -where -```javascript -class assets{ - let ERC20address; - - function loadFromDataToken(erc20_address){ - this.ERC20address=erc20_address - } - async function download(account){ - const publisher = Ocean.publisher.loadFromERC20(this.ERC20address) - const transaction = publisher.prepare(this.ERC20address) - await account.signTransaction(transaction) - const file=await publisher.download(this.ERC20address) - return file - } -} -``` -Disclaimer: this is a logical flow only From 73660957402ed2a9ee20e11824349b0c847efffe Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 12:18:17 +0300 Subject: [PATCH 06/14] Update README_simpleflow.md --- README_simpleflow.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index 7978b796..0b1dc4af 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -47,10 +47,11 @@ const config={ const ocean = Ocean(alice_config) const account = await ocean.accounts.list()[0] const myToken = ocean.datatoken.create('localhost:8030',account) -console.log(myToken.getAddress()) +const dt_address=myToken.getAddress() +console.log(dt_address) ``` -## 2.Alice hosts a dataset +## 2. Alice hosts the dataset A locally providerService is required, which will serve just one file for this demo. Let's create the file to be shared: @@ -82,7 +83,7 @@ myToken.transfer(1,BobAddress) ## 5. Bob consumes dataset Now, you are Bob :) -Given then the provider serves only one file, it will serve the same file for any ERC20 DT + ```javascript From 79f07846a6c14a846e94a964b34d5865fb703dfb Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 12:21:38 +0300 Subject: [PATCH 07/14] Update README_simpleflow.md --- README_simpleflow.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index 0b1dc4af..5302f987 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -95,8 +95,8 @@ const bob_ocean = Ocean(bob_config) const account = await bob_ocean.accounts.list()[0] -const asset=bob_ocean.assets.load(dt_address) -const file=bob_ocean.assets.download(asset,account) +const asset=bob_ocean.assets.get(dt_address) +const file=asset.download(account) ``` From 1b219e930a50c2a51fb13f0c8825b9636f3ec04a Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 12:54:11 +0300 Subject: [PATCH 08/14] Update README_simpleflow.md --- README_simpleflow.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index 5302f987..870c26fa 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -42,7 +42,6 @@ const { Ocean, Logger } = require('@oceanprotocol/lib') const config={ network: 'rinkeby', privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f', - providerUri: 'localhost:8030' //this is the provider URL } const ocean = Ocean(alice_config) const account = await ocean.accounts.list()[0] From 7d34106cdfc4f51eb27df36ccde16da6005307dc Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 12:59:12 +0300 Subject: [PATCH 09/14] Create README_marketplace_flow.md --- README_marketplace_flow.md | 102 +++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 README_marketplace_flow.md diff --git a/README_marketplace_flow.md b/README_marketplace_flow.md new file mode 100644 index 00000000..870c26fa --- /dev/null +++ b/README_marketplace_flow.md @@ -0,0 +1,102 @@ + +# ocean-lib + +`ocean-lib-js` is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can: +* **Publish** data services: static data, streaming data, or compute-to-data. Every data service gets its own [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) token. +* **Mint** data tokens for a given data service +* **Transfer** data tokens to another owner +* **Consume** data tokens, to access the service + +`ocean-lib-js` is part of the [Ocean Protocol](www.oceanprotocol.com) toolset. + +# Installation +``` +// ES6 +import { Ocean, Logger } from '@oceanprotocol/lib' + +// ES2015 +const { Ocean, Logger } = require('@oceanprotocol/lib') + +``` + +# Quickstart + +This section describes a flow with the simplest transfer of value, for static data. + +Here's the steps. +1. Alice publishes a dataset (= publishes a datatoken contract) +1. Alice mints 100 tokens +1. Alice transfers 1 token to Bob +1. Bob consumes dataset + +Let's go through each of these in detail. + + +## 1. Alice publishes a dataset (= publishes a datatoken contract) + +For now, you're Alice:) Let's proceed. + + +```javascript +const { Ocean, Logger } = require('@oceanprotocol/lib') +const config={ + network: 'rinkeby', + privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f', +} +const ocean = Ocean(alice_config) +const account = await ocean.accounts.list()[0] +const myToken = ocean.datatoken.create('localhost:8030',account) +const dt_address=myToken.getAddress() +console.log(dt_address) +``` + +## 2. Alice hosts the dataset + +A locally providerService is required, which will serve just one file for this demo. +Let's create the file to be shared: +``` +touch /var/mydata/myFolder1/file +```` + +Run the providerService: +(given that ERC20 contract address from the above is 0x1234) + +``` +ENV DT="{'0x1234':'/var/mydata/myFolder1'}" +docker run @oceanprotocol/provider-py -e CONFIG=DT +``` + + +## 3. Alice mints 100 tokens + +```javascript +myToken.mint(100) +``` + +## 4. Alice transfers 1 token to Bob + +```javascript +myToken.transfer(1,BobAddress) +``` + +## 5. Bob consumes dataset + +Now, you are Bob :) + + +```javascript + +const bob_config={ + network: 'rinkeby', + privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' +} +const bob_ocean = Ocean(bob_config) + + +const account = await bob_ocean.accounts.list()[0] +const asset=bob_ocean.assets.get(dt_address) +const file=asset.download(account) + +``` + + From d098d5d913bc4393ac24b1872743e1637f4f8596 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 14:26:30 +0300 Subject: [PATCH 10/14] Update README_simpleflow.md --- README_simpleflow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index 870c26fa..fb7473ab 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -94,7 +94,7 @@ const bob_ocean = Ocean(bob_config) const account = await bob_ocean.accounts.list()[0] -const asset=bob_ocean.assets.get(dt_address) +const asset=bob_ocean.assets.getFromDTAddress(dt_address) const file=asset.download(account) ``` From 8a3faecffeb8bac72f2483ad3838a5bd7743c74b Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 14:27:01 +0300 Subject: [PATCH 11/14] Update README_simpleflow.md --- README_simpleflow.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README_simpleflow.md b/README_simpleflow.md index fb7473ab..51f44b4a 100644 --- a/README_simpleflow.md +++ b/README_simpleflow.md @@ -94,7 +94,7 @@ const bob_ocean = Ocean(bob_config) const account = await bob_ocean.accounts.list()[0] -const asset=bob_ocean.assets.getFromDTAddress(dt_address) +const asset=bob_ocean.assets.getFromDTAddress(dt_address)[0] const file=asset.download(account) ``` From 9a5fdb458ebbbbcff8a0eeb42957f86ca3b57799 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 14:31:39 +0300 Subject: [PATCH 12/14] Update README_marketplace_flow.md --- README_marketplace_flow.md | 121 +++++++++++++++++++++++++++++-------- 1 file changed, 97 insertions(+), 24 deletions(-) diff --git a/README_marketplace_flow.md b/README_marketplace_flow.md index 870c26fa..eafd8028 100644 --- a/README_marketplace_flow.md +++ b/README_marketplace_flow.md @@ -1,6 +1,23 @@ + Alice -> Alice: create new ID + Alice -> Alice: define PublisherService in DDO + Alice -> Alice : initialize MetaData with services + Alice -> Library: publish asset + Library -> Provider: get ID for URL + Provider -> Library : URL + Library -> Alice: sign DeployDToken transaction + Alice -> Library: sign DeployDToken + Library -> contracts: DeployDToken(blob) + contracts -> Library : Deployed: (0x12345) + Library -> Library: update MetaData ERC20 with DT address +else import MetaData + Alice -> Library: import MetaData + + + # ocean-lib + `ocean-lib-js` is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can: * **Publish** data services: static data, streaming data, or compute-to-data. Every data service gets its own [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) token. * **Mint** data tokens for a given data service @@ -21,7 +38,7 @@ const { Ocean, Logger } = require('@oceanprotocol/lib') # Quickstart -This section describes a flow with the simplest transfer of value, for static data. +This section describes a marketplace flow with multiple services Here's the steps. 1. Alice publishes a dataset (= publishes a datatoken contract) @@ -32,39 +49,64 @@ Here's the steps. Let's go through each of these in detail. -## 1. Alice publishes a dataset (= publishes a datatoken contract) +## 1. Alice hosts the dataset + +A locally providerService ,metadatastore and marketplace are required: + +Run the providerService and metadatastore: +``` +docker run @oceanprotocol/provider-py:latest +docker run @oceanprotocol/aquarius:latest +docker run @oceanprotocol/marketplace:latest +``` + + +## 2. Alice publishes a dataset (= publishes a datatoken contract) For now, you're Alice:) Let's proceed. ```javascript const { Ocean, Logger } = require('@oceanprotocol/lib') + +const marketPlaceAddress='0x9876' +//Alice's config const config={ network: 'rinkeby', privateKey:'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f', + metadataStoreURI: 'localhost:5000', + providerUri: 'localhost:8030' } const ocean = Ocean(alice_config) const account = await ocean.accounts.list()[0] -const myToken = ocean.datatoken.create('localhost:8030',account) + + +const myToken = ocean.datatoken.create(config.metadataStoreURI,account) +//Alice allows MarketPlace to transfer 20 DT +myToken.approve(marketPlaceAddress,20) + const dt_address=myToken.getAddress() -console.log(dt_address) + +//create asset 1 +const metaData={ + "did":"did:op:1234", + "owner":"0xaaaaa", + "dtAddress":dt_address, + "name":"Asset1", + "services="[ + { "id":0, "serviceEndpoint":"providerUri", "type":"download", "dtCost":10, "timeout":0, + "files":[{"url":"http://example.net"},{"url":"http://example.com" }] + }, + { "id":1, "type":"compute", "serviceEndpoint":"providerUri", "dtCost":1,"timeout":3600}, + { "id":2, "type":"compute", "serviceEndpoint":"providerUri", "dtCost":2, "timeout":7200 }, + ] +} +//create will encrypt the URLs using publisher and update the ddo before pushing to aquarius +//create will require that metaData.dtAddress is a valid DT Contract address +const asset = ocean.assets.create(metaData,account) +const did = asset.did ``` -## 2. Alice hosts the dataset - -A locally providerService is required, which will serve just one file for this demo. -Let's create the file to be shared: -``` -touch /var/mydata/myFolder1/file -```` - -Run the providerService: -(given that ERC20 contract address from the above is 0x1234) - -``` -ENV DT="{'0x1234':'/var/mydata/myFolder1'}" -docker run @oceanprotocol/provider-py -e CONFIG=DT -``` ## 3. Alice mints 100 tokens @@ -73,10 +115,28 @@ docker run @oceanprotocol/provider-py -e CONFIG=DT myToken.mint(100) ``` -## 4. Alice transfers 1 token to Bob +## 4. Exchange of value : How Bob gets DT +``` + +const bob_config={ + network: 'rinkeby', + privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' + marketPlaceUri: 'localhost:3000' +} +const bob_ocean = Ocean(bob_config) +const bob_account = await bob_ocean.accounts.list()[0] + +const asset = ocean.assets.resolve(did) +const serviceIndex = assets.findServiceByType('compute') +const num_dt_needed = assets.getDtCost(serviceIndex) +//Bob need to buy num_dt_needed . DTAddress = asset.dtAddress + +const {price, currency } = ocean.marketplace.getPrice(num_dt_needed,asset.dtAddress) +bob_account.approve(price, currency, marketPlaceAddress) +ocean.marketplace.buy(num_dt_needed,asset.dtAddress) + + -```javascript -myToken.transfer(1,BobAddress) ``` ## 5. Bob consumes dataset @@ -94,8 +154,21 @@ const bob_ocean = Ocean(bob_config) const account = await bob_ocean.accounts.list()[0] -const asset=bob_ocean.assets.get(dt_address) -const file=asset.download(account) +const asset = ocean.assets.getFromDID(did) +const serviceIndex = assets.findServiceByType('compute') + +export const rawAlgoMeta = { + rawcode: `console.log('Hello world'!)`, + format: 'docker-image', + version: '0.1', + container: { + entrypoint: 'node $ALGO', + image: 'node', + tag: '10' + } +} + +const computeJob=asset.StartCompute(serviceIndex, rawAlgoMeta, account) ``` From 061ee0e707f7cfd75d45dea2fb92065b7ecfc906 Mon Sep 17 00:00:00 2001 From: Alex Coseru Date: Fri, 22 May 2020 14:31:58 +0300 Subject: [PATCH 13/14] Update README_marketplace_flow.md --- README_marketplace_flow.md | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/README_marketplace_flow.md b/README_marketplace_flow.md index eafd8028..78e7eba8 100644 --- a/README_marketplace_flow.md +++ b/README_marketplace_flow.md @@ -1,21 +1,4 @@ - Alice -> Alice: create new ID - Alice -> Alice: define PublisherService in DDO - Alice -> Alice : initialize MetaData with services - Alice -> Library: publish asset - Library -> Provider: get ID for URL - Provider -> Library : URL - Library -> Alice: sign DeployDToken transaction - Alice -> Library: sign DeployDToken - Library -> contracts: DeployDToken(blob) - contracts -> Library : Deployed: (0x12345) - Library -> Library: update MetaData ERC20 with DT address -else import MetaData - Alice -> Library: import MetaData - - - - -# ocean-lib + # ocean-lib `ocean-lib-js` is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can: From 2e53c7d2a4a31564470c872d558ba8a5c6e36d5f Mon Sep 17 00:00:00 2001 From: Ahmed Date: Fri, 22 May 2020 13:37:47 +0200 Subject: [PATCH 14/14] minor rendering fix --- README_marketplace_flow.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README_marketplace_flow.md b/README_marketplace_flow.md index 78e7eba8..725da0bf 100644 --- a/README_marketplace_flow.md +++ b/README_marketplace_flow.md @@ -99,8 +99,7 @@ myToken.mint(100) ``` ## 4. Exchange of value : How Bob gets DT -``` - +```javascript const bob_config={ network: 'rinkeby', privateKey:'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f' @@ -117,9 +116,6 @@ const num_dt_needed = assets.getDtCost(serviceIndex) const {price, currency } = ocean.marketplace.getPrice(num_dt_needed,asset.dtAddress) bob_account.approve(price, currency, marketPlaceAddress) ocean.marketplace.buy(num_dt_needed,asset.dtAddress) - - - ``` ## 5. Bob consumes dataset