mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix simple flow
This commit is contained in:
parent
0c7e867a47
commit
414445bb77
@ -26,17 +26,17 @@ This is in alpha state and you can expect running into problems. If you run into
|
||||
|
||||
This stripped-down flow shows the essence of Ocean. Just downloading, no metadata.
|
||||
|
||||
[Go to simple flow](README_simple_flow.md)
|
||||
[Go to simple flow](doc/README_simple_flow.md)
|
||||
|
||||
## Quickstart: Marketplace Flow
|
||||
|
||||
This batteries-included flow includes metadata, multiple services for one datatoken, and compute-to-data.
|
||||
|
||||
[Go to marketplace flow](README_marketplace_flow.md)
|
||||
[Go to marketplace flow](doc/README_marketplace_flow.md)
|
||||
|
||||
## For ocean-lib Developers
|
||||
|
||||
[Go to ocean-lib-developers flow](README_ocean-lib-developers.md)
|
||||
[Go to ocean-lib-developers flow](doc/README_ocean-lib-developers.md)
|
||||
|
||||
## License
|
||||
|
||||
|
@ -1,126 +0,0 @@
|
||||
# Quickstart: Marketplace Flow
|
||||
|
||||
This batteries-included flow includes metadata, multiple services for one datatoken, and compute-to-data.
|
||||
|
||||
It focuses on Alice's experience as a publisher, and Bob's experience as a buyer & consumer. The rest are services used by Alice and Bob.
|
||||
|
||||
Here's the steps.
|
||||
1. Initialize services
|
||||
1. Alice publishes assets for data services (= publishes a datatoken contract and metadata)
|
||||
1. Alice mints 100 tokens
|
||||
1. Alice allows marketplace to sell her datatokens
|
||||
1. Marketplace posts asset for sale
|
||||
1. Value swap: Bob buys datatokens from marketplace
|
||||
1. Bob uses a service he just purchased (download)
|
||||
|
||||
Let's go through each step.
|
||||
|
||||
## 0. Installation
|
||||
|
||||
If you haven't installed yet:
|
||||
```console
|
||||
pip install ocean-lib
|
||||
```
|
||||
|
||||
## 1. Initialize services
|
||||
|
||||
This quickstart treats the publisher service, metadata store, and marketplace as
|
||||
externally-run services. For convenience, we run them locally in default settings.
|
||||
|
||||
```
|
||||
docker run @oceanprotocol/provider-py:latest
|
||||
docker run @oceanprotocol/metadatastore:latest
|
||||
docker run @oceanprotocol/marketplace:latest
|
||||
```
|
||||
|
||||
## 2. Alice publishes assets for data services (= publishes a datatoken contract)
|
||||
|
||||
```python
|
||||
from ocean_lib import Ocean
|
||||
from ocean_lib.web3_internal.utils import get_account
|
||||
|
||||
#Alice's config
|
||||
config = {
|
||||
'network' : 'rinkeby',
|
||||
'privateKey' :'8da4ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
||||
'metadataStoreUri' : 'localhost:5000',
|
||||
'providerUri' : 'localhost:8030'
|
||||
}
|
||||
ocean = Ocean(config)
|
||||
account = get_account(0)
|
||||
|
||||
data_token = ocean.create_data_token(ocean.config.metadata_store_url, account)
|
||||
token_address = data_token.address
|
||||
|
||||
metadata = {"main": {
|
||||
"type": "dataset", "name": "10 Monkey Species Small", "author": "Mario",
|
||||
"license": "CC0: Public Domain", "dateCreated": "2012-02-01T10:55:11Z",
|
||||
"files": [{ "index": 0, "contentType": "application/zip", "url": "https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/training.zip"},
|
||||
{ "index": 1, "contentType": "text/text", "url": "https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/monkey_labels.txt"},
|
||||
{ "index": 2, "contentType": "application/zip", "url": "https://s3.amazonaws.com/datacommons-seeding-us-east/10_Monkey_Species_Small/assets/validation.zip"}]}}
|
||||
asset = ocean.assets.create(metadata, account, data_token_address=token_address)
|
||||
assert token_address == asset._other_values['dataTokenAddress']
|
||||
|
||||
did = asset.did
|
||||
```
|
||||
|
||||
## 3. Alice mints 100 tokens
|
||||
|
||||
```python
|
||||
data_token.mint(account.address, 100, account)
|
||||
```
|
||||
|
||||
## 4. Alice allows marketplace to sell her datatokens
|
||||
|
||||
```python
|
||||
marketplace_address = '0x068ed00cf0441e4829d9784fcbe7b9e26d4bd8d0'
|
||||
data_token.approve(marketplace_address, 20)
|
||||
```
|
||||
|
||||
## 5. Marketplace posts asset for sale
|
||||
Now, you're the marketplace:)
|
||||
|
||||
```python
|
||||
from ocean_lib import Ocean
|
||||
|
||||
#Market's config
|
||||
config = {
|
||||
'network': 'rinkeby',
|
||||
'privateKey':'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8f',
|
||||
}
|
||||
market_ocean = Ocean(config)
|
||||
|
||||
asset = ocean.assets.resolve(did)
|
||||
service1 = asset.get_service('download')
|
||||
service2 = asset.get_service('access')
|
||||
price = 10.0 #marketplace-set price of 10 USD / datatoken
|
||||
|
||||
#Display key asset information, such as the cost of each service
|
||||
print(f"Service 1 costs {service1.get_num_dt_needed() * price} USD") # 1.5 * 10 = 15
|
||||
print(f"Service 2 costs {service2.get_num_dt_needed() * price} USD") # 2.5 * 10 = 25
|
||||
```
|
||||
|
||||
## 6. Value swap: Bob buys datatokens from marketplace
|
||||
|
||||
```python
|
||||
#Not shown: in marketplace GUI, Bob uses Stripe to send USD to marketplace (or other methods / currencies).
|
||||
|
||||
market_token = market_ocean.get_data_token(token_address)
|
||||
market_token.transfer(dst_address=bob_address, 1.0)
|
||||
```
|
||||
|
||||
## 7. Bob uses a service he just purchased (download)
|
||||
Now, you're Bob:)
|
||||
|
||||
```python
|
||||
|
||||
#Bob's config
|
||||
config = {
|
||||
'network': 'rinkeby',
|
||||
'privateKey':'1234ef21b864d2cc526dbdb2a120bd2874c36c9d0a1fb7f8c63d7f7a8b41de8o',
|
||||
}
|
||||
market_ocean = Ocean(config)
|
||||
|
||||
service = asset.get_service('access')
|
||||
file_path = bob_ocean.assets.download(asset.did, service.index, bob_account, '~/my-datasets')
|
||||
```
|
@ -1,96 +0,0 @@
|
||||
|
||||
# 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](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) 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](www.oceanprotocol.com) toolset.
|
||||
|
||||
# Installation
|
||||
```
|
||||
// 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)
|
||||
1. Alice mints 100 tokens
|
||||
1. Alice transfers 1 token to Bob
|
||||
1. 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:
|
||||
```bash
|
||||
ganache-cli
|
||||
```
|
||||
|
||||
Then proceed in with your code:
|
||||
```javascript
|
||||
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](https://github.com/oceanprotocol/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
|
||||
|
||||
```javascript
|
||||
datatoken.mint(tokenAddress, alice, tokenAmount)
|
||||
```
|
||||
|
||||
## 4. Alice transfers 1 token to Bob
|
||||
|
||||
```javascript
|
||||
const ts = await datatoken.transfer(tokenAddress, bob, transferAmount, alice)
|
||||
const transactionId = ts['transactionHash']
|
||||
```
|
||||
|
||||
## 5. Bob consumes dataset
|
||||
|
||||
Now, you are Bob :)
|
||||
|
||||
|
||||
```javascript
|
||||
|
||||
const config = new Config()
|
||||
const ocean = await Ocean.getInstance()
|
||||
|
||||
await ocean.assets.download(tokenAddress, blob, transactionId, bob)
|
||||
```
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user