Ocean Assets Tech Details

Technical details about OceanAssets functions

Through this class we can publish different types of assets & consume them to make πŸ’²πŸ’²πŸ’²

Creates URL Asset

  • create_url_asset(self, name: str, url: str, publisher_wallet, wait_for_aqua: bool = True ) -> tuple

It is the most used functions in all the READMEs.

Creates asset of type "dataset", having UrlFiles, with good defaults.

It can be called after instantiating Ocean object.

Parameters

  • name - name of the asset, string

  • url - url that is stored in the asset, string

  • publisher_wallet - wallet of the asset publisher/owner, eth Account

  • wait_for_aqua - boolean value which default is True, waiting for aquarius to fetch the asset takes additional time, but if you want to be sure that your asset is indexed, keep the default value.

Returns

tuple

A tuple which contains the data NFT, datatoken and the data asset.

Defined in

ocean/ocean_assets.py

Source code
 @enforce_types
    def create_url_asset(
        self, name: str, url: str, publisher_wallet, wait_for_aqua: bool = True
    ) -> tuple:
        """Create asset of type "data", having UrlFiles, with good defaults"""
        metadata = self._default_metadata(name, publisher_wallet)
        files = [UrlFile(url)]
        return self._create_1dt(metadata, files, publisher_wallet, wait_for_aqua)

Creates Algorithm Asset

  • create_algo_asset(self, name: str, url: str, publisher_wallet, image: str = "oceanprotocol/algo_dockers", tag: str = "python-branin", checksum: str = "sha256:8221d20c1c16491d7d56b9657ea09082c0ee4a8ab1a6621fa720da58b09580e4", wait_for_aqua: bool = True) -> tuple:

Create asset of type "algorithm", having UrlFiles, with good defaults.

It can be called after instantiating Ocean object.

Parameters:

  • name - name of the asset, string

  • url - url that is stored in the asset, string

  • publisher_wallet - wallet of the asset publisher/owner, eth Account

  • image - docker image of that algorithm, string

  • tag - docker tag for that algorithm image, string

  • checksum - docker checksum for algorithm's image, string

  • wait_for_aqua - boolean value which default is True, waiting for aquarius to fetch the asset takes additional time, but if you want to be sure that your asset is indexed, keep the default value.

Returns

tuple

A tuple which contains the algorithm NFT, algorithm datatoken and the algorithm asset.

Defined in

ocean/ocean_assets.py

Source code

Creates Arweave Asset

  • create_arweave_asset(self, name: str, transaction_id: str, publisher_wallet, wait_for_aqua: bool = True) -> tuple

Creates asset of type "data", having ArweaveFile, with good defaults.

It can be called after instantiating Ocean object.

Parameters

  • name - name of the asset, string

  • transaction_id - transaction id from the arweave file, string

  • publisher_wallet - wallet of the asset publisher/owner, eth Account

  • wait_for_aqua - boolean value which default is True, waiting for aquarius to fetch the asset takes additional time, but if you want to be sure that your asset is indexed, keep the default value.

Returns

tuple

A tuple which contains the data NFT, datatoken and the data asset.

Defined in

ocean/ocean_assets.py

Source code

Creates GraphQL Asset

  • create_graphql_asset(self, name: str, url: str, query: str, publisher_wallet, wait_for_aqua: bool = True) -> tuple

Creates asset of type "data", having GraphqlQuery files, with good defaults.

It can be called after instantiating Ocean object.

Parameters

  • name - name of the asset, string

  • url - url of subgraph that you are using, string

  • query - GraphQL query, string

  • publisher_wallet - wallet of the asset publisher/owner, eth Account

  • wait_for_aqua - boolean value which default is True, waiting for aquarius to fetch the asset takes additional time, but if you want to be sure that your asset is indexed, keep the default value.

Returns

tuple

A tuple which contains the data NFT, datatoken and the data asset.

Defined in

ocean/ocean_assets.py

Source code

Creates Onchain Asset

  • create_onchain_asset(self, name: str, contract_address: str, contract_abi: dict, publisher_wallet, wait_for_aqua: bool = True) -> tuple

Creates asset of type "data", having SmartContractCall files, with good defaults.

It can be called after instantiating Ocean object.

Parameters

  • name - name of the asset, string

  • contract_address - contract address that should be stored in the asset, string

  • contract_abi - ABI of functions presented in the contract, string

  • publisher_wallet - wallet of the asset publisher/owner, eth Account

  • wait_for_aqua - boolean value which default is True, waiting for aquarius to fetch the asset takes additional time, but if you want to be sure that your asset is indexed, keep the default value.

Returns

tuple

A tuple which contains the data NFT, datatoken and the data asset.

Defined in

ocean/ocean_assets.py

Source code

Creates Asset (for advanced skills)

  • create(self, metadata: dict, publisher_wallet, credentials: Optional[dict] = None, data_nft_address: Optional[str] = None, data_nft_args: Optional[DataNFTArguments] = None, deployed_datatokens: Optional[List[Datatoken]] = None, services: Optional[list] = None, datatoken_args: Optional[List["DatatokenArguments"]] = None, encrypt_flag: Optional[bool] = True, compress_flag: Optional[bool] = True, wait_for_aqua: bool = True) -> tuple

Register an asset on-chain. Asset = {data_NFT, >=0 datatokens, DDO}

Creating/deploying a DataNFT contract and in the Metadata store (Aquarius).

Parameters

  • metadata: dictionary conforming to the Metadata accepted by Ocean Protocol.

  • publisher_wallet- eth Account of the publisher registering this asset.

  • credentials - credentials dictionary necessary for the asset, which establish who can consume the asset and who cannot.

  • data_nft_address- hex string, the address of the data NFT. The new asset will be associated with this data NFT address.

  • data_nft_args- object of DataNFTArguments type if creating a new one.

  • deployed_datatokens- list of datatokens which are already deployed.

  • services - list of Service objects if you want to run multiple services for a datatoken or you have multiple datatokens with a single service each.

  • datatoken_args - list of objects of DatatokenArguments type if creating a new datatokens.

  • encrypt_flag- bool for encryption of the DDO.

  • compress_flag- bool for compression of the DDO.

  • wait_for_aqua- bool for spending time waiting for DDO to be updated in Aquarius.

Returns

tuple

A tuple which contains the data NFT, datatoken and the data asset.

Defined in

ocean/ocean_assets.py

Source code

Publishing Alternatives

Here are some examples similar to the create() above, but exposes more fine-grained control.

In the same python console:

DDO Encryption or Compression

The DDO is stored on-chain. It's encrypted and compressed by default. Therefore it supports GDPR "right-to-be-forgotten" compliance rules by default.

You can control this during create():

  • To disable encryption, use ocean.assets.create(..., encrypt_flag=False).

  • To disable compression, use ocean.assets.create(..., compress_flag=False).

  • To disable both, use ocean.assetspy.create(..., encrypt_flag=False, compress_flag=False).

Create _just_** a data NFT**

Calling create() like above generates a data NFT, a datatoken for that NFT, and a ddo. This is the most common case. However, sometimes you may want just the data NFT, e.g. if using a data NFT as a simple key-value store. Here's how:

If you call create() after this, you can pass in an argument data_nft_address:string and it will use that NFT rather than creating a new one.

Create a datatoken from a data NFT

Calling create() like above generates a data NFT, a datatoken for that NFT, and a ddo object. However, we may want a second datatoken. Or, we may have started with just the data NFT, and want to add a datatoken to it. Here's how:

If you call create() after this, you can pass in an argument deployed_datatokens:List[Datatoken1] and it will use those datatokens during creation.

Create an asset & pricing schema simultaneously

Ocean Assets allows you to bundle several common scenarios as a single transaction, thus lowering gas fees.

Any of the ocean.assets.create_<type>_asset() functions can also take an optional parameter that describes a bundled pricing schema (Dispenser or Fixed Rate Exchange).

Here is an example involving an exchange:

Updates Asset

  • update(self, ddo: DDO, publisher_wallet, provider_uri: Optional[str] = None, encrypt_flag: Optional[bool] = True, compress_flag: Optional[bool] = True) -> Optional[DDO]

Updates a ddo on-chain.

Parameters

  • ddo - DDO to update

  • publisher_wallet - who published this DDO

  • provider_uri - URL of service provider. This will be used as base to construct the serviceEndpoint for the access (download) service.

  • encrypt_flag - boolean value for encryption the DDO

  • compress_flag - boolean value for compression the DDO

Returns

DDO or None

The updated DDO, or None if updated DDO not found in Aquarius.

Defined in

ocean/ocean_assets.py

Source code

Resolves Asset

  • resolve(self, did: str) -> "DDO"

Resolves the asset from Metadata Cache store (Aquarius).

Parameter

  • did - identifier of the DDO to be searched & resolved in Aquarius

Returns

DDO

Returns DDO instance.

Defined in

ocean/ocean_assets.py

Source code

Searches Assets by Text

  • search(self, text: str) -> list

Searches a DDO by a specific text.

Parameter

  • text - string text to search for assets which include it.

Returns

list

A list of DDOs which have matches with the text provided as parameter.

Defined in

ocean/ocean_assets.py

Source code

Searches Asset by GraphQL Query

  • query(self, query: dict) -> list

Searches a DDO by a specific query.

Parameter

  • query - dictionary type query to search for assets which include it.

Returns

list

A list of DDOs which have matches with the query provided as parameter.

Defined in

ocean/ocean_assets.py

Source code

Downloads Asset

  • download_asset(self, ddo: DDO, consumer_wallet, destination: str, order_tx_id: Union[str, bytes], service: Optional[Service] = None, index: Optional[int] = None, userdata: Optional[dict] = None) -> str

Downloads the asset from Ocean Market.

Parameters

  • ddo - DDO to be downloaded.

  • consumer_wallet - eth Account for the wallet that "ordered" the asset.

  • destination - destination path, as string, where the asset will be downloaded.

  • order_tx_id - transaction ID for the placed order, string and bytes formats are accepted.

Optional parameters

  • service - optionally if you want to provide the Service object through you downloaded the asset.

  • index - optionally if you want to download certain files, not the whole asset, you can specify how many files you want to download as positive integer format.

  • userdata - dictionary additional data from user.

Returns

str

The full path to the downloaded file as string.

Defined in

ocean/ocean_assets.py

Source code

Pays for Access Service

  • pay_for_access_service(self, ddo: DDO, wallet, service: Optional[Service] = None, consume_market_fees: Optional[TokenFeeInfo] = None, consumer_address: Optional[str] = None, userdata: Optional[dict] = None)

Pays for access service by calling initialize endpoint from Provider and starting the order.

Parameters

  • ddo - DDO to be downloaded.

  • wallet- eth Account for the wallet that pays for the asset.

Optional parameters

  • service - optionally if you want to provide the Service object through you downloaded the asset.

  • consume_market_fees - TokenFeeInfo object which contains consume market fee address, amount and token address.

  • consumer_address - address for the consumer which pays for the access.

  • userdata - dictionary additional data from user.

Returns

str

Return value is a hex string for transaction hash which denotes the proof of starting order.

Defined in

ocean/ocean_assets.py

Source code

Pays for Compute Service

  • pay_for_compute_service(self, datasets: List[ComputeInput], algorithm_data: Union[ComputeInput, AlgorithmMetadata], compute_environment: str, valid_until: int, consume_market_order_fee_address: str, wallet, consumer_address: Optional[str] = None)

Pays for compute service by calling initializeCompute endpoint from Provider to retrieve the provider fees and starting the order afterwards.

Parameters

  • datasets - list of ComputeInput objects, each of them includes mandatory the DDO and service.

  • algorithm_data - which can be either a ComputeInput object which contains the whole DDO and service, either provide just the algorithm metadata as AlgorithmMetadata.

  • compute_environment - string that represents the ID from the chosen C2D environment.

  • valid_until - UNIX timestamp which represents until when the algorithm can be used/run.

  • consume_market_order_fee_address - string address which denotes the consume market fee address for that order and can be the wallet address itself.

  • wallet - the eth Account which pays for the compute service

Optional parameters

  • consumer_address - is the string address of the C2D environment consumer.

Returns

tuple

Return value is a tuple composed of list of datasets and algorithm data (if exists in result), (datasets, algorithm_data).

Defined in

ocean/ocean_assets.py

Source code

Last updated

Was this helpful?