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

Merge pull request #1053 from oceanprotocol/issue-1042-using-ocean-libraries

Using ocean libraries
This commit is contained in:
mihaisc 2022-08-03 06:12:36 -07:00 committed by GitHub
commit 9b04d65ecc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 752 additions and 23 deletions

View File

@ -18,12 +18,18 @@
* [Publish a data asset](using-ocean-market/marketplace-publish-data-asset.md)
* [Download a data asset](using-ocean-market/marketplace-download-data-asset.md)
* [Publishing with hosting services](building-with-ocean/asset-hosting.md)
* [Liquidity Pools [deprecated]](using-ocean-market/remove-liquidity-using-etherscan.md)
* [Liquidity Pools \[deprecated\]](using-ocean-market/remove-liquidity-using-etherscan.md)
* [Building with Ocean](building-with-ocean/README.md)
* [Build a Marketplace](building-with-ocean/build-a-marketplace/README.md)
* [Forking Ocean Market](building-with-ocean/build-a-marketplace/forking-ocean-market.md)
* [Customising your market](building-with-ocean/build-a-marketplace/customising-your-market.md)
* [Deploying your market](building-with-ocean/build-a-marketplace/deploying-market.md)
* [Using Ocean libraries](building-with-ocean/using-ocean-libraries/README.md)
* [Configuration](building-with-ocean/using-ocean-libraries/configuration.md)
* [Creating a data NFT](building-with-ocean/using-ocean-libraries/creating\_dataNFT.md)
* [Create datatoken with fixed pricing](building-with-ocean/using-ocean-libraries/create-datatoken-with-fixed-pricing.md)
* [Mint datatokens](building-with-ocean/using-ocean-libraries/mint-datatoken.md)
* [Update metadata](building-with-ocean/using-ocean-libraries/update-metadata.md)
* [Compute-to-Data](building-with-ocean/compute-to-data/README.md)
* [Architecture](building-with-ocean/compute-to-data/compute-to-data-architecture.md)
* [Datasets & Algorithms](building-with-ocean/compute-to-data/compute-to-data-datasets-algorithms.md)

View File

@ -12,11 +12,7 @@ Aquarius consists of two parts:\
* A server for hosting Aquarius. See [this guide](setup-server.md) on creating a server.
* Docker and Docker compose are installed. Click [here](https://docs.docker.com/engine/install/) to view guide on installing docker.
* Ethereum API. Aquarius uses Ethereum api for monitoring on-chain events.\
Choose any api provider of your choice. Some of the commonly used are:
* [Infura](https://infura.io/)
* [Alchemy](https://www.alchemy.com/)
* [Moralis](https://moralis.io/)
* [Obtain an API key](../using-ocean-libraries/configuration.md#obtaining-api-key-for-ethereum-node-provider)
### Create a working directory

View File

@ -8,11 +8,7 @@ Ocean subgraph allows querying the datatoken, dataNFT, and all event information
* A server for hosting Ocean subgraph. See [this guide](setup-server.md) on creating a server.
* Docker and Docker compose are installed. Click [here](https://docs.docker.com/engine/install/) to view guide on installing docker.
* Ethereum API. Aquarius uses Ethereum api for monitoring on-chain events.\
Choose any api provider of your choice. Some of the commonly used are:
* [Infura](https://infura.io/)
* [Alchemy](https://www.alchemy.com/)
* [Moralis](https://moralis.io/)
* [Obtain an API key](../using-ocean-libraries/configuration.md#obtaining-api-key-for-ethereum-node-provider)
### Create a working directory

View File

@ -2,14 +2,12 @@
### About Provider
Provider encrypts the URL and metadata during publish and decrypts the URL when the dataset is downloaded or a compute job is started. It enables the access to data assets by streaming data (and never the URL). It performs checks on chain for buyer permissions and payments. It also Provides compute services (connects to C2D environment).
The source code of Provider can be access from [here](https://github.com/oceanprotocol/provider).
Provider encrypts the URL and metadata during publish and decrypts the URL when the dataset is downloaded or a compute job is started. It enables the access to data assets by streaming data (and never the URL). It performs checks on chain for buyer permissions and payments. It also Provides compute services (connects to C2D environment). The source code of Provider can be access from [here](https://github.com/oceanprotocol/provider).
### Prerequisites
* Docker and Docker compose are installed. Click [here](https://docs.docker.com/engine/install/) to view guide on installing docker.
* Ethereum API.
See [this](../obtaining-api-key.md) guide on obtaining api key.
* [Obtain an API key](../using-ocean-libraries/configuration.md#obtaining-api-key-for-ethereum-node-provider)
### Create a working directory
@ -22,7 +20,6 @@ cd Provider
Copy the below content into the \`.env\` file and edit the values as needed.
{% code title=".env" %}
```
# Mandatory variables

View File

@ -0,0 +1,14 @@
# Using Ocean libraries
Ocean Protocol officially supports two client libraries:
* ocean.js
* ocean.py
| <b>ocean.js</b> | <b>ocean.py</b> |
| -------------------------------------------------------------- | -------------------------------------------------------------- |
| 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

@ -0,0 +1,207 @@
# Configuration
### Obtaining API key for Ethereum node provider
Ocean Protocol's smart contracts are deployed on EVM-compatible networks. Using an API key provided by a third-party Ethereum node provider allows you to interact with the Ocean Protocol's smart contracts on the supported networks without requiring you to host a local node.
Choose any API provider of your choice. Some of the commonly used are:
* [Infura](https://infura.io/)
* [Alchemy](https://www.alchemy.com/)
* [Moralis](https://moralis.io/)
The supported networks are listed [here](../../core-concepts/networks.md).
### 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
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. If you are using git, then include this file name in `.gitignore` file.
{% endhint %}
The below tabs show partially filled `.env` file content for some of the supported networks.
{% tabs %}
{% tab title="Mainnet" %}
{% code title=".env" %}
```
# Mandatory environment variables
OCEAN_NETWORK=mainnet
OCEAN_NETWORK_URL=<replace this>
PRIVATE_KEY=<secret>
# Optional environment variables
AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.mainnet.oceanprotocol.com
```
{% endcode %}
{% endtab %}
{% tab title="Polygon" %}
{% code title=".env" %}
```
# Mandatory environment variables
OCEAN_NETWORK=polygon
OCEAN_NETWORK_URL=<replace this>
PRIVATE_KEY=<secret>
# Optional environment variables
AQUARIUS_URL=https://v4.aquarius.oceanprotocol.com/
PROVIDER_URL=https://v4.provider.polygon.oceanprotocol.com
```
{% endcode %}
{% endtab %}
{% tab title="Local (using Barge)" %}
{% code title=".env" %}
```
# Mandatory environment variables
OCEAN_NETWORK=development
OCEAN_NETWORK_URL=http://172.15.0.3:8545/
AQUARIUS_URL=http://172.15.0.5:5000
PROVIDER_URL=http://172.15.0.4:8030
# Replace PRIVATE_KEY if needed
PRIVATE_KEY=0xc594c6e5def4bab63ac29eed19a134c130388f74f019bc74b8f4389df2837a58
```
{% endcode %}
{% 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._
### Setup dependencies
In this step the required dependencies will be installed.
{% tabs %}
{% tab title="ocean.js" %}
```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
pip3 install wheel
# Install Ocean library. Allow pre-releases to get the latest v4 version.
pip3 install ocean-lib python-dotenv web3
```
{% 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.
Create the configuration file in the working directory i.e. at the same path where the `.env` is located.
{% tabs %}
{% tab title="ocean.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');
// Get configuration for the given network
let oceanConfig = new ConfigHelper().getConfig(process.env.OCEAN_NETWORK);
// 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(
fs.readFileSync(
process.env.ADDRESS_FILE
|| `${homedir}/.ocean/ocean-contracts/artifacts/address.json`,
'utf8'
)
);
const addresses = addressData[process.env.OCEAN_NETWORK];
oceanConfig = {
...oceanConfig,
oceanTokenAddress: addresses.Ocean,
poolTemplateAddress: addresses.poolTemplate,
fixedRateExchangeAddress: addresses.FixedPrice,
dispenserAddress: addresses.Dispenser,
erc721FactoryAddress: addresses.ERC721Factory,
sideStakingAddress: addresses.Staking,
opfCommunityFeeCollector: addresses.OPFCommunityFeeCollector
};
}
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
};
const web3Provider = new HDWalletProvider(
process.env.PRIVATE_KEY,
oceanConfig.nodeUri
);
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.ocean.ocean import Ocean
from ocean_lib.web3_internal.wallet import Wallet
from ocean_lib.example_config import ExampleConfig, get_config_dict
from ocean_lib.ocean.ocean import Ocean
from ocean_lib.ocean.util import get_web3
load_dotenv()
config = ExampleConfig.get_config()
ocean = Ocean(config)
user_private_key = os.getenv('PRIVATE_KEY')
web3_wallet = Wallet(ocean.web3, user_private_key, ocean.config.block_confirmations, ocean.config.transaction_timeout)
```
{% endcode %}
{% endtab %}
{% endtabs %}
Now, all the dependencies are ready and you can proceed with interacting with Ocean infrastructure using Ocean libraries.

View File

@ -0,0 +1,180 @@
# Create datatoken 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](../../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.
#### 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. &#x20;
{% hint style="info" %}
**Fees**: The code snippets below define fees related parameters. Please refer [fees page ](../../core-concepts/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

@ -0,0 +1,106 @@
# Creating a dataNFT
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#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. &#x20;
{% 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

@ -0,0 +1,117 @@
# Mint datatoken
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.&#x20;
#### 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. &#x20;
{% 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

@ -0,0 +1,102 @@
# 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.
#### 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)
{% hint style="info" %}
The variable **AQUARIUS\_URL** and **PROVIDER\_URL** should be set correctly in `.env` file
{% endhint %}
#### 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. &#x20;
{% tabs %}
{% tab title="ocean.js" %}
{% code title="updateMetadata.js" %}
```javascript
// Import dependencies
const {
Nft,
ProviderInstance,
getHash,
Aquarius
} = require('@oceanprotocol/lib');
const { SHA256 } = require('crypto-js');
const Web3 = require('web3');
const { web3Provider, oceanConfig } = require('./config');
// Create a web3 instance
const web3 = new Web3(web3Provider);
// Create Aquarius instance
const aquarius = new Aquarius(oceanConfig.metadataCacheUri);
const nft = new Nft(web3);
const providerUrl = oceanConfig.providerUri;
// replace the did here
const did = "did:op:a419f07306d71f3357f8df74807d5d12bddd6bcd738eb0b461470c64859d6f0f";
// This function takes did as a parameter and updates the data NFT information
const setMetadata = async (did) => {
const accounts = await web3.eth.getAccounts();
const publisherAccount = accounts[0];
// Fetch ddo from Aquarius
const ddo = await aquarius.resolve(did);
// update the ddo here
ddo.metadata.name = "Sample dataset v2";
ddo.metadata.description = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam";
ddo.metadata.tags = ["new tag1", "new tag2"];
providerResponse = await ProviderInstance.encrypt(ddo, providerUrl);
const encryptedResponse = await providerResponse;
const metadataHash = getHash(JSON.stringify(ddo));
// Update the data NFT metadata
await nft.setMetadata(
ddo.nftAddress,
publisherAccount,
0,
providerUrl,
'',
'0x2',
encryptedResponse,
`0x${metadataHash}`
);
// Check if ddo is correctly udpated in Aquarius
await aquarius.waitForAqua(ddo.id);
console.log(`Resolved asset did [${ddo.id}]from aquarius.`);
console.log(`Updated name: [${ddo.metadata.name}].`);
console.log(`Updated description: [${ddo.metadata.description}].`);
console.log(`Updated tags: [${ddo.metadata.tags}].`);
};
// Call setMetadata(...) function defined above
setMetadata(did).then(() => {
process.exit();
}).catch((err) => {
console.error(err);
process.exit(1);
});
```
{% endcode %}
Execute the script
```bash
node updateMetadata.js
```
{% endtab %}
{% endtabs %}

View File

@ -311,6 +311,8 @@ An asset with a service of `type` `compute` has the following additional attribu
| `boolean` | **✓** | If `true`, any passed raw text will be allowed to run. Useful for an algorithm drag & drop use case, but increases risk of data escape through malicious user input. Should be `false` by default in all implementations. |
| Type | Required | Description |
| `boolean` | **✓** | If `true`, any passed raw text will be allowed to run. Useful for an algorithm drag & drop use case, but increases risk of data escape through malicious user input. Should be `false` by default in all implementations. |
| Type | Required | Description |
| `boolean` | **✓** | If `true`, any passed raw text will be allowed to run. Useful for an algorithm drag & drop use case, but increases risk of data escape through malicious user input. Should be `false` by default in all implementations. |
| <p><strong><code>allowNetworkAccess</code></strong></p><table><thead><tr><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><code>boolean</code></td><td><strong></strong></td><td>If <code>true</code>, the algorithm job will have network access.</td></tr></tbody></table> | | |
| Type | Required | Description |
| `boolean` | **✓** | If `true`, the algorithm job will have network access. |
@ -322,6 +324,8 @@ An asset with a service of `type` `compute` has the following additional attribu
| `boolean` | **✓** | If `true`, the algorithm job will have network access. |
| Type | Required | Description |
| `boolean` | **✓** | If `true`, the algorithm job will have network access. |
| Type | Required | Description |
| `boolean` | **✓** | If `true`, the algorithm job will have network access. |
| <p><strong><code>publisherTrustedAlgorithmPublishers</code></strong></p><table><thead><tr><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td>Array of <code>string</code></td><td><strong></strong></td><td>If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. If not empty any algo published by the defined publishers is allowed.</td></tr></tbody></table> | | |
| Type | Required | Description |
| Array of `string` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. If not empty any algo published by the defined publishers is allowed. |
@ -333,6 +337,8 @@ An asset with a service of `type` `compute` has the following additional attribu
| Array of `string` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. If not empty any algo published by the defined publishers is allowed. |
| Type | Required | Description |
| Array of `string` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. If not empty any algo published by the defined publishers is allowed. |
| Type | Required | Description |
| Array of `string` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. If not empty any algo published by the defined publishers is allowed. |
| <p><strong><code>publisherTrustedAlgorithms</code></strong></p><table><thead><tr><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td>Array of <code>publisherTrustedAlgorithms</code></td><td><strong></strong></td><td>If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. Otherwise only the algorithms defined in the array are allowed. (see below).</td></tr></tbody></table> | | |
| Type | Required | Description |
| Array of `publisherTrustedAlgorithms` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. Otherwise only the algorithms defined in the array are allowed. (see below). |
@ -344,6 +350,8 @@ An asset with a service of `type` `compute` has the following additional attribu
| Array of `publisherTrustedAlgorithms` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. Otherwise only the algorithms defined in the array are allowed. (see below). |
| Type | Required | Description |
| Array of `publisherTrustedAlgorithms` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. Otherwise only the algorithms defined in the array are allowed. (see below). |
| Type | Required | Description |
| Array of `publisherTrustedAlgorithms` | **✓** | If not defined, then any published algorithm is allowed. If empty array, then no algorithm is allowed. Otherwise only the algorithms defined in the array are allowed. (see below). |
The `publisherTrustedAlgorithms` is an array of objects with the following structure:

View File

@ -10,27 +10,27 @@ description: Tutorial about how to set up MetaMask for Chrome.
1. Go to the [Chrome Web Store for extensions](https://chrome.google.com/webstore/category/extensions) and search for MetaMask.
![metamask-chrome-store](../.gitbook/assets/metamask-chrome-extension.png)
![metamask-chrome-store](../building-with-ocean/images/metamask-chrome-extension.png)
* Install MetaMask. The wallet provides a friendly user interface that will help you through each step. MetaMask gives you two options: importing an existing wallet or creating a new one. Choose to `Create a Wallet`:
![Create a wallet](../.gitbook/assets/create-new-metamask-wallet.png)
![Create a wallet](../building-with-ocean/images/create-new-metamask-wallet.png)
* In the next step create a new password for your wallet. Read through and accept the terms and conditions. After that, MetaMask will generate Secret Backup Phrase for you. Write it down and store it in a safe place.
![Secret Backup Phrase](../.gitbook/assets/secret-backup-phrase.png)
![Secret Backup Phrase](../building-with-ocean/images/secret-backup-phrase.png)
* Continue forward. On the next page, MetaMask will ask you to confirm the backup phrase. Select the words in the correct sequence:
![Confirm secret backup phrase](../.gitbook/assets/confirm-backup-phrase.png)
![Confirm secret backup phrase](../building-with-ocean/images/confirm-backup-phrase.png)
* Voila! Your account is now created. You can access MetaMask via the browser extension in the top right corner of your browser.
![MetaMask browser extension](../.gitbook/assets/metamask-browser-extension.png)
![MetaMask browser extension](../building-with-ocean/images/metamask-browser-extension.png)
* You can now manage Ether and Ocean Tokens with your wallet. You can copy your account address to the clipboard from the options. When you want someone to send Ether or Ocean Tokens to you, you will have to give them that address. It's not a secret.
![Manage tokens](../.gitbook/assets/manage-tokens.png)
![Manage tokens](../building-with-ocean/images/manage-tokens.png)
You can also watch our [tutorial video snippets](https://www.youtube.com/playlist?list=PL\_dn0wVs9kWolBCbtHaFxsi408cumOeth) if you want more help setting up MetaMask.
@ -40,7 +40,7 @@ Sometimes it is required to use custom or external networks in MetaMask. We can
Open the Settings menu and find the `Networks` option. When you open it, you'll be able to see all available networks your MetaMask wallet currently use. Click the `Add Network` button.
![Add custom/external network](../.gitbook/assets/metamask-add-network.png)
![Add custom/external network](../building-with-ocean/images/metamask-add-network.png)
There are a few empty inputs we need to fill:

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 143 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 221 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 79 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 223 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 KiB