Publish a Data Set with Compute features

Tutorial to add a dataset with compute capabilities to a basic React app.

Requirements

This is a continuation of the React App Setup tutorial, so make sure you have done all the steps described in there.

  1. React App Setup

Open src/Compute.js from your marketplace/ folder.

Define Asset

We will use the same asset as in Publish a Data Set, but we are going to allow only compute features, without the ability to download the asset.

This is achiveable by adding a ‘compute’ service to the DDO:

      const service = await ocean.compute.createComputeServiceAttributes(
        accounts[0],
        '0',
        '2020-03-10T10:00:00Z'
      )

Handle Asset Publishing

Note that ocean.assets.create will define an ‘access’ service if the services list is missing. Since we are providing this attribute, our asset will have only a ‘compute’ service and no ‘access’ service.

  async function publish() {
    try {
      const accounts = await ocean.accounts.list()
      console.log('Publishing asset.')

      const service = await ocean.compute.createComputeServiceAttributes(
        accounts[0],
        '0',
        '2020-03-10T10:00:00Z'
      )
      console.log(service)
      const ddoAssetNew = await ocean.assets.create(asset, accounts[0], [
        service
      ])
      console.log('Asset successfully submitted.')
      console.log(ddoAssetNew)
      // keep track of this registered asset for consumption later on
      setDdoAssetId(ddoAssetNew.id)
      alert('Asset successfully submitted.')
    } catch (error) {
      console.error(error.message)
    }
  }

The last thing we need is a button to start our registration inside the render() function:

        <button onClick={publish}>Publish dataset with compute service</button>

Move on to Publish a Algorithm.