Skip to content

Editing

Update your published services

Editing asset metadata

Editing asset metadata can be done in a few steps.

Instantiate AssetBuilder

We use the getAquariusAsset method the fetch the existing metadata of an asset. We use the unique did:op as identifier. The AssetBuilder takes the aquariusAsset as parameter to prepare the editing.

 
import { Wallet, providers } from 'ethers'
import { AssetBuilder, Nautilus } from '@deltadao/nautilus'
 
const provider = new providers.JsonRpcProvider('https://rpc.dev.pontus-x.eu')
const signer = new Wallet('0x...', provider)
const nautilus = await Nautilus.create(signer)
 
const aquariusAsset = await nautilus.getAquariusAsset( 
    'did:op:926098d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308'
) 
 
const assetBuilder = new AssetBuilder(aquariusAsset) 

Using AssetBuilder to edit assetMetadata

When updating an existing asset you only have to set fields you want to change (e.g. the name using setName). After setting the new metadata using the assetBuildermethods, you have to run the build() method to receive an asset object.

const asset = assetBuilder
      .setName('Nautilus edit Example: New name')
      .setAuthor('Author')
      .setDescription(
        '# Asset Description - Markdown supported'
      )
      .build()

Now use the built asset object to call nautilus.edit to apply the changes.

const result = await nautilus.edit(asset)

For a detailed look at the builder class, please refer to the AssetBuilder documentation.

Editing asset access control (credentials)

Editing access control settings ins possible via editing the allow and deny lists. The process is similar to updating any other metadata.

Example: add address to allow list
import { CredentialListTypes } from '@deltadao/nautilus'
 
const asset = assetBuilder  
      .addCredentialAddresses(CredentialListTypes.ALLOW, [  
        '0x0000000000000000000000000000000000000000'
      ]) 
      .build()  
 
const result = await nautilus.edit(asset)

Refer to the addCredentialAddresses() and removeCredentialAddresses api documentations for more information.

Edit asset lifecycle state

You can change the lifecycle state of you asset. This is especially important if you want to revoke a service offering.

Example:
import { LifecycleStates } from '@deltadao/nautilus'
 
const aquariusAsset = await nautilus.getAquariusAsset(
      'did:op:926098d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308'
    )
 
const tx = await nautilus.setAssetLifecycleState(
aquariusAsset,
LifecycleStates.REVOKED_BY_PUBLISHER
)

To learn more about all available lifecycle states, refer to the nautilus.setAssetLifecycleState() API documentation.

Edit service price

Changing the price of a service offering is straight forward. You have to query the aquarius asset via did:op and select the service via serviceId. You have to format the new price as string.

Example:
const aquariusAsset = await nautilus.getAquariusAsset(
    'did:op:926098d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308'
)
 
const serviceId = aquariusAsset.services?.[0]?.id // '41b4f7004149620d9ffbc47e85cca980dda033dd824e0ddf7f9249e02284673b'
const newPrice = '0.1'
 
const txReceipt = await nautilus.setServicePrice(
    aquariusAsset,
    serviceId,
    newPrice
)

Refer to the nautilus.setServicePrice() API documentation for further information.

Editing services

Assets can have multiple services attached. This could useful if you want to offer different versions of a data product or want to have options for different access durations with different pricings.

The process to edit an existing service is not complicated:

  1. Use the nautilus.getAquariusAsset method to get the asset metadata of the asset you want to edit.
  2. Instantiate an AssetBuilder using the aquariusAsset
  3. Instantiate a ServiceBuilder using the aquariusAsset and the id of the service you want to edit (most assets have only one service, which allows to search for index 0 in the services array).
  4. Use methods like setTimeout() to edit the service
  5. Call the build() method of the serviceBuilder
  6. Pass the updated service into the assetBuilder
  7. Call the build() method of the assetBuilder
  8. Call nautilus.edit() with the updated asset as parameter to publish your changes
Example:
import { AssetBuilder, ServiceBuilder } from '@deltadao/nautilus'
 
const aquariusAsset = await nautilus.getAquariusAsset(
    'did:op:926098d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308'
)
const assetBuilder = new AssetBuilder(aquariusAsset)
 
const serviceBuilderConfig = { 
    aquariusAsset, 
    serviceId: aquariusAsset?.services?.[0]?.id // '41b4f7004149620d9ffbc47e85cca980dda033dd824e0ddf7f9249e02284673b'
} 
 
const serviceBuilder = new ServiceBuilder(serviceBuilderConfig) 
 
const service = serviceBuilder 
    .setName('TestServiceName') 
    .setDescription('TestServiceDescription') 
    .setTimeout(1000) 
    .build() 
 
const asset = assetBuilder.addService(service).build() 
 
const result = await nautilus.edit(asset)

Replacing service data sources and access credentials (files)

The files object array holds the access credentials to the data sources. These could be access controlled endpoints our just public URLs.

You can find all supported file types in the official Ocean Protocol docs.

const service = serviceBuilder
    .addFile({
      type: 'url',
      url: 'https://url.to/your/file/endpoint/or/api.csv',
      method: 'GET'
    })
    .build()

Editing the serviceEndpoint (provider - access controller)

const service = serviceBuilder
    .setServiceEndpoint('https://v4.provider.oceanprotocol.com/')
    .addFile({
      type: 'url',
      url: 'https://url.to/your/file/endpoint/or/api.csv',
      method: 'GET'
    })
    .build()

Editing additionalInfo for a specific service

Similar to additionalInfo on asset level you can include any additional info into the service object. You simply pass in any object. Existing values will be overwritten.

const service = serviceBuilder
    .addAdditionalInformation({
    key: 'value',
    number: 6,
    nested: { name: 'nested' }
    })
    .build()

Editing consumerParameter

You use the ConsumerParameterBuilder to build each parameter and attach it to a service via addConsumerParameter.

Editing trusted publishers (for compute assets)

To protect your data it's possible to only allow algorithms from trusted publishers to perform computations on your data.

Adding trusted publishers

import { AssetBuilder, ServiceBuilder } from '@deltadao/nautilus'
 
const aquariusAsset = await nautilus.getAquariusAsset(
    'did:op:926098d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308'
)
const assetBuilder = new AssetBuilder(aquariusAsset)
 
const serviceBuilderConfig = {
    aquariusAsset, 
    serviceId: aquariusAsset?.services?.[0]?.id // '41b4f7004149620d9ffbc47e85cca980dda033dd824e0ddf7f9249e02284673b'
} 
 
const serviceBuilder = new ServiceBuilder(serviceBuilderConfig)
const service = serviceBuilder 
    .addTrustedAlgorithmPublisher('0x96F7e...') 
    .build() 
 
const asset = assetBuilder.addService(service).build() 
 
const result = await nautilus.edit(asset)

Removing trusted publishers

const service = serviceBuilder
    .removeTrustedAlgorithmPublisher('0x96F7e...')
    .build()

Set all publishers trusted

const service = serviceBuilder
    .setAllAlgorithmPublishersTrusted()
    .build()

Set all publishers untrusted

const service = serviceBuilder
    .setAllAlgorithmPublishersUntrusted()
    .build()

Editing trusted algorithms

To protect your data it's possible to only allow algorithms which have passed your security audit.

Adding trusted algorithms

Nautilus will fetch the services on index 0 of the given dids automatically and calculate all needed checksums in the background.

const service = serviceBuilder
    .addTrustedAlgorithms([
    {
        did: 'did:op:221298d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e107'
    },
    {
        did: 'did:op:774398d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e889'
    }
    ])
    .build()

Removing trusted algorithm

const service = serviceBuilder
    .removeTrustedAlgorithm('did:op:475698d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308')
    .build()

Set all algorithms trusted

const service = serviceBuilder
    .setAllAlgorithmsTrusted()
    .build()

Set all algorithms untrusted

const service = serviceBuilder
    .setAllAlgorithmsUntrusted()
    .build()

Allow/Restrict algorithm network access (compute)

Network access settings specify if an algorithm is allowed to call the internet during execution. For data security it's recommended to stay with the default restricted access unless there is a specific reason to change this setting.

Allow:
const service = serviceBuilder.allowAlgorithmNetworkAccess().build()
Restrict:
const service = serviceBuilder.allowAlgorithmNetworkAccess(false).build()

Allow/Restrict raw algorithm (compute)

When set to true, this option permits the execution of raw text input. However, it's important to note that enabling this option elevates the potential for data breaches via malicious user inputs. As a precautionary measure, the default setting for this option is false in all implementations.

Allow:
const service = serviceBuilder.allowRawAlgorithms().build()
Restrict:
const service = serviceBuilder.allowRawAlgorithms(false).build()

Adding an additional service to an Asset (multi-service assets)

Adding an additional service to an asset via editing is similar to publishing. The main differences are that you load the existing aquariusAsset into the AssetBuilder and use the nautilus.edit() method to publish your changes.

import { AssetBuilder, FileTypes, ServiceBuilder, ServiceTypes } from '@deltadao/nautilus'
 
const aquariusAsset = await nautilus.getAquariusAsset( 
    'did:op:926098d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308'
) 
const assetBuilder = new AssetBuilder(aquariusAsset) 
 
const serviceBuilderConfig = {
    serviceType: ServiceTypes.COMPUTE,
    fileType: FileTypes.URL
}
 
const serviceBuilder = new ServiceBuilder(serviceBuilderConfig)
const service = serviceBuilder
    .setServiceEndpoint('https://v4.provider.oceanprotocol.com/')
    .addFile({
      type: 'url',
      url: 'https://url.to/your/file/endpoint/or/api.csv',
      method: 'GET'
    })
    .setTimeout(1000)
    .setPricing({ type: 'free' })
    .build()
 
const asset = assetBuilder.addService(service).build()
 
const result = await nautilus.edit(asset) 

Remove a service from an asset

You can remove a service from your asset if you have an asset with multiple services. You should not remove the last service of an asset. If you want to revoke an asset use the lifecycle states instead.

const aquariusAsset = await nautilus.getAquariusAsset(
    'did:op:926098d069b017dcf3736370f3c3d77e6046ca6622af111229accf5f9c83e308'
)
const assetBuilder = new AssetBuilder(aquariusAsset)
 
const serviceId = aquariusAsset?.services?.[1]?.id // '41b4f7004149620d9ffbc47e85cca980dda033dd824e0ddf7f9249e02284673b'
const asset = assetBuilder.removeService(serviceId).build()