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

GITBOOK-233: ocean.js section

This commit is contained in:
Bogdan Fazakas 2023-05-26 11:50:44 +00:00 committed by gitbook-bot
parent afcd485bed
commit ca0cc85ec1
No known key found for this signature in database
GPG Key ID: 07D2180C7B12D0FF
23 changed files with 454 additions and 523 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 77 KiB

View File

Before

Width:  |  Height:  |  Size: 1.4 MiB

After

Width:  |  Height:  |  Size: 1.4 MiB

View File

@ -1,6 +1,6 @@
---
description: Help for wherever you are on your Ocean Protocol journey.
cover: .gitbook/assets/cover/contribute (1) (1).png
cover: .gitbook/assets/cover/contribute (1).png
coverY: 0
layout: landing
---

View File

@ -55,12 +55,13 @@
* [Install](developers/ocean.py/install.md)
* [Publish flow](developers/ocean.py/publish-flow.md)
* [Consume flow](developers/ocean.py/consume-flow.md)
* [Ocean Libraries](developers/ocean-libraries/README.md)
* [Configuration](developers/using-ocean-libraries/configuration.md)
* [Creating a data NFT](developers/using-ocean-libraries/creating-datanft.md)
* [Publish with Fixed Pricing](developers/using-ocean-libraries/create-datatoken-with-fixed-pricing.md)
* [Mint Datatokens](developers/using-ocean-libraries/mint-datatoken.md)
* [Update Metadata](developers/using-ocean-libraries/update-metadata.md)
* [Ocean.js](developers/ocean.js/README.md)
* [Configuration](developers/ocean.js/configuration.md)
* [Creating a data NFT](developers/ocean.js/creating-datanft.md)
* [Publish](developers/ocean.js/publish.md)
* [Mint Datatokens](developers/ocean.js/mint-datatoken.md)
* [Update Metadata](developers/ocean.js/update-metadata.md)
* [Remove Asset](developers/ocean.js/remove-asset.md)
* [Compute to data](developers/compute-to-data/README.md)
* [Architecture](developers/compute-to-data/compute-to-data-architecture.md)
* [Datasets & Algorithms](developers/compute-to-data/compute-to-data-datasets-algorithms.md)

View File

@ -15,7 +15,7 @@ Congratulations on making it this far! If you've arrived here, you're ready to e
With Ocean, crypto wallets transform into magical data wallets, where your data can roam freely and securely. Crypto exchanges? Well, they've taken on a new role as data marketplaces, where you can showcase and trade your valuable data treasures. And hold on tight because DAOs are here to create epic data co-ops, where collaboration and innovation reign supreme! 🤝
But hold on tight, because we have even more in store for you! With Ocean Protocol, you gain access to a treasure trove of tools that will unlock your data scientist superpowers and allow you to unleash your creativity. Whether you're a Python aficionado or a JavaScript maestro, we have you covered with [ocean.py](ocean.py/) and [ocean.js](ocean-libraries/) libraries. So, get ready to dive into the depths of data innovation and create the next groundbreaking dAapp (that's a decentralized App, by the way) using [ocean.js's](ocean-libraries/) powerful capabilities or unleash your skills with [ocean.py](ocean.py/). It's time to shake up the data world like never before! 🌐🚀
But hold on tight, because we have even more in store for you! With Ocean Protocol, you gain access to a treasure trove of tools that will unlock your data scientist superpowers and allow you to unleash your creativity. Whether you're a Python aficionado or a JavaScript maestro, we have you covered with [ocean.py](ocean.py/) and [ocean.js](broken-reference) libraries. So, get ready to dive into the depths of data innovation and create the next groundbreaking dAapp (that's a decentralized App, by the way) using [ocean.js's](broken-reference) powerful capabilities or unleash your skills with [ocean.py](ocean.py/). It's time to shake up the data world like never before! 🌐🚀
<figure><img src="../.gitbook/assets/developers.png" alt=""><figcaption><p>Ocean Protocol Explorer</p></figcaption></figure>

View File

@ -21,9 +21,9 @@ Above the smart contracts, you'll find essential [libraries](architecture.md#lib
#### Libraries
These libraries include [Ocean.js](ocean-libraries/), a JavaScript library, and [Ocean.py](ocean.py/), a Python library. They serve as powerful tools for developers, enabling integration and interaction with the protocol.
These libraries include [Ocean.js](broken-reference), a JavaScript library, and [Ocean.py](ocean.py/), a Python library. They serve as powerful tools for developers, enabling integration and interaction with the protocol.
1. [Ocean.js](ocean-libraries/): Ocean.js is a JavaScript library that serves as a powerful tool for developers looking to integrate their applications with the Ocean Protocol ecosystem. Designed to facilitate interaction with the protocol, Ocean.js provides a comprehensive set of functionalities, including data tokenization, asset management, and smart contract interaction. Ocean.js simplifies the process of implementing data access controls, building data marketplaces, and exploring data sets within a decentralized environment.&#x20;
1. [Ocean.js](broken-reference): Ocean.js is a JavaScript library that serves as a powerful tool for developers looking to integrate their applications with the Ocean Protocol ecosystem. Designed to facilitate interaction with the protocol, Ocean.js provides a comprehensive set of functionalities, including data tokenization, asset management, and smart contract interaction. Ocean.js simplifies the process of implementing data access controls, building data marketplaces, and exploring data sets within a decentralized environment.&#x20;
2. [Ocean.py](ocean.py/): Ocean.py is a Python library that empowers developers to integrate their applications with the Ocean Protocol ecosystem. With its rich set of functionalities, Ocean.py provides a comprehensive toolkit for interacting with the protocol. Developers and [data scientists](../data-science/) can leverage Ocean.py to perform a wide range of tasks, including data tokenization, asset management, and smart contract interactions. This library serves as a bridge between Python and the decentralized world of Ocean Protocol, enabling you to harness the power of decentralized data.
#### Middleware components

View File

@ -1,18 +0,0 @@
# 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.js) | [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.
Watch our **Ocean.py Playlist of video tutorials** here:
{% embed url="https://www.youtube.com/playlist?list=PL_dn0wVs9kWoM-PMVt78Gkb7BFwlE_njK" %}

View File

@ -0,0 +1,15 @@
---
description: >-
JavaScript library to privately & securely publish, exchange, and consume
data.
---
# Ocean.js
With ocean.js, you can:
* **Publish** data services: downloadable files or compute-to-data. Create an ERC721 **data NFT** for each service, and ERC20 **datatoken** for access (1.0 datatokens to access).
* **Sell** datatokens for a fixed price. Sell data NFTs.
* **Transfer** data NFTs & datatokens.
Ocean.js is part of the [Ocean Protocol](https://oceanprotocol.com) toolset.

View File

@ -28,7 +28,7 @@ In the working directory create a `.env` file. The content of this file will sto
| 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 |
| **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 |
@ -52,7 +52,7 @@ PRIVATE_KEY=<secret>
# Optional environment variables
AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.mainnet.oceanprotocol.com
PROVIDER_URL=https://v4.provider.oceanprotocol.com
```
{% endcode %}
{% endtab %}
@ -69,7 +69,7 @@ PRIVATE_KEY=<secret>
# Optional environment variables
AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.polygon.oceanprotocol.com
PROVIDER_URL=https://v4.provider.oceanprotocol.com
```
{% endcode %}
{% endtab %}
@ -90,63 +90,71 @@ 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._
Replace `<replace this>` with the appropriate values. \*\*You can see all the networks configuration on Oceanjs' [config helper](https://github.com/oceanprotocol/ocean.js/blob/main/src/config/ConfigHelper.ts#L42).
### Setup dependencies
In this step the required dependencies will be installed.
In this step all required dependencies will be installed.
### Installation & Usage
Let's install Oceanjs library into your current project by running:
{% tabs %}
{% tab title="ocean.js" %}
{% tab title="Terminal" %}
```bash
npm init
npm install @oceanprotocol/lib@latest dotenv web3 @truffle/hdwallet-provider
```
{% endtab %}
{% tab title="ocean.py" %}
```bash
python3 -m venv venv
source venv/bin/activate
pip install wheel
# Install Ocean library. Allow pre-releases to get the latest v4 version.
pip install ocean-lib
npm i @oceanprotocol/lib@3.0.0-next.5 dotenv crypto-js ethers@5.7.4 @truffle/hdwallet-provider
```
{% endtab %}
{% endtabs %}
### 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.
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 an 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" %}
{% tab title="config.js" %}
{% code title="config.js" %}
```javascript
// Import dependencies
require('dotenv').config();
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const { homedir } = require('os');
const { ConfigHelper } = require('@oceanprotocol/lib');
const { Aquarius, ZERO_ADDRESS, ConfigHelper, configHelperNetworks } = require('@oceanprotocol/lib');
const { providers } = require('ethers')
const ethers = require('ethers');
async function oceanConfig(){
// Get configuration for the given network
let oceanConfig = new ConfigHelper().getConfig(process.env.OCEAN_NETWORK);
// Get configuration for the given network
const provider = new providers.JsonRpcProvider(
process.env.OCEAN_NETWORK_URL || configHelperNetworks[1].nodeUri
)
// If using local development environment, read the addresses from local file.
// The local deployment address file can be generated using barge.
if (process.env.OCEAN_NETWORK === 'development') {
const addressData = JSON.parse(
const ethersProvider = new ethers.Wallet(
process.env.PRIVATE_KEY,
provider
);
const publisherAccount = await ethersProvider.provider.getSigner(ethersProvider.address);
const consumerAccount = publisherAccount
const stakerAccount = publisherAccount
let oceanConfig = new ConfigHelper().getConfig(
parseInt(String((await provider.getSigner(0).provider.getNetwork()).chainId))
)
const aquarius = new Aquarius(oceanConfig?.metadataCacheUri)
// If using local development environment, read the addresses from local file.
// The local deployment address file can be generated using barge.
if (process.env.OCEAN_NETWORK === 'development') {
const addresses = JSON.parse(
// eslint-disable-next-line security/detect-non-literal-fs-filename
fs.readFileSync(
process.env.ADDRESS_FILE
|| `${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
process.env.ADDRESS_FILE ||
`${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
'utf8'
)
);
const addresses = addressData[process.env.OCEAN_NETWORK];
).development
oceanConfig = {
...oceanConfig,
@ -154,58 +162,30 @@ if (process.env.OCEAN_NETWORK === 'development') {
poolTemplateAddress: addresses.poolTemplate,
fixedRateExchangeAddress: addresses.FixedPrice,
dispenserAddress: addresses.Dispenser,
erc721FactoryAddress: addresses.ERC721Factory,
nftFactoryAddress: addresses.ERC721Factory,
sideStakingAddress: addresses.Staking,
opfCommunityFeeCollector: addresses.OPFCommunityFeeCollector
};
}
}
oceanConfig = {
oceanConfig = {
...oceanConfig,
nodeUri: process.env.OCEAN_NETWORK_URL,
// Set optional properties - Provider URL and Aquarius URL
metadataCacheUri: process.env.AQUARIUS_URL || oceanConfig.metadataCacheUri,
providerUri: process.env.PROVIDER_URL || oceanConfig.providerUri
};
publisherAccount: publisherAccount,
consumerAccount: consumerAccount,
stakerAccount: stakerAccount,
aquarius: aquarius,
ethersProvider: ethersProvider,
};
const web3Provider = new HDWalletProvider(
process.env.PRIVATE_KEY,
oceanConfig.nodeUri
);
return oceanConfig
};
module.exports = {
web3Provider,
oceanConfig
};
```
{% endcode %}
{% endtab %}
{% tab title="ocean.py" %}
{% code title="config.py" %}
```python
import os
from dotenv import load_dotenv
from ocean_lib.example_config import get_config_dict
from ocean_lib.web3_internal.utils import connect_to_network
from ocean_lib.ocean.ocean import Ocean
load_dotenv()
# Create Ocean instance
network_name = os.getenv("OCEAN_NETWORK")
connect_to_network(network_name)
config = get_config_dict(network_name)
ocean = Ocean(config)
from brownie.network import accounts
accounts.clear()
user_private_key = os.getenv('PRIVATE_KEY')
wallet = accounts.add(user_private_key)
}
```
{% endcode %}
{% endtab %}
{% endtabs %}
Now, all the dependencies are ready and you can proceed with interacting with Ocean infrastructure using Ocean libraries.
Now you have set up the necessary files and configurations to interact with Ocean Protocol's smart contracts using ocean.js. You can proceed with further tutorials or development using these configurations.

View File

@ -0,0 +1,78 @@
# Creating a data NFT
This tutorial guides you through the process of creating your own data NFT using Ocean libraries. To know more about data NFT please refer [this page](../../core-concepts/datanft-and-datatoken.md).
#### Prerequisites
* [Obtain an API key](configuration.md)
* [Set up the .env file](configuration.md)
* [Install the dependencies](configuration.md)
* [Create a configuration file](configuration.md)
#### Create a script to deploy dataNFT
The provided script demonstrates how to create a data NFT using Oceanjs.&#x20;
First, create a new file in the working directory, alongside the `config.js` and `.env` files. Name it `create_dataNFT.js` (or any appropriate name). Then, copy the following code into the new created file:
{% tabs %}
{% tab title="create_dataNFT.js" %}
{% code title="create_dataNFT.js" %}
```javascript
// Note: Make sure .env file and config.js are created and setup correctly
const { oceanConfig } = require('./config.js');
const { ZERO_ADDRESS, NftFactory } = require ('@oceanprotocol/lib');
// Deinfe a function which will create a dataNFT using Ocean.js library
const createDataNFT = async () => {
let config = await oceanConfig();
// Create a NFTFactory
const factory = new NftFactory(config.nftFactoryAddress, config.publisherAccount);
const publisherAccount = await config.publisherAccount.getAddress();
// Define dataNFT parameters
const nftParams = {
name: '72120Bundle',
symbol: '72Bundle',
// Optional parameters
templateIndex: 1,
tokenURI: 'https://example.com',
transferable: true,
owner: publisherAccount
};
const bundleNFT = await factory.createNFT(nftParams);
const trxReceipt = await bundleNFT.wait()
return {
trxReceipt
};
};
// Call the create createDataNFT() function
createDataNFT()
.then(({ nftAddress }) => {
console.log(`DataNft address ${nftAddress}`);
process.exit();
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
Run script:
```bash
node create_dataNFT.js
```
{% endtab %}
{% endtabs %}
* Checkout our [code examples](https://github.com/oceanprotocol/ocean.js/blob/main/CodeExamples.md#L0-L1) or [compute to data examples](https://github.com/oceanprotocol/ocean.js/blob/main/ComputeExamples.md#L417) to see how you can use ocean.js.
* If you have any difficulties or if you have further questions about how to use ocean.js please reach out to us on [Discord](https://discord.gg/TnXjkR5).
* If you notice any bugs or issues with ocean.js please [open an issue on github](https://github.com/oceanprotocol/ocean.js/issues/new?assignees=\&labels=bug\&template=bug\_report.md\&title=).
* Visit the [Ocean Protocol website](https://docs.oceanprotocol.com/) for general information about Ocean Protocol.

View File

@ -0,0 +1,85 @@
# Mint Datatokens
This tutorial guides you through the process of minting datatokens and sending them to a receiver address. The tutorial assumes that you already have the address of the datatoken contract which is owned by you.
#### Prerequisites
* [Obtain an API key](broken-reference)
* [Set up the .env file](broken-reference)
* [Install the dependencies](broken-reference)
* [Create a configuration file](configuration.md)
#### Create a script to mint datatokens
Create a new file in the same working directory where configuration file (`config.js`) and `.env` files are present, and copy the code as listed below.
{% tabs %}
{% tab title="mint_datatoken.js" %}
{% code title="mint_datatoken.js" %}
```javascript
// Note: Make sure .env file and config.js are created and setup correctly
const { oceanConfig } = require('./config.js');
const { amountToUnits } = require ('@oceanprotocol/lib');
const ethers = require('ethers');
// Define a function createFRE()
const createMINT = async () => {
let config = await oceanConfig();
const publisher = config.publisherAccount
const publisherAccount = await config.publisherAccount.getAddress()
const minAbi = [
{
constant: false,
inputs: [
{ name: 'to', type: 'address' },
{ name: 'value', type: 'uint256' }
],
name: 'mint',
outputs: [{ name: '', type: 'bool' }],
payable: false,
stateMutability: 'nonpayable',
type: 'function'
}
]
const tokenContract = new ethers.Contract(config.oceanTokenAddress, minAbi, publisher)
const estGasPublisher = await tokenContract.estimateGas.mint(
publisherAccount,
amountToUnits(null, null, '1000', 18)
)
const trxReceipt = await sendTx(
estGasPublisher,
publisher,
1,
tokenContract.mint,
publisherAccount,
amountToUnits(null, null, '1000', 18)
)
return {
trxReceipt
};
};
// Call the createFRE() function
createMINT()
.then(({ trxReceipt }) => {
console.log(`TX Receipt ${trxReceipt}`);
process.exit(1);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
**Execute script**
```
node mint_datatoken.js
```
{% endtab %}
{% endtabs %}

View File

@ -0,0 +1,190 @@
# Publish
This tutorial guides you through the process of creating your own data NFT and a datatoken using Ocean libraries. To know more about data NFTs and datatokens please refer [this page](../datanft-and-datatoken.md). Ocean Protocol supports different pricing schemes which can be set while publishing an asset. Please refer [this page](../asset-pricing.md) for more details on pricing schemes.
#### Prerequisites
* [Obtain an API key](broken-reference)
* [Set up the .env file](broken-reference)
* [Install the dependencies](broken-reference)
* [Create a configuration file](configuration.md)
#### Create a script to deploy a data NFT and datatoken with the price schema you chose.
Create a new file in the same working directory where configuration file (`config.js`) and `.env` files are present, and copy the code as listed below.
{% hint style="info" %}
**Fees**: The code snippets below define fees related parameters. Please refer [fees page ](../../core-concepts/fees.md)for more details
{% endhint %}
The code utilizes methods such as `NftFactory` and `Datatoken` from the Ocean libraries to enable you to interact with the Ocean Protocol and perform various operations related to data NFTs and datatokens.&#x20;
The `createFRE()` performs the following:
1. Creates a web3 instance with [Web3](https://web3js.readthedocs.io/en/v1.10.0/).
2. Retrieves the accounts from the web3 instance and sets the publisher.
3. Defines parameters for the data NFT, including name, symbol, template index, token URI, transferability, and owner.
4. Defines parameters for the datatoken, including name, symbol, template index, cap, fee amount, payment collector address, fee token address, minter, and multi-party fee address.
5. Defines parameters for the price schema, including the fixed rate address, base token address, owner, market fee collector, base token decimals, datatoken decimals, fixed rate, market fee, and optional parameters.
6. Uses the NftFactory to create a data NFT and datatoken with the fixed rate exchange, using the specified parameters.
7. Retrieves the addresses of the data NFT and datatoken from the result.
8. Returns the data NFT and datatoken addresses.
{% tabs %}
{% tab title="create_datatoken_with_fre.js" %}
{% code title="create_datatoken_with_fre.js" %}
```javascript
// Note: Make sure .env file and config.js are created and setup correctly
const { oceanConfig } = require('./config.js');
const { ZERO_ADDRESS, NftFactory } = require ('@oceanprotocol/lib');
// Define a function createFRE()
const createFRE = async () => {
const FRE_NFT_NAME = 'Datatoken 2'
const FRE_NFT_SYMBOL = 'DT2'
let config = await oceanConfig();
// Create a NFTFactory
const factory = new NftFactory(config.nftFactoryAddress, config.publisherAccount);
const nftParams = {
name: FRE_NFT_NAME,
symbol: FRE_NFT_SYMBOL,
templateIndex: 1,
tokenURI: '',
transferable: true,
owner: await config.publisherAccount.getAddress()
}
const datatokenParams = {
templateIndex: 1,
cap: '100000',
feeAmount: '0',
paymentCollector: ZERO_ADDRESS,
feeToken: ZERO_ADDRESS,
minter: await config.publisherAccount.getAddress(),
mpFeeAddress: ZERO_ADDRESS
}
const freParams = {
fixedRateAddress: config.fixedRateExchangeAddress,
baseTokenAddress: config.oceanTokenAddress,
owner: await config.publisherAccount.getAddress(),
marketFeeCollector: await config.publisherAccount.getAddress(),
baseTokenDecimals: 18,
datatokenDecimals: 18,
fixedRate: '1',
marketFee: '0.001',
allowedConsumer: ZERO_ADDRESS,
withMint: true
}
const bundleNFT = await factory.createNftWithDatatokenWithFixedRate(
nftParams,
datatokenParams,
freParams
)
const trxReceipt = await bundleNFT.wait()
return {
trxReceipt
};
};
// Call the createFRE() function
createFRE()
.then(({ trxReceipt }) => {
console.log(`TX Receipt ${trxReceipt}`);
process.exit(1);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
Execute script
```
node create_datatoken_with_fre.js
```
{% endtab %}
{% tab title="create_datatoken_with_free.js" %}
{% code title="create_datatoken_with_free.js" %}
```javascript
// Note: Make sure .env file and config.js are created and setup correctly
const { oceanConfig } = require('./config.js');
const { ZERO_ADDRESS, NftFactory } = require ('@oceanprotocol/lib');
// Define a function createFRE()
const createFRE = async () => {
const DISP_NFT_NAME = 'Datatoken 3'
const DISP_NFT_SYMBOL = 'DT3'
let config = await oceanConfig();
// Create a NFTFactory
const factory = new NftFactory(config.nftFactoryAddress, config.publisherAccount);
const nftParams = {
name: DISP_NFT_NAME,
symbol: DISP_NFT_SYMBOL,
templateIndex: 1,
tokenURI: '',
transferable: true,
owner: await config.publisherAccount.getAddress()
}
const datatokenParams = {
templateIndex: 1,
cap: '100000',
feeAmount: '0',
paymentCollector: ZERO_ADDRESS,
feeToken: ZERO_ADDRESS,
minter: await config.publisherAccount.getAddress(),
mpFeeAddress: ZERO_ADDRESS
}
const dispenserParams = {
dispenserAddress: config.dispenserAddress,
maxTokens: '1',
maxBalance: '1',
withMint: true,
allowedSwapper: ZERO_ADDRESS
}
const bundleNFT = await factory.createNftWithDatatokenWithDispenser(
nftParams,
datatokenParams,
dispenserParams
)
const trxReceipt = await bundleNFT.wait()
return {
trxReceipt
};
};
// Call the createFRE() function
createDispenser()
.then(({ trxReceipt }) => {
console.log(`TX Receipt ${trxReceipt}`);
process.exit(1);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
{% endtab %}
{% endtabs %}
By utilizing these dependencies and configuration settings, the script can leverage the functionalities provided by the Ocean libraries and interact with the Ocean Protocol ecosystem effectively.

View File

@ -0,0 +1,2 @@
# Remove Asset

View File

@ -1,13 +1,13 @@
# 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](../ddo-specification.md) to know more about additional the fields which can be updated.
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.
#### Prerequisites
* [Obtain an API key](configuration.md#obtaining-api-key-for-ethereum-node-provider)
* [Set up the .env file](configuration.md#create-a-.env-file)
* [Install the dependencies](configuration.md#setup-dependencies)
* [Create a configuration file](configuration.md#create-a-configuration-file)
* [Obtain an API key](broken-reference)
* [Set up the .env file](broken-reference)
* [Install the dependencies](broken-reference)
* [Create a configuration file](configuration.md)
{% hint style="info" %}
The variable **AQUARIUS\_URL** and **PROVIDER\_URL** should be set correctly in `.env` file

View File

@ -1,179 +0,0 @@
# Publish with Fixed Pricing
This tutorial guides you through the process of creating your own data NFT and a datatoken with fixed pricing, using Ocean libraries. To know more about data NFTs and datatokens please refer [this page](../datanft-and-datatoken.md). Ocean Protocol supports different pricing schemes which can be set while publishing an asset. Please refer [this page](../asset-pricing.md) for more details on pricing schemes.
#### Prerequisites
* [Obtain an API key](configuration.md#obtaining-api-key-for-ethereum-node-provider)
* [Set up the .env file](configuration.md#create-a-.env-file)
* [Install the dependencies](configuration.md#setup-dependencies)
* [Create a configuration file](configuration.md#create-a-configuration-file)
#### Create a script to deploy data NFT 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.
{% hint style="info" %}
**Fees**: The code snippets below define fees related parameters. Please refer [fees page ](../fees.md)for more details
{% endhint %}
{% tabs %}
{% tab title="ocean.js" %}
{% code title="create_datatoken_with_fre.js" %}
```javascript
// Import dependencies
const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
const Web3 = require('web3');
const { web3Provider, oceanConfig } = require('./config');
// Create a web3 instance
const web3 = new Web3(web3Provider);
// Define a function createFRE()
const createFRE = async () => {
const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3);
// Get accounts from web3 instance
const accounts = await web3.eth.getAccounts();
const publisherAccount = accounts[0];
// data NFT parameters: name, symbol, templateIndex, etc.
const nftParams = {
name: '72120Bundle',
symbol: '72Bundle',
templateIndex: 1,
tokenURI: 'https://example.com',
transferable: true,
owner: publisherAccount
};
// datatoken parameters: name, symbol, templateIndex, etc.
const erc20Params = {
name: "Sample datatoken",
symbol: "SDT",
templateIndex: 1,
cap: '100000',
feeAmount: '0',
// paymentCollector is the address
paymentCollector: '0x0000000000000000000000000000000000000000',
feeToken: '0x0000000000000000000000000000000000000000',
minter: publisherAccount,
mpFeeAddress: '0x0000000000000000000000000000000000000000'
};
const fixedPriceParams = {
fixedRateAddress: oceanConfig.fixedRateExchangeAddress,
baseTokenAddress: oceanConfig.oceanTokenAddress,
owner: publisherAccount,
marketFeeCollector: publisherAccount,
baseTokenDecimals: 18,
datatokenDecimals: 18,
fixedRate: '100',
marketFee: '0',
// Optional parameters
// allowedConsumer: publisherAccount, // only account that consume the exhchange
withMint: false // add FixedPriced contract as minter if withMint == true
}
// Create data NFT and a datatoken with Fixed Rate exchange
const result = await Factory.createNftErc20WithFixedRate(
publisherAccount,
nftParams,
erc20Params,
fixedPriceParams
);
// Get the data NFT address and datatoken address from the result
const erc721Address = result.events.NFTCreated.returnValues[0];
const datatokenAddress = result.events.TokenCreated.returnValues[0];
return {
erc721Address,
datatokenAddress
};
};
// Call the createFRE() function
createFRE()
.then(({ erc721Address, datatokenAddress }) => {
console.log(`DataNft address ${erc721Address}`);
console.log(`Datatoken address ${datatokenAddress}`);
process.exit(1);
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
Execute script
```
node create_datatoken_with_fre.js
```
{% endtab %}
{% tab title="ocean.py" %}
{% code title="create_datatoken_with_fre.py" %}
```python
# Note: Ensure that .env and config.py are correctly setup
from config import web3_wallet, ocean
data_nft = ocean.create_data_nft(
name="NFTToken1",
symbol="NFT1",
from_wallet=web3_wallet,
# Optional parameters
token_uri="https://example.com",
template_index=1,
transferable=True,
owner=web3_wallet.address,
)
print(f"Created dataNFT. Its address is {data_nft.address}")
# replace the addresses here
fee_manager = "0x0000000000000000000000000000000000000000"
publish_market_order_fee_address = "0x0000000000000000000000000000000000000000"
publish_market_order_fee_token = "0x0000000000000000000000000000000000000000"
minter = web3_wallet.address
# replace the fee amount
publish_market_order_fee_amount = 0
datatoken = data_nft.create_datatoken(
name="Datatoken 1",
symbol="DT1",
datatoken_cap="100000",
from_wallet=web3_wallet,
# Ootional parameters below
template_index=1,
fee_manager=fee_manager,
publish_market_order_fee_token=publish_market_order_fee_token,
publish_market_order_fee_amount=publish_market_order_fee_amount,
minter=minter,
publish_market_order_fee_address=publish_market_order_fee_address,
)
print(f"Created datatoken. Its address is {datatoken.address}")
exchange_id = ocean.create_fixed_rate(
datatoken=datatoken,
base_token=ocean.OCEAN_token,
amount=ocean.to_wei(100),
from_wallet=web3_wallet,
)
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,106 +0,0 @@
# Creating a data NFT
This tutorial guides you through the process of creating your own data NFT using Ocean libraries. To know more about data NFT please refer [this page](../datanft-and-datatoken.md).
#### Prerequisites
* [Obtain an API key](configuration.md#obtaining-api-key-for-ethereum-node-provider)
* [Set up the .env file](configuration.md#create-a-.env-file)
* [Install the dependencies](configuration.md#setup-dependencies)
* [Create a configuration file](configuration.md#create-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" %}
```javascript
// Import dependencies
const { NftFactory } = require('@oceanprotocol/lib');
const Web3 = require('web3');
// Note: Make sure .env file and config.js are created and setup correctly
const { web3Provider, oceanConfig } = require('./config');
const web3 = new Web3(web3Provider);
// Deinfe a function which will create a dataNFT using Ocean.js library
const createDataNFT = async () => {
// Create a NFTFactory
const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3);
const accounts = await web3.eth.getAccounts();
const publisherAccount = accounts[0];
// Define dataNFT parameters
const nftParams = {
name: '72120Bundle',
symbol: '72Bundle',
// Optional parameters
templateIndex: 1,
tokenURI: 'https://example.com',
transferable: true,
owner: publisherAccount
};
// Call a Factory.createNFT(...) which will create a new dataNFT
const erc721Address = await Factory.createNFT(
publisherAccount,
nftParams
);
return {
erc721Address
};
};
// Call the create createDataNFT() function
createDataNFT()
.then(({ erc721Address }) => {
console.log(`DataNft address ${erc721Address}`);
process.exit();
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
Executing script
```bash
node create_dataNFT.js
```
{% endtab %}
{% tab title="ocean.py" %}
{% code title="create_dataNFT.py" %}
```python
# Note: Ensure that .env and config.py are correctly setup
from config import web3_wallet, ocean
data_nft = ocean.create_data_nft(
name="NFTToken1",
symbol="NFT1",
from_wallet=web3_wallet,
# Optional parameters
token_uri="https://example.com",
template_index=1,
transferable=True,
owner=web3_wallet.address,
)
print(f"Created dataNFT. Its address is {data_nft.address}")
```
{% endcode %}
Executing script
```bash
python create_dataNFT.py
```
{% endtab %}
{% endtabs %}

View File

@ -1,117 +0,0 @@
# Mint Datatokens
This tutorial guides you through the process of minting datatokens and sending them to a receiver address. The tutorial assumes that you already have the address of the datatoken contract which is owned by you.
#### Prerequisites
* [Obtain an API key](configuration.md#obtaining-api-key-for-ethereum-node-provider)
* [Set up the .env file](configuration.md#create-a-.env-file)
* [Install the dependencies](configuration.md#setup-dependencies)
* [Create a configuration file](configuration.md#create-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" %}
```javascript
// Import dependencies
const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
const Web3 = require('web3');
const { web3Provider, oceanConfig } = require('./config');
// Create a web3 instance
const web3 = new Web3(web3Provider);
// Change this
const datatokenAddress = "0xD3542e5F56655fb818F9118CE219e1D10751BC82"
const receiverAddress = "0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"
// Create a function which will take `datatokenAddress` and `receiverAddress` as parameters
const mintDatatoken = async (datatokenAddress, receiverAddress) => {
const accounts = await web3.eth.getAccounts();
const publisherAccount = accounts[0];
// Create datatoken instance
const datatoken = new Datatoken(web3);
// Get current datatoken balance of receiver
let receiverBalance = await datatoken.balance(
datatokenAddress,
receiverAddress
);
console.log(`Receiver balance before mint: ${receiverBalance}`);
// Mint datatoken
await datatoken.mint(
datatokenAddress,
publisherAccount,
'1',
receiverAddress
);
// Get new datatoken balance of receiver
receiverBalance = await datatoken.balance(
datatokenAddress,
receiverAddress
);
console.log(`Receiver balance after mint: ${receiverBalance}`);
};
// Call mintDatatoken(...) function defined above
mintDatatoken(datatokenAddress, receiverAddress)
.then(() => {
process.exit((err) => {
console.error(err);
process.exit(1);
});
})
.catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
**Execute script**
```
node mint_datatoken.js
```
{% endtab %}
{% tab title="ocean.py" %}
{% code title="mint_datatoken.py" %}
```python
# Note: Ensure that .env and config.py are correctly setup
from config import web3_wallet, ocean
# Change this
datatoken_address = "0xD3542e5F56655fb818F9118CE219e1D10751BC82"
receiver_address = "0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"
datatoken = ocean.get_datatoken(datatoken_address)
print(f"Balance before mint: {datatoken.balanceOf(receiver_address)}")
# Mint datatokens
datatoken.mint(
account_address=receiver_address,
value=ocean.to_wei("1"),
from_wallet=web3_wallet,
)
print(f"Balance after mint: {datatoken.balanceOf(receiver_address)}")
nt_d
```
{% endcode %}
**Execute script**
```
python mint_datatoken.py
```
{% endtab %}
{% endtabs %}

View File

@ -74,7 +74,7 @@ The following guides will help you get started with buying and selling data:
<summary><mark style="color:blue;">Manage datatokens and data NFTs for use in DeFi</mark><br><br>Ocean makes it easy to publish data services (deploy ERC721 data NFTs and ERC20 datatokens), and to consume data services (spend datatokens). Crypto wallets, exchanges, and DAOs become data wallets, exchanges, and DAOs.</summary>
Use Ocean [JavaScript](../developers/ocean-libraries/) or [Python](../developers/ocean.py/) drivers to manage data NFTs and datatokens:
Use Ocean [JavaScript](broken-reference) or [Python](../developers/ocean.py/) drivers to manage data NFTs and datatokens:
Ocean-based apps make data assets on-ramps and off-ramps easy for end users. Ocean smart contracts and libraries make this easy for developers. The data itself does not need to be on-chain, just the access control.

View File

@ -6,7 +6,7 @@ description: Fundamental knowledge of using ERC-20 crypto wallets.
Ocean Protocol users require an ERC-20 compatible wallet to manage their OCEAN and ETH tokens. In this guide, we will provide some recommendations for different wallet options.
<figure><img src="../.gitbook/assets/whats-a-wallet (1).gif" alt=""><figcaption></figcaption></figure>
<figure><img src="../.gitbook/assets/show-wallet.gif" alt=""><figcaption></figcaption></figure>
### What is a wallet?

View File

@ -14,7 +14,7 @@ Liquidity pools and dynamic pricing used to be supported in previous versions of
4\. Go to field `20. balanceOf` and insert your ETH address. This will retrieve your pool share token balance in wei.
<figure><img src="../.gitbook/assets/liquidity/remove-liquidity-2 (1) (1) (2).png" alt=""><figcaption><p>Balance Of</p></figcaption></figure>
<figure><img src="../.gitbook/assets/liquidity/remove-liquidity-2 (1).png" alt=""><figcaption><p>Balance Of</p></figcaption></figure>
5\. Copy this number as later you will use it as the `poolAmountIn` parameter.