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

GitBook: [#11] Add text in using Ocean libraries

This commit is contained in:
Akshay Patel 2022-08-02 09:59:29 +00:00 committed by gitbook-bot
parent 8d32b0dfca
commit 7caf885544
No known key found for this signature in database
GPG Key ID: 07D2180C7B12D0FF
6 changed files with 91 additions and 23 deletions

View File

@ -1 +1,14 @@
# Using Ocean libraries
# Using Ocean libraries
Ocean Protocol officially supports two client libraries:
* ocean.js
* ocean.py 
| ocean.js | ocean.py |
| -------------------------------------------------------------- | -------------------------------------------------------------- |
| Written in Javascript | Written in Python |
| [Source code](https://github.com/oceanprotocol/ocean.py) | [Source code](https://github.com/oceanprotocol/ocean.py) |
| [Releases](https://github.com/oceanprotocol/ocean.js/releases) | [Releases](https://github.com/oceanprotocol/ocean.py/releases) |
The tutorials in this section will guide you how to setup the required configuration and interact with Ocean Protocol's smart contracts, Aquarius and Provider using the supported libraries. 

View File

@ -2,9 +2,11 @@
### Obtaining API key for Ethereum node provider
See this [guide](../obtaining-api-key.md) on getting an API key to interact with EVM compatible networks.
Ocean libraries need an Ethereum node provider API key to send transactions to the Ocean Protocol's Smart contracts. See this [guide](../obtaining-api-key.md) on getting an API key to interact with EVM compatible networks. The supported networks are listed [here](../../core-concepts/networks.md).
#### Create a directory
### Create a directory
Let's start with creating a working directory where we store the environment variable file, configuration files and the scripts.
```
mkdir my-ocean-project
@ -13,6 +15,22 @@ cd my-ocean-project
### Create a `.env` file
In the working directory create a \`.env\` file. The content of this file will store the values for following variables:
| Variable name | Description | Required |
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
| **OCEAN\_NETWORK** | Name of the network where the Ocean Protocol's smart contracts are deployed. | Yes |
| **OCEAN\_NETWORK\_URL** | The URL of the Ethereum node (along with API key for non-local networks) | Yes |
| **PRIVATE\_KEY** | The private key of the account which you want to use. A private key is made up of 64 hex characters. Make sure you have sufficient balance to pay for the transaction fees. | Yes |
| **AQUARIUS\_URL** | The URL of the Aquarius. This value is needed when reading an asset from off-chain store. | No |
| **PROVIDER\_URL** | The URL of the Provider. This value is needed when publishing a new asset or update an existing asset. | No |
{% hint style="info" %}
Treat this file as a secret and do not commit this file to git or share the content publicly.
{% endhint %}
The below tabs show partially filled \`.env\` file content for some of the supported networks. 
{% tabs %}
{% tab title="Mainnet" %}
{% code title=".env" %}
@ -64,9 +82,11 @@ PRIVATE_KEY=0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58
{% endtab %}
{% endtabs %}
_NOTE: If using ocean.py, additionally specify **ADDRESS_FILE** variable in the `.env` file. Copy the content of this [link](https://github.com/oceanprotocol/contracts/blob/v4main/addresses/address.json) locally and set the **ADDRESS_FILE** so that its value is a correct file path._
_NOTE: If using ocean.py, additionally specify **ADDRESS\_FILE** variable in the `.env` file. Copy the content of this_ [_link_](https://github.com/oceanprotocol/contracts/blob/v4main/addresses/address.json) _locally and set the **ADDRESS\_FILE** so that its value is a correct file path._
#### Setup dependencies
### Setup dependencies
In this step the required dependencies will be installed.
{% tabs %}
{% tab title="ocean.js" %}
@ -88,7 +108,11 @@ pip3 install ocean-lib python-dotenv web3
{% endtab %}
{% endtabs %}
#### Create a configuration file
### Create a configuration file
A configuration file will read the content of the \`.env\` file and initialize the required configuration objects which will be used in the further tutorials. The below scripts creates a Web3 wallet instance and a Ocean's configuration object.
Create the configuration file in the working directory i.e. at the same path where the \`.env\` is located. 
{% tabs %}
{% tab title="ocean.js" %}
@ -145,11 +169,8 @@ module.exports = {
web3Provider,
oceanConfig
};
```
{% endcode %}
{% endtab %}
{% tab title="ocean.py" %}
@ -173,4 +194,6 @@ web3_wallet = Wallet(ocean.web3, user_private_key, ocean.config.block_confirmati
```
{% endcode %}
{% endtab %}
{% endtabs %}
{% endtabs %}
Now, all the dependencies at ready and you can proceed with interacting with Ocean infrastructure using Ocean libraries.

View File

@ -1,11 +1,15 @@
# Create Datatoken with fixed pricing
This tutorial will guide you for creating your own data NFT and a datatoken using Ocean libraries. To know more about data NFT and datatoken please refer [this page](../../core-concepts/datanft-and-datatoken.md). Ocean Protocol supports different pricing schemes which can be set while publishing an asset. Please refer [this page](../../core-concepts/asset-pricing.md) for more details on pricing schemes.
#### Configuration
See [this](configuration.md) guide on defining a `.env` file and a configuration file
See [this](configuration.md) guide on defining a `.env` file and a configuration file.
#### Create a script to deploy dataNFT and datatoken with fixed pricing.
Create a new file in the same working directory where configuration file (`config.py`/`config.js`) and `.env` files are present, and copy the code as listed below.  
{% tabs %}
{% tab title="ocean.js" %}
{% code title="create_datatoken_with_fre.js" %}
@ -48,7 +52,7 @@ const createDataNFT = async () => {
marketFeeCollector: publisherAccount,
baseTokenDecimals: 18,
datatokenDecimals: 18,
fixedRate: '1',
fixedRate: '100',
marketFee: '0',
allowedConsumer: publisherAccount,
withMint: false
@ -81,9 +85,14 @@ createDataNFT()
console.error(err);
process.exit(1);
});
teatatokfreicreate_datatoken_with_fre.js
```
{% endcode %}
Execute script
```
node create_datatoken_with_fre.js
```
{% endtab %}
{% tab title="ocean.py" %}
@ -120,7 +129,11 @@ print(f"Created fixed rate exchange with ID {exchange_id.hex()}")
```
{% endcode %}
#### Execute script
```
python create_datatoken_with_fre.py
```
{% endtab %}
{% endtabs %}

View File

@ -1,11 +1,15 @@
# Create a dataNFT
# Creating a dataNFT
This tutorial will guide you for creating your own data NFT using Ocean libraries. To know more about data NFT please refer [this page](../../core-concepts/datanft-and-datatoken.md).
#### Configuration
See [this](./configuration.md) guide on defining a `.env` file and a configuration file
See [this](configuration.md) guide on defining a `.env` file and a configuration file.
#### Create a script to deploy dataNFT
Create a new file in the same working directory where configuration file (`config.py`/`config.js`) and `.env` files are present, and copy the code as listed below.  
{% tabs %}
{% tab title="ocean.js" %}
{% code title="create_dataNFT.js" %}
@ -64,10 +68,10 @@ createDataNFT()
{% endcode %}
Executing script
```bash
node create_dataNFT.js
```
{% endtab %}
{% tab title="ocean.py" %}
@ -91,10 +95,9 @@ print(f"Created dataNFT. Its address is {data_nft.address}")
{% endcode %}
Executing script
```bash
python create_dataNFT.py
```
{% endtab %}
{% endtabs %}
{% endtabs %}

View File

@ -1,11 +1,15 @@
# Mint datatoken
This tutorial will guide you to mint datatoken and send it to a receiver address. The tutorial assumes that you already have the address of the datatoken contract which is owned by you. 
#### Configuration
See [this](configuration.md) guide on defining a `.env` file and a configuration file
#### Create a script to mint datatokens
Create a new file in the same working directory where configuration file (`config.py`/`config.js`) and `.env` files are present, and copy the code as listed below.  
{% tabs %}
{% tab title="ocean.js" %}
{% code title="mint_datatoken.js" %}
@ -59,6 +63,12 @@ mintDatatoken(datatokenAddress, receiverAddress)
});
```
{% endcode %}
#### Execute script
```
node mint_datatoken.js
```
{% endtab %}
{% tab title="ocean.py" %}
@ -85,5 +95,11 @@ print(f"Balance after mint: {datatoken.balanceOf(receiver_address)}")
nt_d
```
{% endcode %}
#### Execute script
```
python mint_datatoken.py
```
{% endtab %}
{% endtabs %}

View File

@ -1,11 +1,15 @@
# Update metadata
This tutorial will guide you to update an existing asset published on-chain using Ocean libraries. The tutorial assumes that you already have the `did` of the asset which needs to be updated. In this tutorial, we will update the name, description, tags of the data NFT. Please refer [the page on DDO](../../core-concepts/did-ddo.md) to know more about additional the fields which can be updated.
#### Configuration
See [this](configuration.md) guide on defining a `.env` file and a configuration file
#### Create a script to update the metadata
Create a new file in the same working directory where configuration file (`config.py`/`config.js`) and `.env` files are present, and copy the code as listed below.  
{% tabs %}
{% tab title="ocean.js" %}
{% code title="updateMetadata.js" %}
@ -78,9 +82,5 @@ Execute the script
```bash
node updateMetadata.js
```
{% endtab %}
{% tab title="ocean.py" %}
{% endtab %}
{% endtabs %}