@oceanprotocol/lib 5.0.3 → 5.0.4

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.
package/CHANGELOG.md CHANGED
@@ -4,12 +4,22 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [v5.0.4](https://github.com/oceanprotocol/ocean.js/compare/v5.0.3...v5.0.4)
8
+
9
+ - add envs and termination details [`#2004`](https://github.com/oceanprotocol/ocean.js/pull/2004)
10
+ - Add Cheatsheet. [`#2001`](https://github.com/oceanprotocol/ocean.js/pull/2001)
11
+ - Add support for BASE network. [`#2002`](https://github.com/oceanprotocol/ocean.js/pull/2002)
12
+ - Bump ddo.js to 0.1.4. [`#1996`](https://github.com/oceanprotocol/ocean.js/pull/1996)
13
+
7
14
  #### [v5.0.3](https://github.com/oceanprotocol/ocean.js/compare/v5.0.2...v5.0.3)
8
15
 
16
+ > 23 September 2025
17
+
9
18
  - Bump sha.js from 2.4.11 to 2.4.12 [`#1989`](https://github.com/oceanprotocol/ocean.js/pull/1989)
10
19
  - Bump @types/node from 22.15.29 to 24.3.0 [`#1992`](https://github.com/oceanprotocol/ocean.js/pull/1992)
11
20
  - extend metadata interface [`#1993`](https://github.com/oceanprotocol/ocean.js/pull/1993)
12
21
  - Bump tmp and @inquirer/editor [`#1985`](https://github.com/oceanprotocol/ocean.js/pull/1985)
22
+ - Release 5.0.3 [`d046872`](https://github.com/oceanprotocol/ocean.js/commit/d046872003bab4092d6cc50de4d32d2cdf72dc4c)
13
23
 
14
24
  #### [v5.0.2](https://github.com/oceanprotocol/ocean.js/compare/v5.0.1...v5.0.2)
15
25
 
package/Cheatsheet.md ADDED
@@ -0,0 +1,326 @@
1
+ # Ocean.js Cheatsheet
2
+
3
+ ## Prerequisites
4
+ - Git, Node.js, Docker
5
+ - Install Git: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
6
+ - Node.js: https://nodejs.org/en/download/
7
+ - Docker: https://docs.docker.com/get-docker/
8
+
9
+ ### Installation & Usage
10
+
11
+ ```bash
12
+ npm init
13
+ npm install @oceanprotocol/lib crypto-js ethers@5.7.2 typescript @types/node ts-node
14
+ ```
15
+
16
+ ### Configuration
17
+
18
+ ```bash
19
+ export NODE_URL='https://compute1.oceanprotocol.com'
20
+ export PRIVATE_KEY=<replace_me>
21
+ export RPC=<replace_me>
22
+ ```
23
+
24
+ ### Publish Flow
25
+
26
+ 1. Define DDO object
27
+ ```javascript
28
+
29
+ const genericAsset: DDO = {
30
+ '@context': ['https://w3id.org/did/v1'],
31
+ id: 'did:op',
32
+ version: '4.1.0',
33
+ chainId: 8996,
34
+ nftAddress: '0x0',
35
+ metadata: {
36
+ created: '2021-12-20T14:35:20Z',
37
+ updated: '2021-12-20T14:35:20Z',
38
+ type: 'dataset',
39
+ name: 'dataset-name',
40
+ description: 'Ocean protocol test dataset description',
41
+ author: 'oceanprotocol-team',
42
+ license: 'MIT',
43
+ tags: ['white-papers'],
44
+ additionalInformation: { 'test-key': 'test-value' },
45
+ links: ['http://data.ceda.ac.uk/badc/ukcp09/']
46
+ },
47
+ services: [
48
+ {
49
+ id: 'db164c1b981e4d2974e90e61bda121512e6909c1035c908d68933ae4cfaba6b0',
50
+ type: 'access',
51
+ files: '',
52
+ datatokenAddress: '0xa15024b732A8f2146423D14209eFd074e61964F3',
53
+ serviceEndpoint: 'http://127.0.0.1:8001',
54
+ timeout: 0
55
+ }
56
+ ]
57
+ }
58
+ ```
59
+ 2. Create NFT + datatoken + dispenser/FRE:
60
+
61
+ ```javascript
62
+
63
+ const { chainId } = await publisherAccount.provider.getNetwork()
64
+ const factory = new NftFactory(
65
+ addresses.ERC721Factory,
66
+ publisherAccount,
67
+ Number(chainId)
68
+ )
69
+
70
+ const nftParams: NftCreateData = {
71
+ name: FRE_NFT_NAME,
72
+ symbol: FRE_NFT_SYMBOL,
73
+ templateIndex: 1,
74
+ tokenURI: '',
75
+ transferable: true,
76
+ owner: await publisherAccount.getAddress()
77
+ }
78
+
79
+ const datatokenParams: DatatokenCreateParams = {
80
+ templateIndex: 1,
81
+ cap: '100000',
82
+ feeAmount: '0',
83
+ paymentCollector: ZERO_ADDRESS,
84
+ feeToken: ZERO_ADDRESS,
85
+ minter: await publisherAccount.getAddress(),
86
+ mpFeeAddress: ZERO_ADDRESS
87
+ }
88
+
89
+ const freParams: FreCreationParams = {
90
+ fixedRateAddress: addresses.FixedPrice,
91
+ baseTokenAddress: addresses.Ocean,
92
+ owner: await publisherAccount.getAddress(),
93
+ marketFeeCollector: await publisherAccount.getAddress(),
94
+ baseTokenDecimals: 18,
95
+ datatokenDecimals: 18,
96
+ fixedRate: '1',
97
+ marketFee: '0.001',
98
+ allowedConsumer: ZERO_ADDRESS,
99
+ withMint: true
100
+ }
101
+
102
+ const bundleNFT = await factory.createNftWithDatatokenWithFixedRate(
103
+ nftParams,
104
+ datatokenParams,
105
+ freParams
106
+ )
107
+
108
+ ```
109
+ ### Consume Flow
110
+ As a prerequisite for this flow, publish flow needs to be executed before.
111
+ ```javascript
112
+ const fixedRate = new FixedRateExchange(freAddress, consumerAccount, Number(chainId))
113
+ await fixedRate.buyDatatokens(freId, '1', '2')
114
+
115
+ const resolvedDDO = await aquarius.waitForIndexer(fixedDDO.id)
116
+ assert(resolvedDDO, 'Cannot fetch DDO from Aquarius')
117
+
118
+ // Initialize - obtain proof for ordering assets
119
+
120
+ const initializeData = await ProviderInstance.initialize(
121
+ resolvedDDO.id,
122
+ resolvedDDO.services[0].id,
123
+ 0,
124
+ await consumerAccount.getAddress(),
125
+ providerUrl
126
+ )
127
+
128
+ const providerFees: ProviderFees = {
129
+ providerFeeAddress: initializeData.providerFee.providerFeeAddress,
130
+ providerFeeToken: initializeData.providerFee.providerFeeToken,
131
+ providerFeeAmount: initializeData.providerFee.providerFeeAmount,
132
+ v: initializeData.providerFee.v,
133
+ r: initializeData.providerFee.r,
134
+ s: initializeData.providerFee.s,
135
+ providerData: initializeData.providerFee.providerData,
136
+ validUntil: initializeData.providerFee.validUntil
137
+ }
138
+ // Starting order after retriving provider fees
139
+ const tx = await datatoken.startOrder(
140
+ freDatatokenAddress,
141
+ await consumerAccount.getAddress(),
142
+ 0,
143
+ providerFees
144
+ )
145
+ const orderTx = await tx.wait()
146
+ const orderStartedTx = getEventFromTx(orderTx, 'OrderStarted')
147
+ console.log(`Order started, tx: ${orderStartedTx.transactionHash}`)
148
+
149
+ const downloadURL = await ProviderInstance.getDownloadUrl(
150
+ fixedDDO.id,
151
+ fixedDDO.services[0].id,
152
+ 0,
153
+ orderStartedTx.transactionHash,
154
+ providerUrl,
155
+ consumerAccount
156
+ )
157
+
158
+ // Lets check that the download URL was successfully received
159
+ console.log(`Download URL: ${downloadURL}`)
160
+
161
+ ```
162
+ For better UX, it is recommended to have installed VSCode extension.
163
+ ### Get compute environments
164
+
165
+ ```javascript
166
+
167
+
168
+ // Fetch compute envrionments first
169
+ const computeEnvs = await ProviderInstance.getComputeEnvironments(providerUrl)
170
+
171
+ ```
172
+ For `free start compute` it is not necessary publish flow.
173
+
174
+
175
+ ### Free Start Compute
176
+
177
+ ```javascript
178
+
179
+ // Let's have 5 minute of compute access
180
+ const mytime = new Date()
181
+ const computeMinutes = 5
182
+ mytime.setMinutes(mytime.getMinutes() + computeMinutes)
183
+
184
+ // Let's prepare the dataset and algorithm assets to be used in the compute job
185
+ const assets: ComputeAsset[] = [
186
+ {
187
+ documentId: resolvedDatasetDdo.id,
188
+ serviceId: resolvedDatasetDdo.services[0].id
189
+ }
190
+ ]
191
+
192
+ const algo: ComputeAlgorithm = {
193
+ documentId: resolvedAlgorithmDdo.id,
194
+ serviceId: resolvedAlgorithmDdo.services[0].id,
195
+ meta: resolvedAlgorithmDdo.metadata.algorithm
196
+ }
197
+
198
+ // Let's start the free compute job
199
+ const computeJobs = await ProviderInstance.freeComputeStart(
200
+ providerUrl,
201
+ consumerAccount,
202
+ computeEnv.id,
203
+ assets,
204
+ algo
205
+ )
206
+
207
+ ```
208
+
209
+ ### Paid Start Compute
210
+
211
+
212
+ ```javascript
213
+
214
+
215
+ const mytime = new Date()
216
+ const computeMinutes = 5
217
+ mytime.setMinutes(mytime.getMinutes() + computeMinutes)
218
+ const computeValidUntil = Math.floor(mytime.getTime() / 1000)
219
+
220
+ const resources: ComputeResourceRequest[] = [
221
+ {
222
+ id: 'cpu',
223
+ amount: 2
224
+ },
225
+ {
226
+ id: 'ram',
227
+ amount: 1000000000
228
+ },
229
+ {
230
+ id: 'disk',
231
+ amount: 0
232
+ }
233
+ ]
234
+ const assets: ComputeAsset[] = [
235
+ {
236
+ documentId: resolvedDatasetDdo.id,
237
+ serviceId: resolvedDatasetDdo.services[0].id
238
+ }
239
+ ]
240
+ const dtAddressArray = [resolvedDatasetDdo.services[0].datatokenAddress]
241
+ const algo: ComputeAlgorithm = {
242
+ documentId: resolvedAlgorithmDdo.id,
243
+ serviceId: resolvedAlgorithmDdo.services[0].id,
244
+ meta: resolvedAlgorithmDdo.metadata.algorithm
245
+ }
246
+
247
+ const providerInitializeComputeResults = await ProviderInstance.initializeCompute(
248
+ assets,
249
+ algo,
250
+ computeEnv.id,
251
+ paymentToken,
252
+ computeValidUntil,
253
+ providerUrl,
254
+ consumerAccount,
255
+ resources,
256
+ Number(chainId)
257
+ )
258
+ // Initialize payment contract
259
+ const escrow = new EscrowContract(
260
+ getAddress(providerInitializeComputeResults.payment.escrowAddress),
261
+ consumerAccount
262
+ )
263
+ const amountToDeposit = (providerInitializeComputeResults.payment.amount * 2).toString()
264
+ await escrow.verifyFundsForEscrowPayment(
265
+ paymentToken,
266
+ computeEnv.consumerAddress,
267
+ await unitsToAmount(consumerAccount, paymentToken, amountToDeposit),
268
+ providerInitializeComputeResults.payment.amount.toString(),
269
+ providerInitializeComputeResults.payment.minLockSeconds.toString(),
270
+ '10'
271
+ )
272
+
273
+ algo.transferTxId = await handleOrder(
274
+ providerInitializeComputeResults.algorithm,
275
+ resolvedAlgorithmDdo.services[0].datatokenAddress,
276
+ consumerAccount,
277
+ computeEnv.consumerAddress,
278
+ 0
279
+ )
280
+ for (let i = 0; i < providerInitializeComputeResults.datasets.length; i++) {
281
+ assets[i].transferTxId = await handleOrder(
282
+ providerInitializeComputeResults.datasets[i],
283
+ dtAddressArray[i],
284
+ consumerAccount,
285
+ computeEnv.consumerAddress,
286
+ 0
287
+ )
288
+ }
289
+
290
+ const computeJobs = await ProviderInstance.computeStart(
291
+ providerUrl,
292
+ consumerAccount,
293
+ computeEnv.id,
294
+ assets,
295
+ algo,
296
+ computeValidUntil,
297
+ paymentToken,
298
+ resources,
299
+ Number(chainId)
300
+ )
301
+ ```
302
+
303
+ ### Get compute job status
304
+
305
+ ```javascript
306
+
307
+ const jobStatus = await ProviderInstance.computeStatus(
308
+ providerUrl,
309
+ await consumerAccount.getAddress(),
310
+ computeJobId
311
+ )
312
+ ```
313
+
314
+ ### Get download compute results URL
315
+
316
+ ```javascript
317
+
318
+ const downloadURL = await ProviderInstance.getComputeResultUrl(
319
+ providerUrl,
320
+ consumerAccount,
321
+ computeJobId,
322
+ 0
323
+ )
324
+
325
+
326
+ ```
package/CodeExamples.md CHANGED
@@ -66,7 +66,7 @@ cat > marketplace.js
66
66
  Install dependencies running the following command in your terminal:
67
67
 
68
68
  ```bash
69
- npm install @oceanprotocol/lib crypto-js ethers@5.7.2 typescript @types/node ts-node
69
+ npm install @oceanprotocol/lib crypto-js ethers
70
70
  ```
71
71
 
72
72
  ## 4. Import dependencies and add variables and constants
@@ -106,7 +106,7 @@ node dist/compute.js
106
106
  Install dependencies running the following command in your terminal:
107
107
 
108
108
  ```bash
109
- npm install @oceanprotocol/lib crypto-js ethers@5.7.2 typescript @types/node ts-node
109
+ npm install @oceanprotocol/lib crypto-js ethers
110
110
  ```
111
111
 
112
112
  ## 4. Import dependencies and add variables, constants and helper methods
@@ -792,7 +792,7 @@ let's select compute environment which have free and paid resources
792
792
  },
793
793
  {
794
794
  id: 'ram',
795
- amount: 1000000000
795
+ amount: 2
796
796
  },
797
797
  {
798
798
  id: 'disk',