@oceanprotocol/lib 1.0.0-next.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/CHANGELOG.md +390 -1
  2. package/CodeExamples.md +918 -0
  3. package/README.md +12 -80
  4. package/dist/lib.js +1 -1
  5. package/dist/lib.js.map +1 -1
  6. package/dist/lib.modern.js +1 -1
  7. package/dist/lib.modern.js.map +1 -1
  8. package/dist/lib.module.js +1 -1
  9. package/dist/lib.module.js.map +1 -1
  10. package/dist/lib.umd.js +1 -1
  11. package/dist/lib.umd.js.map +1 -1
  12. package/dist/src/@types/Asset.d.ts +83 -0
  13. package/dist/src/@types/Compute.d.ts +18 -1
  14. package/dist/src/@types/DDO/DDO.d.ts +43 -0
  15. package/dist/src/@types/DDO/Event.d.ts +20 -0
  16. package/dist/src/@types/DDO/Metadata.d.ts +92 -0
  17. package/dist/src/@types/DDO/Service.d.ts +72 -6
  18. package/dist/src/{interfaces/DispenserInterface.d.ts → @types/Dispenser.d.ts} +0 -0
  19. package/dist/src/@types/Erc20.d.ts +21 -0
  20. package/dist/src/{interfaces/Erc721Interface.d.ts → @types/Erc721.d.ts} +2 -2
  21. package/dist/src/@types/FileMetadata.d.ts +29 -0
  22. package/dist/src/{interfaces/FixedRateInterface.d.ts → @types/FixedPrice.d.ts} +7 -1
  23. package/dist/src/{interfaces/PoolInterface.d.ts → @types/Pool.d.ts} +11 -2
  24. package/dist/src/@types/Provider.d.ts +9 -0
  25. package/dist/src/@types/Router.d.ts +59 -0
  26. package/dist/src/@types/index.d.ts +6 -0
  27. package/dist/src/aquarius/Aquarius.d.ts +23 -1
  28. package/dist/src/factories/NFTFactory.d.ts +222 -14
  29. package/dist/src/index.d.ts +1 -1
  30. package/dist/src/models/Config.d.ts +128 -0
  31. package/dist/src/pools/Router.d.ts +189 -8
  32. package/dist/src/pools/balancer/Pool.d.ts +354 -29
  33. package/dist/src/pools/dispenser/Dispenser.d.ts +109 -2
  34. package/dist/src/pools/fixedRate/FixedRateExchange.d.ts +309 -17
  35. package/dist/src/pools/index.d.ts +2 -0
  36. package/dist/src/pools/ssContracts/SideStaking.d.ts +110 -7
  37. package/dist/src/provider/Provider.d.ts +125 -6
  38. package/dist/src/tokens/Datatoken.d.ts +347 -8
  39. package/dist/src/tokens/NFT.d.ts +297 -5
  40. package/dist/src/utils/ContractUtils.d.ts +13 -4
  41. package/dist/src/utils/DatatokenName.d.ts +4 -0
  42. package/dist/src/utils/General.d.ts +4 -0
  43. package/dist/src/utils/PoolHelpers.d.ts +8 -0
  44. package/dist/src/utils/SignatureUtils.d.ts +0 -2
  45. package/dist/src/utils/TokenUtils.d.ts +65 -3
  46. package/dist/src/utils/index.d.ts +2 -0
  47. package/dist/test/TestContractHandler.d.ts +8 -36
  48. package/dist/test/config.d.ts +5 -0
  49. package/dist/test/{unit/NftFactory.test.d.ts → integration/CodeExamples.test.d.ts} +0 -0
  50. package/dist/test/unit/factories/NftFactory.test.d.ts +1 -0
  51. package/package.json +37 -32
  52. package/dist/src/interfaces/Erc20Interface.d.ts +0 -11
  53. package/dist/src/interfaces/RouterInterface.d.ts +0 -12
  54. package/dist/src/interfaces/index.d.ts +0 -5
  55. package/dist/test/integration/config.d.ts +0 -3
  56. package/dist/test/unit/config.d.ts +0 -3
  57. package/docs/beginners_guide.md +0 -338
  58. package/docs/get-test-OCEAN.md +0 -24
  59. package/docs/overview.md +0 -394
  60. package/docs/quickstart_marketplace.md +0 -423
  61. package/docs/quickstart_simple.md +0 -272
  62. package/docs/services.md +0 -94
  63. package/docs/wallets.md +0 -98
@@ -1,423 +0,0 @@
1
- # Quickstart: Marketplace Flow
2
-
3
- This batteries-included flow includes metadata, multiple services for one datatoken, and compute-to-data.
4
-
5
- It focuses on Alice's experience as a publisher, and Bob's experience as a buyer & consumer. The rest are services used by Alice and Bob.
6
-
7
- Here's the steps.
8
-
9
- 1. Initialize services
10
- 2. Create a new node.js project
11
- 3. Install dependancies
12
- 4. Create a config file and update contract addresses
13
- 5. Publish a new datatoken
14
- 6. Mint 200 tokens
15
- 7. Publish a dataset
16
- 8. Alice allows marketplace to sell her datatokens
17
- 9. Marketplace withdraws Alice's datatokens from allowance
18
- 10. Marketplace posts asset for sale
19
- 11. Bob acquires datatokens (value swap)
20
- 12. Bob downloads the dataset
21
- 13. Extensions
22
-
23
- Let's go through each step.
24
-
25
- ## 1. Initialize services
26
-
27
- We start by initializing the services. To do this, we clone the Barge repository and run it. This will run the current default versions of [Aquarius](https://github.com/oceanprotocol/aquarius), [Provider](https://github.com/oceanprotocol/provider-py), and [Ganache](https://github.com/trufflesuite/ganache-cli) with [our contracts](https://github.com/oceanprotocol/ocean-contracts) deployed to it.
28
-
29
- ```bash
30
- git clone https://github.com/oceanprotocol/barge.git
31
- cd barge/
32
- ./start_ocean.sh --with-provider2 --no-dashboard
33
- ```
34
-
35
- ## 2. Create a new node.js project
36
-
37
- Start by creating a new Node.js project. Open a new terminal and enter the following commands:
38
-
39
- ```bash
40
- mkdir marketplace-quickstart
41
- cd marketplace-quickstart
42
- npm init
43
- # Answer the questions in the command line prompt
44
- cat > marketplace.js
45
- # On linux press CTRL + D to save
46
- ```
47
-
48
- ## 3. Install dependancies
49
-
50
- Open the package.json file in a text editor and update the dependancies to include the following:
51
-
52
- ```JSON
53
- "dependencies": {
54
- "@oceanprotocol/contracts": "^0.5.6",
55
- "@oceanprotocol/lib": "^0.6.5",
56
- "web3": "^1.3.0"
57
- }
58
- ```
59
-
60
- Now in your terminal run the following command:
61
-
62
- ```bash
63
- npm install
64
- ```
65
-
66
- ## 4. Create a config file and update contract addresses
67
-
68
- Create a new config.js file:
69
-
70
- ```bash
71
- cat > config.js
72
- ```
73
-
74
- Now open the config.js in your code editor and enter the following:
75
-
76
- ```Javascript
77
- const { ConfigHelper } = require("@oceanprotocol/lib");
78
- const Web3 = require("web3");
79
- const defaultConfig = new ConfigHelper().getConfig("development");
80
-
81
- const urls = {
82
- networkUrl: "http://localhost:8545",
83
- aquarius: "http://localhost:5000",
84
- providerUri: "http://localhost:8030",
85
- };
86
-
87
- const contracts = {
88
- "DTFactory": "0x_YOUR_DTFactory_ADDRESS_",
89
- "BFactory": "0x_YOUR_DTFactory_ADDRESS_",
90
- "FixedRateExchange": "0x_YOUR_DTFactory_ADDRESS_",
91
- "Metadata": "0x_YOUR_Metadata_ADDRESS_",
92
- "Ocean": "0x_YOUR_Ocean_ADDRESS_"
93
- };
94
-
95
- const config = {
96
- ...defaultConfig,
97
- metadataCacheUri: urls.aquarius,
98
- providerUri: urls.providerUri,
99
- web3Provider: new Web3(urls.networkUrl),
100
- };
101
-
102
- module.exports = {
103
- config,
104
- contracts,
105
- urls,
106
- };
107
-
108
- ```
109
-
110
- Now check what your contract addresses are locally. In your terminal run:
111
-
112
- ```bash
113
- cat ~/.ocean/ocean-contracts/artifacts/address.json
114
- ```
115
-
116
- Next, update the contract addresses in your config.js file. Replace each of the place holders with the actual addresses that were outputted into your terminal.
117
-
118
- ## 5. Publish a new datatoken
119
-
120
- Now open the `marketplace.js` file in your text editor. Enter the following code and save the file:
121
-
122
- ```Javascript
123
- const Web3 = require("web3");
124
- const { Ocean, Datatokens } = require("@oceanprotocol/lib");
125
-
126
- const { factoryABI } = require("@oceanprotocol/contracts/artifacts/contracts/DTFactory.json");
127
- const { datatokensABI } = require("@oceanprotocol/contracts/artifacts/contracts/DatatokenTemplate.json");
128
- const { config, contracts, urls } = require("./config");
129
-
130
-
131
-
132
- const init = async () => {
133
- const ocean = await Ocean.getInstance(config);
134
- const blob = `http://localhost:8030/api/v1/services/consume`;
135
-
136
- const accounts = await ocean.accounts.list();
137
- const alice = accounts[0].id;
138
- console.log('Alice account address:', alice)
139
-
140
- const datatoken = new Datatokens(
141
- contracts.DTFactory,
142
- factoryABI,
143
- datatokensABI,
144
- new Web3(urls.networkUrl)
145
- );
146
- const tokenAddress = await datatoken.create(blob, alice);
147
- console.log(`Deployed datatoken address: ${tokenAddress}`);
148
- };
149
-
150
- init();
151
- ```
152
-
153
- Now in your terminal, run the following command:
154
-
155
- ```bash
156
- node marketplace.js
157
- ```
158
-
159
- Congratulations, you've created your first Ocean datatoken! 🌊🐋
160
-
161
- ## 6. Mint 200 tokens
162
-
163
- Next, we will edit the code in `marketplace.js` to mint 200 datatokens. These 200 datatokens are minted and sent to Alice's Address.
164
-
165
- At the end of the `init() { ... }` function (after `console.log('Deployed datatoken address: ${tokenAddress}')`) add the following line of code:
166
-
167
- ```Javascript
168
- await datatoken.mint(tokenAddress, alice, '200', alice)
169
- let aliceBalance = await datatoken.balance(tokenAddress, alice)
170
- console.log('Alice token balance:', aliceBalance)
171
- ```
172
-
173
- Now run the `marketplace.js` file again:
174
-
175
- ```bash
176
- node marketplace.js
177
- ```
178
-
179
- You should now see in the console output that Alice has a token balance of 200.
180
-
181
- ## 7. Publish a dataset
182
-
183
- Create a new file called data.js. In your terminal enter these commands:
184
-
185
- ```Bash
186
- cat > data.js
187
- ```
188
-
189
- Open the data.js file in your text editor. Enter the following code and save the file:
190
-
191
- ```Javascript
192
- const testData = {
193
- main: {
194
- type: "dataset",
195
- name: "test-dataset",
196
- dateCreated: new Date(Date.now()).toISOString().split(".")[0] + "Z",
197
- author: "test",
198
- license: "MIT",
199
- files: [
200
- {
201
- url:
202
- "https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_10.xls",
203
- contentType: "xlsx",
204
- },
205
- ],
206
- },
207
- };
208
-
209
- module.exports = { testData };
210
- ```
211
-
212
- Now, in your `marketplace.js` file import the test data. Add the following line of code at the top of the file under the other `require()` statements:
213
-
214
- ```Javascript
215
- const { testData } = require("./data");
216
- ```
217
-
218
- At the end of the `init() { ... }` function (after `console.log('Bob token balance:', bobBalance)`) add the following code:
219
-
220
- ```Javascript
221
- dataService = await ocean.assets.createAccessServiceAttributes(
222
- accounts[0],
223
- 10, // set the price in datatoken
224
- new Date(Date.now()).toISOString().split(".")[0] + "Z", // publishedDate
225
- 0 // timeout
226
- );
227
-
228
- // publish asset
229
- const createData = await ocean.assets.create(
230
- testData,
231
- accounts[0],
232
- [dataService],
233
- tokenAddress
234
- );
235
-
236
- const dataId = createData.id;
237
- console.log('Data ID:', dataId);
238
- ```
239
-
240
- Now save and run the `marketplace.js` file:
241
-
242
- ```Bash
243
- node marketplace.js
244
- ```
245
-
246
- In the terminal output you should now see the Data ID (did) outputed.
247
-
248
- Congratulations, you have published your first dataset! 🌊🐠
249
-
250
- ## 8. Alice allows marketplace to sell her datatokens
251
-
252
- On the line after `const alice = accounts[0].id` add the following code:
253
-
254
- ```Javascript
255
- const marketplace = accounts[1].id;
256
- console.log('Marketplace account address:', marketplace);
257
- ```
258
-
259
- At the end of the `init() { ... }` function (after `console.log('Data ID:', dataId)`) add the following code:
260
-
261
- ```Javascript
262
- await datatoken.approve(
263
- tokenAddress,
264
- marketplace, // marketplace address,
265
- '100', // marketplaceAllowance
266
- alice
267
- )
268
-
269
- const marketplaceAllowance = await datatoken.allowance(
270
- tokenAddress,
271
- alice,
272
- marketplace, // marketplace address,
273
- );
274
-
275
- console.log("Marketplace Allowance:", marketplaceAllowance);
276
- ```
277
-
278
- You should see in the terminal output that the marketplace has a datatoken allowance of 100 tokens.
279
-
280
- Now save the file and run it:
281
-
282
- ```Bash
283
- node marketplace.js
284
- ```
285
-
286
- You should see in the terminal output that the marketplace has an allowance of 100 datatokens.
287
-
288
- ## 9. Marketplace withdraws Alice's datatokens from allowance
289
-
290
- Now, you're the marketplace :) At the end of the `init() { ... }` function (after `console.log("Marketplace Allowance:", marketplaceAllowance)`) add the following code:
291
-
292
- ```Javascript
293
- await datatoken.transferFrom(tokenAddress, alice, '100', marketplace)
294
- const marketplaceBalance = await datatoken.balance(tokenAddress, marketplace)
295
- aliceBalance = await datatoken.balance(tokenAddress, alice)
296
-
297
- console.log("Marketplace balance:", marketplaceBalance)
298
- console.log("Alice balance:", aliceBalance)
299
- ```
300
-
301
- Now save and run the file:
302
-
303
- ```Bash
304
- node marketplace.js
305
- ```
306
-
307
- You should see in the terminal output that the Markeplace now has a datatoken balance of 100 and Alice now has a balance of 100.
308
-
309
- ## 10. Marketplace posts asset for sale
310
-
311
- In this section we show how the maketplace can post the dataset for sale.
312
-
313
- First, in the same terminal that you are running your files, enter the following command:
314
-
315
- ```bash
316
- export ADDRESS_FILE="${HOME}/.ocean/ocean-contracts/artifacts/address.json"
317
- ```
318
-
319
- This tells ocean.js the location of the contract addresses.
320
-
321
- At the end of the `init() { ... }` function (after `console.log("Alice balance:", aliceBalance)`) add the following code:
322
-
323
- ```javascript
324
- // Wait for datatoken to be published
325
- await new Promise((r) => setTimeout(r, 15000))
326
-
327
- const asset = await ocean.assets.resolve(dataId)
328
- const accessService = await ocean.assets.getServiceByType(asset.id, 'access')
329
- console.log('accessService', accessService)
330
- ```
331
-
332
- Now save and run the file:
333
-
334
- ```Bash
335
- node marketplace.js
336
- ```
337
-
338
- In the terminal output you should see the atributes of your dataset, including the cost, creator address and published date.
339
-
340
- ## 11. Bob acquires datatokens (value swap)
341
-
342
- Now, you're Bob :) In production environment, Bob would visit the marketplace website and purchase datatokends with USD via a payment gateway such as Stripe. In this example we demonstrate Alice sending Bob datatokens so that he is able to consume the dataset.
343
-
344
- First we will edit the `init() { ... }` function to create an address for Bob. On the line after `const marketplace = accounts[1].id;` add the following code:
345
-
346
- ```Javascript
347
- const bob = accounts[2].id;
348
- console.log('Bob account address:', bob);
349
- ```
350
-
351
- Now at the end of the `init() { ... }` function (after `console.log('transactionId', transactionId)`) add the following code:
352
-
353
- ```Javascript
354
- const transaction = await datatoken.transfer(tokenAddress, bob, '50', alice)
355
- const transactionId = transaction['transactionHash']
356
- console.log('transactionId', transactionId)
357
-
358
- let bobBalance = await datatoken.balance(tokenAddress, bob)
359
- aliceBalance = await datatoken.balance(tokenAddress, alice)
360
-
361
- console.log('Alice token balance:', aliceBalance)
362
- console.log('Bob token balance:', bobBalance)
363
- ```
364
-
365
- Save the `marketplace.js` file and run it again. In your terminal enter:
366
-
367
- ```bash
368
- node marketplace.js
369
- ```
370
-
371
- You should see in the terminal output that both Bob and Alice have a balance of 50 tokens.
372
-
373
- ## 12. Bob downloads the dataset
374
-
375
- Finally, Bob downloads the dataset. This is is a two part process where he first orders the dataset and then downloads it.
376
-
377
- At the end of the `init() { ... }` function (after `console.log("bobTransaction", bobTransaction)`) add the following code:
378
-
379
- ```javascript
380
- const bobTransaction = await ocean.assets.order(asset.id, accessService.type, bob)
381
- console.log('bobTransaction', bobTransaction)
382
-
383
- const data = await ocean.assets.download(
384
- asset.id,
385
- bobTransaction,
386
- tokenAddress,
387
- accounts[2],
388
- './datafiles'
389
- )
390
- bobBalance = await datatoken.balance(tokenAddress, bob)
391
- console.log('Bob token balance:', bobBalance)
392
- ```
393
-
394
- Save the `marketplace.js` file and run it again. In your terminal enter:
395
-
396
- You should see in the terminal output that Bob's balance has now been reduce to 40 tokens, as he has spent 10 on the dataset. You can confirm in the terminal that the data has been downloaded with the following commands:
397
-
398
- ```bash
399
- cd datafiles
400
- ls
401
- ```
402
-
403
- In the terminal output you should see a new directory has been created that contains your data.
404
-
405
- To view Bob's previous orders you can enter the following code at the end of the `init() { ... }` function (after `console.log("Bob token balance:", bobBalance)`):
406
-
407
- ```javascript
408
- const history = await ocean.assets.getOrderHistory(accounts[2])
409
- console.log("Bob's history", history)
410
- ```
411
-
412
- If you save the file and run it again you should see all of Bob's previous orders.
413
-
414
- ## 13. Extensions
415
-
416
- Congratulations on completing the Oceon.js Marketplace tutorial 🌊🐋🐠. This has given you a solid foundation upon which you can start using Ocean.js. There is still a lot more you can do with Ocean.js, here are some suggestions for next steps to continue learning:
417
-
418
- 1. Check Alice's order history using `ocean.assets.getOrderHistory(accounts[0])`
419
- 2. List all of Alice's assets with `ocean.assets.ownerAssets(alice)`
420
- 3. Update metadata for Alice's dataset using `ocean.assets.editMetadata(ddo, newMetaData)`
421
- 4. Update the new metadata onchain with `ocean.onChainMetadata.update(newDdo.id, newDdo, alice)`
422
- 5. Check the metadata with `ocean.assets.getServiceByType(ddo.id, 'metadata')`
423
- 6. Update the timeout for the dataset with `ocean.assets.editServiceTimeout(ddo, serviceIndex, newTimeout)`
@@ -1,272 +0,0 @@
1
- # Quickstart: Simple Flow
2
-
3
- This section describes how to create a datatoken and host a dataset using the simplest flow.
4
-
5
- Here are the the steps:
6
-
7
- 1. Initialize services
8
- 2. Create a new node.js project
9
- 3. Install dependencies
10
- 4. Create a config file and update contract addresses
11
- 5. Publish a new datatoken
12
- 6. Mint 100 tokens
13
- 7. Transfer tokens between users.
14
- 8. Host a dataset
15
-
16
- Let's go through each of these in detail.
17
-
18
- ## 1. Initialize services
19
-
20
- We start by initializing the services. To do this, we clone the Barge repository and run it. This will run the current default versions of [Aquarius](https://github.com/oceanprotocol/aquarius), [Provider](https://github.com/oceanprotocol/provider-py), and [Ganache](https://github.com/trufflesuite/ganache-cli) with [our contracts](https://github.com/oceanprotocol/ocean-contracts) deployed to it.
21
-
22
- ```bash
23
- git clone https://github.com/oceanprotocol/barge.git
24
- cd barge/
25
- ./start_ocean.sh --with-provider2 --no-dashboard
26
- ```
27
-
28
- ## 2. Create a new node.js project
29
-
30
- Start by creating a new Node.js project. Open a new terminal and enter the following commands:
31
-
32
- ```bash
33
- mkdir ocean-quickstart
34
- cd ocean-quickstart
35
- npm init
36
- # Answer the questions in the command line prompt
37
- cat > index.js
38
- # On linux press CTRL + D to save
39
- ```
40
-
41
- ## 3. Install dependencies
42
-
43
- Open the package.json file in a text editor and update the dependencies to include the following:
44
-
45
- ```JSON
46
- "dependencies": {
47
- "@oceanprotocol/contracts": "^0.5.6",
48
- "@oceanprotocol/lib": "^0.6.5",
49
- "web3": "^1.3.0"
50
- }
51
- ```
52
-
53
- Now in your terminal run the following command:
54
-
55
- ```bash
56
- npm install
57
- ```
58
-
59
- ## 4. Create a config file and update contract addresses
60
-
61
- Create a new config.js file:
62
-
63
- ```bash
64
- cat > config.js
65
- ```
66
-
67
- Now open the config.js in your code editor and enter the following:
68
-
69
- ```Javascript
70
- const { ConfigHelper } = require("@oceanprotocol/lib");
71
- const Web3 = require("web3");
72
- const defaultConfig = new ConfigHelper().getConfig("development");
73
-
74
- const urls = {
75
- networkUrl: "http://localhost:8545",
76
- aquarius: "http://localhost:5000",
77
- providerUri: "http://localhost:8030",
78
- };
79
-
80
- const contracts = {
81
- "DTFactory": "0x_YOUR_DTFactory_ADDRESS_",
82
- "BFactory": "0x_YOUR_DTFactory_ADDRESS_",
83
- "FixedRateExchange": "0x_YOUR_DTFactory_ADDRESS_",
84
- "Metadata": "0x_YOUR_Metadata_ADDRESS_",
85
- "Ocean": "0x_YOUR_Ocean_ADDRESS_"
86
- };
87
-
88
- const config = {
89
- ...defaultConfig,
90
- metadataCacheUri: urls.aquarius,
91
- providerUri: urls.providerUri,
92
- web3Provider: new Web3(urls.networkUrl),
93
- };
94
-
95
- module.exports = {
96
- config,
97
- contracts,
98
- urls,
99
- };
100
-
101
- ```
102
-
103
- Now check what your contract addresses are locally. In your terminal run:
104
-
105
- ```bash
106
- cat ~/.ocean/ocean-contracts/artifacts/address.json
107
- ```
108
-
109
- Next, update the contract addresses in your config.js file. Replace each of the place holders with the actual addresses that were outputted into your terminal.
110
-
111
- ## 5. Publish a new datatoken
112
-
113
- Now open the `index.js` file in your text editor. Enter the following code and save the file:
114
-
115
- ```Javascript
116
- const Web3 = require("web3");
117
- const { Ocean, Datatokens } = require("@oceanprotocol/lib");
118
-
119
- const { factoryABI } = require("@oceanprotocol/contracts/artifacts/contracts/DTFactory.json");
120
- const { datatokensABI } = require("@oceanprotocol/contracts/artifacts/contracts/DatatokenTemplate.json");
121
- const { config, contracts, urls } = require("./config");
122
-
123
-
124
-
125
- const init = async () => {
126
- const ocean = await Ocean.getInstance(config);
127
- const blob = `http://localhost:8030/api/v1/services/consume`;
128
-
129
- const accounts = await ocean.accounts.list();
130
- const alice = accounts[0].id;
131
- console.log('Alice account address:', alice)
132
-
133
- const datatoken = new Datatokens(
134
- contracts.DTFactory,
135
- factoryABI,
136
- datatokensABI,
137
- new Web3(urls.networkUrl)
138
- );
139
- const tokenAddress = await datatoken.create(blob, alice);
140
- console.log(`Deployed datatoken address: ${tokenAddress}`);
141
- };
142
-
143
- init();
144
- ```
145
-
146
- Now in your terminal, run the following command:
147
-
148
- ```bash
149
- node index.js
150
- ```
151
-
152
- Congratulations, you've created your first Ocean datatoken! 🌊🐋
153
-
154
- ## 6. Mint 100 tokens
155
-
156
- Next, we will edit the code in `index.js` to mint 100 datatokens. These 100 datatokens are minted and sent to Alice's Address.
157
-
158
- At the end of the `init() { ... }` function (after `console.log('Deployed datatoken address: ${tokenAddress}')`) add the following line of code:
159
-
160
- ```Javascript
161
- await datatoken.mint(tokenAddress, alice, '100', alice)
162
- let aliceBalance = await datatoken.balance(tokenAddress, alice)
163
- console.log('Alice token balance:', aliceBalance)
164
- ```
165
-
166
- Now run the `index.js` file again:
167
-
168
- ```bash
169
- node index.js
170
- ```
171
-
172
- You should now see in the console output that Alice has a token balance of 100.
173
-
174
- ## 7. Transfer tokens between users.
175
-
176
- Next we will transfer tokens from Alice to Bob. First we will edit the `init() { ... }` function to create an address for Bob. On the line after `const alice = accounts[0].id` add the following code:
177
-
178
- ```Javascript
179
- const bob = accounts[1].id;
180
- console.log('Bob account address:', bob);
181
- ```
182
-
183
- Now at the end of the `init() { ... }` function (after `console.log('Alice token balance:', aliceBalance)`) add the following code:
184
-
185
- ```Javascript
186
- const transaction = await datatoken.transfer(tokenAddress, bob, '50', alice)
187
- const transactionId = transaction['transactionHash']
188
- console.log('transactionId', transactionId)
189
-
190
- const bobBalance = await datatoken.balance(tokenAddress, bob)
191
- aliceBalance = await datatoken.balance(tokenAddress, alice)
192
-
193
- console.log('Alice token balance:', aliceBalance)
194
- console.log('Bob token balance:', bobBalance)
195
- ```
196
-
197
- Save the `index.js` file and run it again. In your terminal enter:
198
-
199
- ```bash
200
- node index.js
201
- ```
202
-
203
- You should now see in the terminal output that both Alice and Bob have a token balance of 50.
204
-
205
- ## 8. Publish a dataset
206
-
207
- Create a new file called data.js. In your terminal enter these commands:
208
-
209
- ```Bash
210
- cat > data.js
211
- ```
212
-
213
- Open the data.js file in your text editor. Enter the following code and save the file:
214
-
215
- ```Javascript
216
- const testData = {
217
- main: {
218
- type: "dataset",
219
- name: "test-dataset",
220
- dateCreated: new Date(Date.now()).toISOString().split(".")[0] + "Z",
221
- author: "test",
222
- license: "MIT",
223
- files: [
224
- {
225
- url:
226
- "https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_10.xls",
227
- contentType: "xlsx",
228
- },
229
- ],
230
- },
231
- };
232
-
233
- module.exports = { testData };
234
- ```
235
-
236
- Now, in your `index.js` file import the test data. Add the following line of code at the top of the file under the other `require()` statements:
237
-
238
- ```Javascript
239
- const { testData } = require("./data");
240
- ```
241
-
242
- At the end of the `init() { ... }` function (after `console.log('Bob token balance:', bobBalance)`) add the following code:
243
-
244
- ```Javascript
245
- dataService = await ocean.assets.createAccessServiceAttributes(
246
- accounts[0],
247
- 10, // set the price in datatoken
248
- new Date(Date.now()).toISOString().split(".")[0] + "Z", // publishedDate
249
- 0 // timeout
250
- );
251
-
252
- // publish asset
253
- const createData = await ocean.assets.create(
254
- testData,
255
- accounts[0],
256
- [dataService],
257
- tokenAddress
258
- );
259
-
260
- const dataId = createData.id;
261
- console.log('Data ID:', dataId);
262
- ```
263
-
264
- Now save and run the `index.js` file:
265
-
266
- ```Bash
267
- node index.js
268
- ```
269
-
270
- In the terminal output you should now see the Data ID (did) outputed.
271
-
272
- Congratulations, you have published your first dataset! 🌊🐠🐡 Now you are ready for the [marketplace flow](docs/quickstart_marketplace.md).