Now we need a button to start our search inside the render() function, just after the Register asset button:

<hr /><buttononClick={()=>this.searchAssets()}>Search assets</button>

Consume Asset

Consuming means downloading one or multiple files attached to an asset. During that process the initial url value we added during the publish process for each file will be decrpyted and the file can be downloaded.

With the following code we start the consume process with the first search result, then go on to download its first attached file. Put it after the searchAssets() function:

asyncconsumeAsset() {try{// get all accountsconstaccounts=awaitthis.state.ocean.accounts.list()// get first asset from search resultsconstconsumeAsset=this.state.results[0]// get service we want to executeconstservice=consumeAsset.findServiceByType('Access')// order service agreementconstagreement=awaitthis.state.ocean.assets.order(consumeAsset.id,service.serviceDefinitionId,accounts[0] )// consume itawaitthis.state.ocean.assets.consume(agreement,consumeAsset.id,service.serviceDefinitionId,accounts[0],'',0 )}catch (error) {console.error(error.message)}}

We still need a button to start consumption. In the render function, just after the Search assets button, add: