Skip to content

Compute to Data

Generate value on data that stays private

The Nautilus instance we created in the setup step provides access to a compute() function that we can use to start new compute jobs. This includes all potentially necessary orders for required datatokens as well as the signed request towards Ocean Provider to start the compute job itself.

Starting a new job

Starting a new compute job can be very quick to achieve. The most basic configuration needs only the identifiers of both the dataset and algorithm.

import { Nautilus } from '@deltadao/nautilus'
import { providers, Wallet } from 'ethers'
 
const provider = new providers.JsonRpcProvider('https://rpc.dev.pontux-x.eu')
const signer = new Wallet('0x...', provider)
 
// create the nautilus instance
const nautilus = await Nautilus.create(signer)
 
const dataset = { 
    did: 'did:op:123abc...'
} 
const algorithm = { 
    did: 'did:op:123abc...'
} 
 
const computeJob = await nautilus.compute({ 
    dataset, 
    algorithm 
}) 

The compute job resulting from this start request can be used in future interactions, for example you can store the specific jobId to reference it later:

const { jobId } = computeJob 

Get a compute job status

Now that you have a reference to any job you started, it is straight forward to monitor the status (see getComputeStatus):

const computeJobStatus = await nautilus.getComputeStatus({
  jobId, // using our extracted jobId
  providerUri: 'https://v4.provider.oceanprotocol.com/'
})

NOTE: The providerUri should be the service endpoint of the datasets service that was computed on. This is where compute jobs are managed and retrieved.

Get compute job results

Once a compute job has finished and you want to access the results (see getComputeResult), this is again very straight forward:

const computeResultUrl = await nautilus.getComputeResult({
  jobId, // use your previously saved jobId
  providerUri // use the provider as described above
})

Same as with access() requests, this will generate a one-time accessible url to retrieve the compute job results. We can use this to then fetch the data itself:

const data = computeResultUrl && await fetch(computeResultUrl)

Deep Dive

For a detailed look into everything possible with the compute APIs, follow the links below: