1
0
mirror of https://github.com/oceanprotocol/docs.git synced 2024-11-26 19:49:26 +01:00

GITBOOK-304: change request with no subject merged in GitBook

This commit is contained in:
mariacarmina.cretu 2023-05-25 13:14:44 +00:00 committed by gitbook-bot
parent c56d976d5d
commit 775849a52c
No known key found for this signature in database
GPG Key ID: 07D2180C7B12D0FF
6 changed files with 106 additions and 11 deletions

BIN
.gitbook/assets/200w.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

BIN
.gitbook/assets/giphy.webp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 245 KiB

View File

@ -54,6 +54,7 @@
* [Ocean.py](developers/ocean.py/README.md) * [Ocean.py](developers/ocean.py/README.md)
* [Install](developers/ocean.py/install.md) * [Install](developers/ocean.py/install.md)
* [Publish flow](developers/ocean.py/publish-flow.md) * [Publish flow](developers/ocean.py/publish-flow.md)
* [Consume flow](developers/ocean.py/consume-flow.md)
* [Ocean Libraries](developers/ocean-libraries/README.md) * [Ocean Libraries](developers/ocean-libraries/README.md)
* [Configuration](developers/using-ocean-libraries/configuration.md) * [Configuration](developers/using-ocean-libraries/configuration.md)
* [Creating a data NFT](developers/using-ocean-libraries/creating-datanft.md) * [Creating a data NFT](developers/using-ocean-libraries/creating-datanft.md)

View File

@ -0,0 +1,101 @@
---
description: This page shows how you can get datatokens & download an asset
---
# Consume flow
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:
```python
from ocean_lib.ocean.util import to_wei
#Approach A: Alice mints datatokens to Bob
datatoken.mint(bob, to_wei(1), {"from": alice})
#Approach B: Alice mints for herself, and transfers to Bob
datatoken.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 & 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
datatoken.mint(alice, 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})
```
For more info, see [Appendix: Dispenser / Faucet Details](https://github.com/oceanprotocol/ocean.py/blob/main/READMEs/main-flow.md#appendix-faucet-details) and [Exchange Details](https://github.com/oceanprotocol/ocean.py/blob/main/READMEs/main-flow.md#appendix-exchange-details).
<figure><img src="../../.gitbook/assets/giphy.webp" alt="" width="199"><figcaption><p>Bob after getting funds</p></figcaption></figure>
### Consume the asset ⬇️
Bob now has the datatoken for the dataset! Time to download the dataset and use it.
<figure><img src="../../.gitbook/assets/200w.webp" alt=""><figcaption></figcaption></figure>
In the same Python console:
```python
# 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
@data
-5.0000,0.0000,308.1291
-3.9286,0.0000,206.1783
...
```
For more info, see [Appendix: Consume Details](https://github.com/oceanprotocol/ocean.py/blob/main/READMEs/main-flow.md#appendix-consume-details).

View File

@ -119,13 +119,12 @@ cd my_project
source venv/bin/activate source venv/bin/activate
``` ```
Then, set keys in readmes. As a Linux user, you'll use "`export`". In the same console: For this tutorial Alice is the publisher of the dataset and Bob is the consumer of the dataset. As a Linux user, you'll use "`export`" for setting the private keys. In the same console:
``` ```
# keys for alice and bob in readmes # keys for alice and bob
export TEST_PRIVATE_KEY1=0x8467415bb2ba7c91084d932276214b11a3dd9bdb2930fefa194b666dd8020b99 export TEST_PRIVATE_KEY1=0x8467415bb2ba7c91084d932276214b11a3dd9bdb2930fefa194b666dd8020b99
export TEST_PRIVATE_KEY2=0x1d751ded5a32226054cd2e71261039b65afb9ee1c746d055dd699b1150a5befc export TEST_PRIVATE_KEY2=0x1d751ded5a32226054cd2e71261039b65afb9ee1c746d055dd699b1150a5befc
export TEST_PRIVATE_KEY3=0x732fbb7c355aa8898f4cff92fa7a6a947339eaf026a08a51f171199e35a18ae0
# key for minting fake OCEAN # key for minting fake OCEAN
@ -176,12 +175,6 @@ bob = accounts.add(bob_private_key)
assert bob.balance() > 0, "Bob needs ETH" assert bob.balance() > 0, "Bob needs ETH"
assert OCEAN.balanceOf(bob) > 0, "Bob needs OCEAN" assert OCEAN.balanceOf(bob) > 0, "Bob needs OCEAN"
carlos_private_key = os.getenv('TEST_PRIVATE_KEY3')
carlos = accounts.add(carlos_private_key)
assert carlos.balance() > 0, "Carlos needs ETH"
assert OCEAN.balanceOf(carlos) > 0, "Carlos needs OCEAN"
# Compact wei <> eth conversion # Compact wei <> eth conversion
from ocean_lib.ocean.util import to_wei, from_wei from ocean_lib.ocean.util import to_wei, from_wei
``` ```

View File

@ -24,8 +24,8 @@ url = "https://raw.githubusercontent.com/trentmc/branin/main/branin.arff"
#print #print
print("Just published asset:") print("Just published asset:")
print(f" data_nft: symbol={data_nft.symbol}, address={data_nft.address}") print(f" data_nft: symbol={data_nft.symbol()}, address={data_nft.address}")
print(f" datatoken: symbol={datatoken.symbol}, address={datatoken.address}") print(f" datatoken: symbol={datatoken.symbol()}, address={datatoken.address}")
print(f" did={ddo.did}") print(f" did={ddo.did}")
``` ```