@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
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oceanprotocol/lib",
3
3
  "source": "./src/index.ts",
4
- "version": "1.0.0-next.9",
4
+ "version": "1.0.0",
5
5
  "description": "JavaScript client library for Ocean Protocol",
6
6
  "main": "./dist/lib.js",
7
7
  "umd:main": "dist/lib.umd.js",
@@ -27,20 +27,25 @@
27
27
  "changelog": "auto-changelog -p",
28
28
  "prepublishOnly": "npm run build",
29
29
  "mocha": "TS_NODE_PROJECT='./test/tsconfig.json' mocha --config=test/.mocharc.json --node-env=test --exit",
30
- "test:ss": "npm run mocha -- 'test/unit/pools/ssContracts/SideStaking.test.ts'",
30
+ "test:nftfactory": "npm run mocha -- 'test/unit/factories/NftFactory.test.ts'",
31
+ "test:nft": "npm run mocha -- 'test/unit/tokens/Nft.test.ts'",
32
+ "test:datatoken": "npm run mocha -- 'test/unit/tokens/Datatoken.test.ts'",
33
+ "test:router": "npm run mocha -- 'test/unit/pools/Router.test.ts'",
31
34
  "test:fixed": "npm run mocha -- 'test/unit/pools/fixedRate/FixedRateExchange.test.ts'",
35
+ "test:ss": "npm run mocha -- 'test/unit/pools/ssContracts/SideStaking.test.ts'",
32
36
  "test:pool": "npm run mocha -- 'test/unit/pools/balancer/Pool.test.ts'",
33
37
  "test:dispenser": "npm run mocha -- 'test/unit/pools/dispenser/Dispenser.test.ts'",
34
- "test:dt": "npm run mocha -- 'test/unit/tokens/Datatoken.test.ts'",
35
- "test:nftDt": "npm run mocha -- 'test/unit/tokens/Nft.test.ts'",
36
- "test:factory": "npm run mocha -- 'test/unit/NftFactory.test.ts'",
37
- "test:router": "npm run mocha -- 'test/unit/pools/Router.test.ts'",
38
38
  "test:publishAll": "npm run mocha -- 'test/integration/PublishFlows.test.ts'",
39
+ "test:examples": "npm run mocha -- 'test/integration/CodeExamples.test.ts'",
40
+ "test:provider": "npm run mocha -- 'test/integration/Provider.test.ts'",
39
41
  "test:unit": "npm run mocha -- 'test/unit/**/*.test.ts'",
40
42
  "test:unit:cover": "nyc --report-dir coverage/unit npm run test:unit",
41
43
  "test:integration": "npm run mocha -- 'test/integration/**/*.test.ts'",
42
- "test:provider": "npm run mocha -- 'test/integration/Provider.test.ts'",
43
- "test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration"
44
+ "test:compute": "npm run mocha -- 'test/integration/ComputeFlow.test.ts'",
45
+ "test:integration:cover": "nyc --report-dir coverage/integration --no-clean npm run test:integration",
46
+ "create:guide": "chmod +x ./scripts/createCodeExamples.sh && ./scripts/createCodeExamples.sh",
47
+ "create:guide:mac": "chmod +x ./scripts/createCodeExamples-mac.sh && ./scripts/createCodeExamples-mac.sh",
48
+ "commit:guide": "chmod +x scripts/commitChanges.sh && scripts/commitChanges.sh"
44
49
  },
45
50
  "repository": {
46
51
  "type": "git",
@@ -54,49 +59,49 @@
54
59
  },
55
60
  "homepage": "https://github.com/oceanprotocol/ocean.js#readme",
56
61
  "peerDependencies": {
57
- "web3": ">=1.3.5"
62
+ "web3": "^1.7.3"
58
63
  },
59
64
  "dependencies": {
60
- "@oceanprotocol/contracts": "^1.0.0-alpha.15",
65
+ "@oceanprotocol/contracts": "^1.0.0",
61
66
  "bignumber.js": "^9.0.2",
62
- "cross-fetch": "^3.1.4",
63
- "crypto-js": "^4.0.0",
64
- "decimal.js": "^10.2.1",
65
- "web3": ">=1.3.5",
66
- "web3-core": "^1.6.1",
67
- "web3-eth-contract": "^1.6.1"
67
+ "cross-fetch": "^3.1.5",
68
+ "crypto-js": "^4.1.1",
69
+ "decimal.js": "^10.3.1",
70
+ "web3": "^1.7.3",
71
+ "web3-core": "^1.7.1",
72
+ "web3-eth-contract": "^1.7.1"
68
73
  },
69
74
  "devDependencies": {
70
- "@truffle/hdwallet-provider": "^1.5.1",
71
- "@types/chai": "^4.2.19",
75
+ "@truffle/hdwallet-provider": "^2.0.8",
76
+ "@types/chai": "^4.3.1",
72
77
  "@types/chai-spies": "^1.0.3",
73
- "@types/crypto-js": "^4.0.1",
74
- "@types/mocha": "^9.0.0",
75
- "@types/node": "^16.10.3",
78
+ "@types/crypto-js": "^4.1.1",
79
+ "@types/mocha": "^9.1.1",
80
+ "@types/node": "^17.0.35",
76
81
  "@types/node-fetch": "^3.0.3",
77
82
  "@typescript-eslint/eslint-plugin": "^4.33.0",
78
83
  "@typescript-eslint/parser": "^4.33.0",
79
- "auto-changelog": "^2.3.0",
80
- "chai": "^4.3.4",
84
+ "auto-changelog": "^2.4.0",
85
+ "chai": "^4.3.6",
81
86
  "chai-spies": "^1.0.0",
82
87
  "cross-env": "^7.0.3",
83
88
  "eslint": "^7.17.0",
84
89
  "eslint-config-oceanprotocol": "^1.5.0",
85
- "eslint-config-prettier": "^8.3.0",
90
+ "eslint-config-prettier": "^8.5.0",
86
91
  "eslint-plugin-prettier": "^4.0.0",
87
92
  "fs": "0.0.1-security",
88
- "microbundle": "^0.14.2",
89
- "mocha": "^9.1.2",
90
- "mock-local-storage": "^1.1.17",
93
+ "microbundle": "0.14.2",
94
+ "mocha": "^10.0.0",
95
+ "mock-local-storage": "^1.1.21",
91
96
  "nyc": "^15.1.0",
92
97
  "ora": "5.4.1",
93
- "prettier": "^2.3.1",
94
- "release-it": "^14.12.1",
98
+ "prettier": "^2.6.2",
99
+ "release-it": "^15.0.0",
95
100
  "source-map-support": "^0.5.19",
96
- "ts-node": "^10.0.0",
101
+ "ts-node": "^10.8.0",
97
102
  "ts-node-register": "^1.0.0",
98
- "typedoc": "0.22.5",
99
- "typescript": "^4.3.4"
103
+ "typedoc": "0.22.15",
104
+ "typescript": "^4.6.4"
100
105
  },
101
106
  "nyc": {
102
107
  "include": [
@@ -1,11 +0,0 @@
1
- export interface Erc20CreateParams {
2
- templateIndex: number;
3
- minter: string;
4
- feeManager: string;
5
- mpFeeAddress: string;
6
- feeToken: string;
7
- feeAmount: string;
8
- cap: string;
9
- name?: string;
10
- symbol?: string;
11
- }
@@ -1,12 +0,0 @@
1
- export interface Operation {
2
- exchangeIds: string;
3
- source: string;
4
- operation: number;
5
- tokenIn: string;
6
- amountsIn: string | number;
7
- tokenOut: string;
8
- amountsOut: string | number;
9
- maxPrice: string | number;
10
- swapMarketFee: string;
11
- marketFeeAddress: string;
12
- }
@@ -1,5 +0,0 @@
1
- export * from './FixedRateInterface';
2
- export * from './PoolInterface';
3
- export * from './Erc20Interface';
4
- export * from './DispenserInterface';
5
- export * from './RouterInterface';
@@ -1,3 +0,0 @@
1
- import { Config } from '../../src/models/Config';
2
- declare const _default: Config;
3
- export default _default;
@@ -1,3 +0,0 @@
1
- import { Config } from '../../src/models/Config';
2
- declare const _default: Config;
3
- export default _default;
@@ -1,338 +0,0 @@
1
- # A beginners guide to selling data over the blockchain
2
-
3
- This is a beginners guide to selling a dataset over the blockchain. The process involves creating a datatoken, which will be used to purchase the dataset, and listing it on a marketplace. This guide provides all the code you need and no prior knowledge is required. It is helpful if you have some experience with javascript but it is not necessary.
4
-
5
- Selling your data over the blockchain puts you in charge of how it is used and can be a great source of passive income. There are many AI startups that have deep expertise in machine learning but need more data to improve their models. Selling your data via the blockchain gives you a level of security that you would be unable to achieve if you were selling via a centralised marketplace.
6
-
7
- In this guide we'll be making use of the Ocean.js library. Ocean Protocol provides you with everything you need to quickly get setup and start selling data over the blockchain.
8
-
9
- If you have any questions or issues at any point while following along to this article please reach out to us on [discord](https://discord.gg/TnXjkR5).
10
-
11
- Here are the steps we will be following throughout the article:
12
-
13
- 0. Prerequisites
14
- 1. Initialize services
15
- 2. Create a new node.js project
16
- 3. Install dependencies
17
- 4. Create a config file and update contract addresses
18
- 5. Publish a new datatoken
19
- 6. Mint 200 tokens
20
- 7. Publish a dataset
21
- 8. Allow the marketplace to sell your datatokens
22
-
23
- Let's go through each step:
24
-
25
- ## 0. Prerequisites
26
- Before we start it is important that you have all of the necessary prerequisites installed on your computer.
27
- - **A Unix based operating system (Linux or Mac)**. If you are a Windows user you can try to run linux inside a virtual machine but this is outside of the scope of this article.
28
- - **Git**. Instructions for installing Git can be found here: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
29
- - **Node.js** can be downloaded from here: https://nodejs.org/en/download/
30
- - **Docker** can be installed from here: https://docs.docker.com/get-docker/. Please note that Docker must run as a non-root user, you can set this up by following these instructions: https://docs.docker.com/engine/install/linux-postinstall/
31
-
32
-
33
-
34
- ## 1. Initialize services
35
- For this tutorial we will be setting up and running a local blockchain and then the datatokens will be published to your local blockchain. This isn’t as difficult as it sounds, fortunately Ocean Protocol provides the services to start your local blockchain with a couple of commands. Deploying your datatoken to a locally run blockchain is a great way to start as it is quick and avoids any costs.
36
-
37
- Simply copy the following commands into your terminal and your own local blockchain will start running:
38
-
39
- ```Bash
40
- git clone https://github.com/oceanprotocol/barge.git
41
- cd barge/
42
- ./start_ocean.sh --with-provider2 --no-dashboard
43
- ```
44
-
45
- These commands clone the Ocean Protocol Barge service and start running it. This does more than just start a local blockchain, it also deploys the Ocean Protocol smart contracts to your local blockchain and starts a local off-chain database for saving the metadata.
46
-
47
- A smart contract is a self executing piece of code that is stored on the blockchain. They essentially provide the backend logic for managing your datasets and datatokens. They are not contracts in the legal sense.
48
-
49
- You can read more about each of the services that barge runs via these links:
50
- - **Aquarius** provides the off-chain database: https://github.com/oceanprotocol/aquarius
51
- - **Ganache** is part of the Truffle Suite of blockchain tools and it sets up and runs the local blockchain: https://github.com/trufflesuite/ganache-cli
52
- - Ocean Protocol **smart contracts**: https://github.com/oceanprotocol/ocean-contracts
53
- - **Provider**: https://github.com/oceanprotocol/provider-py
54
-
55
- You need to leave the Barge services running throughout the rest of the tutorial so make sure you keep this terminal window open. All of the remaining terminal commands will be done in a new terminal window.
56
-
57
- ## 2. Create a new node.js project
58
-
59
- You are now ready to start your project. We start by creating a new folder and initiating a new Node.js project. Open a new terminal and enter the following commands:
60
-
61
- ```bash
62
- mkdir quickstart
63
- cd quickstart
64
- npm init
65
- # Answer the questions in the command line prompt
66
- cat > index.js
67
- # On linux press CTRL + D to save
68
- ```
69
-
70
- ## 3. Install dependencies
71
-
72
- Next we need to set up the Node.js project so that it installs the necessary dependencies. These include the Ocean Protocol libaries and contracts, as well as web3.js which is a javascript library for interacting with the Blockchain. If you would like to learn more about web3.js, you can read the documentation here: https://web3js.readthedocs.io/en/v1.3.4/
73
-
74
- Open the package.json file in a text editor and update the dependencies to include the following:
75
- ```JSON
76
- "dependencies": {
77
- "@oceanprotocol/contracts": "^0.5.6",
78
- "@oceanprotocol/lib": "^0.6.5",
79
- "web3": "^1.3.0"
80
- }
81
- ```
82
-
83
- Now in your terminal run the following command:
84
-
85
- ```bash
86
- npm install
87
- ```
88
-
89
- At this point you may get some warning messages but there shouldn’t be any errors. As long as you don’t have any errors, you are ready to proceed.
90
-
91
- ## 4. Create a config file and update contract addresses
92
- Now we need to set up a configuration file that will determine where your datatoken and dataset are published to. We will enter the local addresses where the Ocean Protocol services are running. When you are ready to deploy your datatoken on the Ethereum mainnet you will need to update these addresses, the process of live deploying your dataset and datatokens will be covered in a later blog post.
93
-
94
- Start by creating a new config.js file. In your terminal, enter the following command.
95
-
96
- ```bash
97
- cat > config.js
98
- ```
99
-
100
- Make sure that this config.js file has been created inside your quickstart directory. Now open the config.js in your code editor and enter the following code:
101
-
102
- ```Javascript
103
- const { ConfigHelper } = require("@oceanprotocol/lib");
104
- const Web3 = require("web3");
105
- const defaultConfig = new ConfigHelper().getConfig("development");
106
-
107
- const urls = {
108
- networkUrl: "http://localhost:8545",
109
- aquarius: "http://localhost:5000",
110
- providerUri: "http://localhost:8030",
111
- };
112
-
113
- const contracts = {
114
- "DTFactory": "0x_YOUR_DTFactory_ADDRESS_",
115
- "BFactory": "0x_YOUR_DTFactory_ADDRESS_",
116
- "FixedRateExchange": "0x_YOUR_DTFactory_ADDRESS_",
117
- "Metadata": "0x_YOUR_Metadata_ADDRESS_",
118
- "Ocean": "0x_YOUR_Ocean_ADDRESS_"
119
- };
120
-
121
- const config = {
122
- ...defaultConfig,
123
- metadataCacheUri: urls.aquarius,
124
- providerUri: urls.providerUri,
125
- web3Provider: new Web3(urls.networkUrl),
126
- };
127
-
128
- module.exports = {
129
- config,
130
- contracts,
131
- urls,
132
- };
133
- ```
134
-
135
- You will notice that the code currently contains placeholders for the contract addresses (e.g. `“0x_YOUR_DTFactory_ADDRESS_"`). This is because we need to update these addresses with the addresses of the Ocean Protocol smart contracts on your local blockchain.
136
-
137
- When the Barge service started running it automatically saved contract addresses in a JSON file in a hidden folder under your home directory. We can check what these contract addresses are by running the following command into your terminal:
138
-
139
- ```bash
140
- cat ~/.ocean/ocean-contracts/artifacts/address.json
141
- ```
142
- You should get an output that looks like this:
143
-
144
- ```JSON
145
- {
146
- "development": {
147
- "DTFactory": "0x27F7b0C827596C7355ee39EdFd3235F8b47C2862",
148
- "BFactory": "0xCe7c408C56f8BFF8EF616F5CE3E7868486de3748",
149
- "FixedRateExchange": "0xf4C7B100cECA95Badc583bdBd10F6CA8D9123B09",
150
- "Metadata": "0x2c11A9763AaCb838fDFD6Ee01fD1179196ee20f5",
151
- "Ocean": "0x11570aE63B4fDe21d213Bc1A9BF61eEA51d13D56"
152
- }
153
- }
154
- ```
155
-
156
- Now we need to remove the placeholder contract addresses from the config.js file and replace them with the contract addresses that were outputted to your terminal. When you have done this, save the file.
157
-
158
- ## 5. Publish a new datatoken
159
- Now you are ready to publish your first datatoken!
160
-
161
- The datatoken that we will be deploying is an ERC20 token. ERC20 is standard for fungible tokens (meaning each token is identical and interchangeable), the standard contains a list of required and optional functions that form the smart contract which manages the token balances and transfers. ERC20 is the most popular standard for tokens deployed on the Ethereum Blockchain and many of the popular tokens that you will have heard of (Tether, USDC, Dai, Binance token) all follow the ERC20 standard. You can read more about the ERC20 token standard here: https://ethereum.org/en/developers/docs/standards/tokens/erc-20/
162
-
163
- Security is incredibly important for any blockchain token (as they are a potential target for attacks) and for this reason it is not best practice to write an ERC20 from scratch. This would introduce unnecessary complexity and would require an in depth security audit. In general, complexity is the enemy of security. Instead of writing our own ERC20 token, the code we deploy will inherit from the OpenZepplin ERC20 library. This library has been thoroughly battle tested in live environments and is used to underpin millions of dollars. You can read more about the OpenZepplin ERC20 contract libraries here: https://docs.openzeppelin.com/contracts/2.x/api/token/erc20
164
-
165
- The process of creating and deploying the ERC20 datatokens has been automated by Ocean Protocol. All we need to do is open the `index.js` file in your text editor and enter the following code:
166
-
167
- ```Javascript
168
- const Web3 = require("web3");
169
- const { Ocean, Datatokens } = require("@oceanprotocol/lib");
170
-
171
- const { factoryABI } = require("@oceanprotocol/contracts/artifacts/contracts/DTFactory.json");
172
- const { datatokensABI } = require("@oceanprotocol/contracts/artifacts/contracts/DatatokenTemplate.json");
173
- const { config, contracts, urls } = require("./config");
174
-
175
- const init = async () => {
176
- const ocean = await Ocean.getInstance(config);
177
- const blob = `http://localhost:8030/api/v1/services/consume`;
178
-
179
- const accounts = await ocean.accounts.list();
180
- const alice = accounts[0].id;
181
- console.log('Alice account address:', alice)
182
-
183
- const datatoken = new Datatokens(
184
- contracts.DTFactory,
185
- factoryABI,
186
- datatokensABI,
187
- new Web3(urls.networkUrl)
188
- );
189
- const tokenAddress = await datatoken.create(blob, alice);
190
- console.log(`Deployed datatoken address: ${tokenAddress}`);
191
- };
192
-
193
- init();
194
- ```
195
-
196
- This is all the code you need to deploy your first datatoken. Now save the file and run it. In your terminal, run the following command:
197
-
198
- ```Bash
199
- node index.js
200
- ```
201
-
202
- You should see the console log message stating the address of your datatoken. Congratulations, you've created your first Ocean datatoken! 🌊🐋
203
-
204
- ## 6. Mint 200 tokens
205
-
206
- Next, we will edit the code in `index.js` to mint 200 datatokens. These 200 datatokens are minted and sent to Alice's Address.
207
-
208
- At the end of the `init() { ... }` function (after `console.log('Deployed datatoken address: ${tokenAddress}')`) add the following line of code:
209
-
210
- ```Javascript
211
- await datatoken.mint(tokenAddress, alice, '200', alice)
212
- let aliceBalance = await datatoken.balance(tokenAddress, alice)
213
- console.log('Alice token balance:', aliceBalance)
214
- ```
215
-
216
- Now run the `index.js` file again:
217
-
218
- ```bash
219
- node index.js
220
- ```
221
-
222
- You should now see in the console output that Alice has a token balance of 200.
223
-
224
- ## 7. Publish a dataset
225
-
226
- Now we will publish your dataset so that it can be sold over the blockchain. We start by creating a new file called data.js. In your terminal enter these commands:
227
-
228
- ```Bash
229
- cat > data.js
230
- ```
231
-
232
- Now open the data.js file in your text editor. Enter the following code and save the file:
233
-
234
- ```Javascript
235
- const testData = {
236
- main: {
237
- type: "dataset",
238
- name: "test-dataset",
239
- dateCreated: new Date(Date.now()).toISOString().split(".")[0] + "Z",
240
- author: "test",
241
- license: "MIT",
242
- files: [
243
- {
244
- url:
245
- "https://file-examples-com.github.io/uploads/2017/02/file_example_XLS_10.xls",
246
- contentType: "xlsx",
247
- },
248
- ],
249
- },
250
- };
251
-
252
- module.exports = { testData };
253
- ```
254
-
255
- If you already have a dataset hosted somewhere you can replace the example link url to the address where your dataset is hosted. You should also update the contentType field with the file extension of your dataset. If you haven’t yet hosted your dataset, you can continue with the example link in place.
256
-
257
- Now, we need to import the dataset into the index.js file. Open your your `index.js` in your text editor and add the following line of code at the top of the file under the other `require()` statements:
258
-
259
- ```Javascript
260
- const { testData } = require("./data");
261
- ```
262
-
263
- Next we add the code for publishing the dataset. This includes important information about your dataset such as the price, the publishing date and the timeout. At the end of the `init() { ... }` function (after `console.log('Bob token balance:', bobBalance)`) add the following code:
264
-
265
- ```Javascript
266
- dataService = await ocean.assets.createAccessServiceAttributes(
267
- accounts[0],
268
- 10, // set the price in datatoken
269
- new Date(Date.now()).toISOString().split(".")[0] + "Z", // publishedDate
270
- 0 // timeout
271
- );
272
-
273
- // publish asset
274
- const createData = await ocean.assets.create(
275
- testData,
276
- accounts[0],
277
- [dataService],
278
- tokenAddress
279
- );
280
-
281
- const dataId = createData.id;
282
- console.log('Data ID:', dataId);
283
- ```
284
-
285
- Now save and run the `index.js` file:
286
-
287
- ```Bash
288
- node index.js
289
- ```
290
-
291
- In the terminal output you should now see the Data ID (did) output.
292
-
293
- Congratulations, you have published your first dataset! 🌊🐠
294
-
295
- ## 8. Allow the marketplace to sell you datatokens
296
-
297
- Finally we will go through the steps for allowing a marketplace to sell your dataset. For this demonstration we will use the address of a marketplace on your local blockchain but in a live environment you would need to use the address of the actual marketplace that will be selling your data. It is important to double check that this address is correct because if it isn’t you could permanently lose your datatokens.
298
-
299
- We start by saving the address of the marketplace. On the line after `const alice = accounts[0].id` add the following code:
300
-
301
- ```Javascript
302
- const marketplace = accounts[1].id;
303
- console.log('Marketplace account address:', marketplace);
304
- ```
305
-
306
- Next we will initiate a transaction that approves the marketplace to send your tokens (to buyers) on your behalf. We then make a call on the datatoken contract to check the allowance that the marketplace now has.
307
-
308
- At the end of the `init() { ... }` function (after `console.log('Data ID:', dataId)`) add the following code:
309
-
310
- ```Javascript
311
- await datatoken.approve(
312
- tokenAddress,
313
- marketplace, // marketplace address,
314
- '100', // marketplaceAllowance
315
- alice
316
- )
317
-
318
- const marketplaceAllowance = await datatoken.allowance(
319
- tokenAddress,
320
- alice,
321
- marketplace, // marketplace address,
322
- );
323
-
324
- console.log("Marketplace Allowance:", marketplaceAllowance);
325
- ```
326
-
327
- Now save the file and run it:
328
-
329
- ```Bash
330
- node index.js
331
- ```
332
-
333
- You should see in the terminal output that the marketplace has an allowance of 100 datatokens.
334
-
335
- Well done, you have now completed the tutorial!
336
-
337
- There are many more things that you can do with Ocean.js which will be the subject of future blog posts. If you have any questions or if you would like you learn more about Ocean Protocol, please reach out to us on [Discord](https://discord.gg/TnXjkR5) or if you have found any issues with Ocean.js please raise them on [GitHub](https://github.com/oceanprotocol/ocean.js/issues/new?assignees=&labels=bug&template=bug_report.md&title=).
338
-
@@ -1,24 +0,0 @@
1
- <!--
2
- Copyright 2021 Ocean Protocol Foundation
3
- SPDX-License-Identifier: Apache-2.0
4
- -->
5
-
6
- # Get Test OCEAN and Verify It
7
-
8
- As you develop on Ocean, you'll often need to use the OCEAN token. It's an ERC20 token on Ethereum mainnet, along with testnet deployments.
9
-
10
- Here, let's get some OCEAN for the Rinkeby testnet.
11
-
12
- ## Setup
13
-
14
- This builds on the setup in the following. Please do it first.
15
-
16
- - [Datatokens tutorial](quickstart_simple.md)
17
-
18
- ## Get OCEAN
19
-
20
- [Get Rinkeby OCEAN via this faucet](https://faucet.rinkeby.oceanprotocol.com/).
21
-
22
- It will tell you that test OCEAN are on the way, and report the transaction id (txid). Copy this txid.
23
-
24
- Go to https://rinkeby.etherscan.io, and search for the txid. You will see the tx that sent you OCEAN.