react/src/hooks/useConsume
alexcos20 9d9360230c split flows for Publish and Buy 2020-10-14 01:11:49 -07:00
..
README.md update example 2020-10-09 20:42:02 +02:00
index.ts setup project architecture 2020-04-25 02:27:45 +02:00
useConsume.ts split flows for Publish and Buy 2020-10-14 01:11:49 -07:00

README.md

useConsume

Get access to, and download a data asset.

Usage

import React from 'react'
import { useOcean, useConsume } from '@oceanprotocol/react'

const did = 'did:op:0x000000000'

export default function MyComponent() {
  const { accountId } = useOcean()

  // Get metadata for this asset
  const { title, price, ddo } = useMetadata(did)

  // Consume helpers
  const { consume, consumeStep } = useConsume()

  async function handleDownload() {
    await consume(did, ddo.dataToken, 'access')
  }

  return (
    <div>
      <h1>{title}</h1>
      <p>Price: {price}</p>

      <p>Your account: {accountId}</p>
      <button onClick={handleDownload}>
        {consumeStep || 'Download Asset'}
      </button>
    </div>
  )
}