Bidya logo
  Crypto Coin Prices and News  
on the top crypto coins and  
over 21,000 coins and tokens  
Cap | Volume | High | Low | Old | New | Rare | Vs | Blockchains | Exchanges | Market | News | Dev News | Search | Watchlist

Getting Started with, Part 4: Walkthrough

News from the OCEAN Coin Development team on April 14, 2023

Introduction is a Python library to privately & securely publish, exchange, and consume data, using Ocean Protocol.

Part 1 of this series introduced, and described how to install it. Part 2 described how to set up for local testing, and part 3 for remote.

This post is a fun one! We pick up where part 2 & 3 left off, and walk you through the main flow:

In this post, you’ll publish a data asset, post for free / for sale, dispense it / buy it, and consume it. We’ll closely follow’s

Background: Ocean Basics

This post assumes a basic understanding of Ocean data NFTs and datatokens. If you don’t yet know about these, we recommend learning about those first, by text or video.

Main Flow: Video

Here’s a video version this post 👇. Or, jump straight into the text content below.

Main Flow: Text

Steps in the flow:

  1. Alice publishes dataset
  2. Bob gets access to the dataset (faucet, priced, etc)
  3. Bob consumes the dataset

Let’s go!

(Note: this blog post is up-to-date as of Apr 2023, but if 2+ months have passed, we recommend using the READMEs directly for up-to-date instructions. )

1. Alice publishes dataset

Alice! Alice! Who the f*** is Alice?

Well, for the steps below, you are Alice! 👧

In the same Python console:

#data info
name = "Branin dataset"
url = ""

#create data asset
(data_nft, datatoken, ddo) = ocean.assets.create_url_asset(name, url, {"from": alice})

print("Just published asset:")
print(f" data_nft: symbol={data_nft.symbol}, address={data_nft.address}")
print(f" datatoken: symbol={datatoken.symbol}, address={datatoken.address}")
print(f" did={ddo.did}")

You’ve now published an Ocean asset!

  • data_nft is the base (base IP)
  • datatoken for access by others (licensing)
  • ddo holding metadata

(For more info, see Appendix: Publish Details.)

2. Bob gets access to the dataset

If you’ve ever spent time in the world of crypto, or cryptography:

Wherever there’s a Bob, there’s always an Alice

OK, OK. So yes, there’s a Bob. He wants to consume the dataset that Alice just published. The first step is for Bob to get 1.0 datatokens.

Below, we show four possible approaches:

  • A & B are when Alice is in contact with Bob. She can mint directly to him, or mint to herself and transfer to him.
  • C is when Alice wants to share access for free, to anyone
  • D is when Alice wants to sell access

In the same Python console:

from ocean_lib.ocean.util import to_wei

#Approach A: Alice mints datatokens to Bob, to_wei(1), {"from": alice})

#Approach B: Alice mints for herself, and transfers to Bob, to_wei(1), {"from": alice})
datatoken.transfer(bob, to_wei(1), {"from": alice})

#Approach C: Alice posts for free, via a dispenser / faucet; Bob requests & gets
datatoken.create_dispenser({"from": alice})
datatoken.dispense(to_wei(1), {"from": bob})

#Approach D: Alice posts for sale; Bob buys
# D.1 Alice creates exchange
price = to_wei(100)
exchange = datatoken.create_exchange({"from": alice}, price, ocean.OCEAN_address)

# D.2 Alice makes 100 datatokens available on the exchange, to_wei(100), {"from": alice})
datatoken.approve(exchange.address, to_wei(100), {"from": alice})

# D.3 Bob lets exchange pull the OCEAN needed
OCEAN_needed = exchange.BT_needed(to_wei(1), consume_market_fee=0)
ocean.OCEAN_token.approve(exchange.address, OCEAN_needed, {"from":bob})

# D.4 Bob buys datatoken
exchange.buy_DT(to_wei(1), consume_market_fee=0, tx_dict={"from": bob})

You may not realize it, but you just covered a crazy amount of ground!! You just went through four different ways to share data! Minting, transferring, faucets, and selling!

What made this possible is that the access control to the data is tokenized, via datatokens. Then you were basically using the tools of crypto to move those datatokens around.

(For more info, see Appendix: Dispenser / Faucet Details and Exchange Details.)

3. Bob consumes the dataset

Bob now has the datatoken for the dataset! Time to download the dataset and use it.

In the same Python console:

# Bob sends a datatoken to the service to get access
order_tx_id = ocean.assets.pay_for_access_service(ddo, {"from": bob})

# Bob downloads the file. If the connection breaks, Bob can try again
asset_dir = ocean.assets.download_asset(ddo, bob, './', order_tx_id)
import os
file_name = os.path.join(asset_dir, "file0")

Let’s check that the file is downloaded. In a new console:

cd my_project/datafile.did:op:*
cat file0

The beginning of the file should contain the following contents:

% 1. Title: Branin Function
% 3. Number of instances: 225
% 6. Number of attributes: 2
@relation branin
@attribute 'x0' numeric
@attribute 'x1' numeric
@attribute 'y' numeric

(For more info, see Appendix: Consume Details.)

Conclusion / Next Step

You’ve now done a walk-through of the main flow, congrats! As Alice, you published a data asset, posted for free / for sale, and had that Bob guy dispense it / buy it and consume it.

Have questions? Here’s the Ocean Protocol #dev-support channel on Discord. For updates from the Ocean team, follow us on Twitter:)

Getting Started with, Part 4: Walkthrough was originally published in Ocean Protocol on Medium, where people are continuing the conversation by highlighting and responding to this story.

Source     #OCEAN Price

OCEAN vs JASMY | A-Z | Topics | ISO 20022

Privacy | Terms | Contact | Powered By