1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00
ocean.js/docs/README_simple_flow.md
Manan Patel 75632372dc
added missing section
Installation section was missing how to install library
2020-07-14 20:56:43 +05:30

2.5 KiB

ocean-lib

ocean-lib-js is a Javascript/Typescript library to privately & securely publish, exchange, and consume data. With it, you can:

  • Publish data services: static data, streaming data, or compute-to-data. Every data service gets its own ERC20 token.
  • Mint data tokens for a given data service
  • Transfer data tokens to another owner
  • Consume data tokens, to access the service

ocean-lib-js is part of the Ocean Protocol toolset.

Installation

npm i --save @oceanprotocol/lib

Usage

// ES6
import { Ocean, Logger } from '@oceanprotocol/lib'

// ES2015
const { Ocean, Logger } = require('@oceanprotocol/lib')

Quickstart

This section describes a flow with the simplest transfer of value, for static data.

Here's the steps.

  1. Alice publishes a dataset (= publishes a datatoken contract)
  2. Alice mints 100 tokens
  3. Alice transfers 1 token to Bob
  4. Bob consumes dataset

Let's go through each of these in detail.

1. Alice publishes a dataset (= publishes a datatoken contract)

For now, you're Alice:) Let's proceed.

Run ganache-cli locally:

ganache-cli

Then proceed in with your code:

const tokenAmount = 100
const transferAmount = 1
const blob = 'http://localhost:8030/api/v1/provider/services'

const alice = await ocean.accounts.list()[0]
const bob = await ocean.accounts.list()[0]
// create datatoken class
const datatoken = new DataTokens(contracts.factoryAddress, factoryABI, datatokensABI, web3)
// deploy datatoken
const tokenAddress = await datatoken.create(blob, alice)

2. Alice hosts the dataset

Clone provider-py and update your local environment variables:

export FLASK_APP=ocean_provider/run.py
export PROVIDER_ADDRESS=your_provider_address
export PROVIDER_KEY=your_provider_key
export CONFIG='{"File": "https://raw.githubusercontent.com/oceanprotocol/barge/master/README.md"}'

3. Alice mints 100 tokens

datatoken.mint(tokenAddress, alice, tokenAmount)

4. Alice transfers 1 token to Bob

const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice)
const transactionId = ts['transactionHash']

5. Bob consumes dataset

Now, you are Bob :)


const config = new Config()        
const ocean = await Ocean.getInstance()

await ocean.assets.download(tokenAddress, blob, transactionId, bob)