2018-12-05 12:08:47 +01:00
---
2018-12-05 15:01:07 +01:00
title: Publish a Data Set
2018-12-06 10:46:27 +01:00
description: Tutorial to add dataset publishing capabilities to a basic React app.
2018-12-05 12:08:47 +01:00
---
2018-12-05 15:01:07 +01:00
## Requirements
2018-12-05 12:08:47 +01:00
2018-12-05 18:53:28 +01:00
This is a continuation of the [React App Setup ](/tutorials/react-setup ) tutorial, so make sure you have all the steps running.
2018-12-05 12:08:47 +01:00
2018-12-05 15:01:07 +01:00
## Adding Publishing
2018-12-05 17:48:15 +01:00
1. Open `src/App.js` in your marketplace app from the [React App Setup ](/tutorials/react-setup ) tutorial.
2018-12-06 10:46:27 +01:00
2. First let's add the asset that we want to publish. To do that, we need to add the following code after `window.ethereum.enable()` line.
2018-12-05 15:01:07 +01:00
```javascript
const asset = {
base: {
name: 'Office Humidity',
description:
'Weather information of UK including temperature and humidity',
dateCreated: '2012-02-01T10:55:11+00:00',
author: 'Met Office',
size: '3.1bg',
license: 'Public Domain',
copyrightHolder: 'Met Office',
contentUrls: [
'https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip'
],
contentType: 'text/csv',
links: [
{
name: 'Dataset sample',
type: 'sample',
url:
'http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/'
}
],
tags: 'weather, uk, 2011, temperature, humidity',
price: 5,
type: 'dataset'
},
curation: {
rating: 0,
numVotes: 0,
schema: 'Binary Voting'
},
additionalInformation: {
updateFrequency: 'yearly'
}
}
```
2018-12-06 10:46:27 +01:00
3. Now that we have an asset to submit, we need function to handle it. Just before `render() {` let's add:
2018-12-05 15:01:07 +01:00
```javascript
async submitAsset(){
const accounts = await this.ocean.getAccounts()
const ddo = await this.ocean.registerAsset(asset, accounts[0])
alert("Asset successfully submited:", JSON.stringify(ddo))
}
```
2018-12-06 10:46:27 +01:00
4. The last thing we need is a button to start our registration inside the render function just after `<h1>Marketplace app</h1>` :
2018-12-05 15:01:07 +01:00
```jsx
< button onClick = {() = > this.submitAsset()}>Register asset< / button >
```
## Finished
2018-12-05 12:08:47 +01:00
2018-12-06 10:46:27 +01:00
That's it. If you have no errors in your `console.log` and you receive an alert after you click `Register asset` then you have successfully registered an asset.
2018-12-05 12:08:47 +01:00
2018-12-06 10:46:27 +01:00
Here is the full source of `src/App.js` that you should have if you followed this tutorial:
2018-12-05 15:01:07 +01:00
```javascript
import React, { Component } from 'react'
import './App.css'
2018-12-06 10:53:54 +01:00
import { Ocean } from '@oceanprotocol/squid'
2018-12-05 15:01:07 +01:00
import * as Web3 from 'web3'
const web3 = new Web3(window.web3.currentProvider)
window.ethereum.enable()
const asset = {
base: {
name: 'Office Humidity',
description: 'Weather information of UK including temperature and humidity',
dateCreated: '2012-02-01T10:55:11+00:00',
author: 'Met Office',
size: '3.1bg',
license: 'Public Domain',
copyrightHolder: 'Met Office',
contentUrls: [
'https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip'
],
contentType: 'text/csv',
links: [
{
name: 'Dataset sample',
type: 'sample',
url:
'http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/'
2018-12-05 12:08:47 +01:00
}
2018-12-05 15:01:07 +01:00
],
tags: 'weather, uk, 2011, temperature, humidity',
price: 5,
type: 'dataset'
},
curation: {
rating: 0,
numVotes: 0,
schema: 'Binary Voting'
},
additionalInformation: {
updateFrequency: 'yearly'
}
}
class App extends Component {
async componentDidMount() {
this.ocean = await new Ocean.getInstance({
web3Provider: web3,
nodeUri: 'http://localhost:8545',
aquariusUri: 'http://localhost:5000',
brizoUri: 'http://localhost:8030',
parityUri: 'http://localhost:8545',
secretStoreUri: 'http://localhost:12001',
threshold: 0,
password: 'secret',
address: '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0'
})
console.log('Finished loading contracts!')
}
async submitAsset() {
const accounts = await this.ocean.getAccounts()
const ddo = await this.ocean.registerAsset(asset, accounts[0])
alert('Asset successfully submited:', JSON.stringify(ddo))
}
render() {
return (
< div className = "App" >
2018-12-05 17:48:15 +01:00
< h1 > Marketplace app< / h1 >
2018-12-05 15:01:07 +01:00
< button onClick = {() = > this.submitAsset()}>Register asset< / button >
< / div >
)
}
}
export default App
```