Consume flow highlights the methods for getting a datatoken for accessing an asset from Ocean Market and for downloading the content of the asset.
We assumed that you accomplished the publish flow presented previously.
Now let's see how can Bob get access to Alice's asset in order to download/consume it.
Get access for a dataset 🔑
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 Bobdatatoken.mint(bob, to_wei(1), {"from": alice})#Approach B: Alice mints for herself, and transfers to Bobdatatoken.mint(alice, 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 & getsdatatoken.create_dispenser({"from": alice})datatoken.dispense(to_wei(1), {"from": bob})#Approach D: Alice posts for sale; Bob buys# D.1 Alice creates exchangeprice =to_wei(100)exchange = datatoken.create_exchange({"from": alice}, price, ocean.OCEAN_address)# D.2 Alice makes 100 datatokens available on the exchangedatatoken.mint(alice, to_wei(100), {"from": alice})datatoken.approve(exchange.address, to_wei(100), {"from": alice})# D.3 Bob lets exchange pull the OCEAN neededOCEAN_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 datatokenexchange.buy_DT(to_wei(1), consume_market_fee=0, tx_dict={"from": bob})
To "consume" an asset typically means placing an "order", where you pass in 1.0 datatokens and get back a url. Then, you typically download the asset from the url.
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 accessorder_tx_id = ocean.assets.pay_for_access_service(ddo, {"from": bob})# Bob downloads the file. If the connection breaks, Bob can try againasset_dir = ocean.assets.download_asset(ddo, bob, './', order_tx_id)import osfile_name = os.path.join(asset_dir, "file0")
Let's check that the file is downloaded. In a new console:
cdmy_project/datafile.did:op:*catfile0
The beginning of the file should contain the following contents: