mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
GitBook: [#12] Add comments in code snippets
This commit is contained in:
parent
7caf885544
commit
012f7ccb24
@ -24,8 +24,8 @@
|
|||||||
* [Obtaining Ethereum node provider API key](building-with-ocean/obtaining-api-key.md)
|
* [Obtaining Ethereum node provider API key](building-with-ocean/obtaining-api-key.md)
|
||||||
* [Using Ocean libraries](building-with-ocean/using-ocean-libraries/README.md)
|
* [Using Ocean libraries](building-with-ocean/using-ocean-libraries/README.md)
|
||||||
* [Configuration](building-with-ocean/using-ocean-libraries/configuration.md)
|
* [Configuration](building-with-ocean/using-ocean-libraries/configuration.md)
|
||||||
* [Creating a dataNFT](building-with-ocean/using-ocean-libraries/creating\_dataNFT.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)
|
* [Create datatoken with fixed pricing](building-with-ocean/using-ocean-libraries/create-datatoken-with-fixed-pricing.md)
|
||||||
* [Mint datatoken](building-with-ocean/using-ocean-libraries/mint-datatoken.md)
|
* [Mint datatoken](building-with-ocean/using-ocean-libraries/mint-datatoken.md)
|
||||||
* [Update metadata](building-with-ocean/using-ocean-libraries/update-metadata.md)
|
* [Update metadata](building-with-ocean/using-ocean-libraries/update-metadata.md)
|
||||||
* [Publish assets using hosting services](building-with-ocean/asset-hosting.md)
|
* [Publish assets using hosting services](building-with-ocean/asset-hosting.md)
|
||||||
|
@ -15,7 +15,7 @@ cd my-ocean-project
|
|||||||
|
|
||||||
### Create a `.env` file
|
### Create a `.env` file
|
||||||
|
|
||||||
In the working directory create a \`.env\` file. The content of this file will store the values for following variables:
|
In the working directory create a `.env` file. The content of this file will store the values for following variables:
|
||||||
|
|
||||||
| Variable name | Description | Required |
|
| Variable name | Description | Required |
|
||||||
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------- |
|
||||||
@ -29,7 +29,7 @@ In the working directory create a \`.env\` file. The content of this file will s
|
|||||||
Treat this file as a secret and do not commit this file to git or share the content publicly.
|
Treat this file as a secret and do not commit this file to git or share the content publicly.
|
||||||
{% endhint %}
|
{% endhint %}
|
||||||
|
|
||||||
The below tabs show partially filled \`.env\` file content for some of the supported networks. 
|
The below tabs show partially filled `.env` file content for some of the supported networks. 
|
||||||
|
|
||||||
{% tabs %}
|
{% tabs %}
|
||||||
{% tab title="Mainnet" %}
|
{% tab title="Mainnet" %}
|
||||||
@ -110,9 +110,9 @@ pip3 install ocean-lib python-dotenv web3
|
|||||||
|
|
||||||
### 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.
|
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. 
|
Create the configuration file in the working directory i.e. at the same path where the `.env` is located. 
|
||||||
|
|
||||||
{% tabs %}
|
{% tabs %}
|
||||||
{% tab title="ocean.js" %}
|
{% tab title="ocean.js" %}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Create Datatoken with fixed pricing
|
# 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.
|
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.
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ This tutorial will guide you for creating your own data NFT and a datatoken usin
|
|||||||
|
|
||||||
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 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.  
|
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.  
|
||||||
|
|
||||||
@ -14,18 +14,23 @@ Create a new file in the same working directory where configuration file (`confi
|
|||||||
{% tab title="ocean.js" %}
|
{% tab title="ocean.js" %}
|
||||||
{% code title="create_datatoken_with_fre.js" %}
|
{% code title="create_datatoken_with_fre.js" %}
|
||||||
```javascript
|
```javascript
|
||||||
|
// Import dependencies
|
||||||
const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
|
const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const { web3Provider, oceanConfig } = require('./config');
|
const { web3Provider, oceanConfig } = require('./config');
|
||||||
|
|
||||||
|
// Create a web3 instance
|
||||||
const web3 = new Web3(web3Provider);
|
const web3 = new Web3(web3Provider);
|
||||||
|
|
||||||
const createDataNFT = async () => {
|
// Define a function createFRE()
|
||||||
|
const createFRE = async () => {
|
||||||
const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3);
|
const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3);
|
||||||
|
|
||||||
|
// Get accounts from web3 instance
|
||||||
const accounts = await web3.eth.getAccounts();
|
const accounts = await web3.eth.getAccounts();
|
||||||
const publisherAccount = accounts[0];
|
const publisherAccount = accounts[0];
|
||||||
|
|
||||||
|
// data NFT parameters: name, symbol, templateIndex, etc.
|
||||||
const nftParams = {
|
const nftParams = {
|
||||||
name: '72120Bundle',
|
name: '72120Bundle',
|
||||||
symbol: '72Bundle',
|
symbol: '72Bundle',
|
||||||
@ -35,10 +40,14 @@ const createDataNFT = async () => {
|
|||||||
owner: publisherAccount
|
owner: publisherAccount
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// datatoken parameters: name, symbol, templateIndex, etc.
|
||||||
const erc20Params = {
|
const erc20Params = {
|
||||||
|
name: "Sample datatoken",
|
||||||
|
symbol: "SDT",
|
||||||
templateIndex: 1,
|
templateIndex: 1,
|
||||||
cap: '100000',
|
cap: '100000',
|
||||||
feeAmount: '0',
|
feeAmount: '0',
|
||||||
|
// paymentCollector is the address
|
||||||
paymentCollector: '0x0000000000000000000000000000000000000000',
|
paymentCollector: '0x0000000000000000000000000000000000000000',
|
||||||
feeToken: '0x0000000000000000000000000000000000000000',
|
feeToken: '0x0000000000000000000000000000000000000000',
|
||||||
minter: publisherAccount,
|
minter: publisherAccount,
|
||||||
@ -54,10 +63,12 @@ const createDataNFT = async () => {
|
|||||||
datatokenDecimals: 18,
|
datatokenDecimals: 18,
|
||||||
fixedRate: '100',
|
fixedRate: '100',
|
||||||
marketFee: '0',
|
marketFee: '0',
|
||||||
allowedConsumer: publisherAccount,
|
// Optional parameters
|
||||||
withMint: false
|
// 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(
|
const result = await Factory.createNftErc20WithFixedRate(
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
nftParams,
|
nftParams,
|
||||||
@ -65,6 +76,7 @@ const createDataNFT = async () => {
|
|||||||
fixedPriceParams
|
fixedPriceParams
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get the data NFT address and datatoken address from the result
|
||||||
const erc721Address = result.events.NFTCreated.returnValues[0];
|
const erc721Address = result.events.NFTCreated.returnValues[0];
|
||||||
const datatokenAddress = result.events.TokenCreated.returnValues[0];
|
const datatokenAddress = result.events.TokenCreated.returnValues[0];
|
||||||
|
|
||||||
@ -74,7 +86,8 @@ const createDataNFT = async () => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
createDataNFT()
|
// Call the createFRE() function
|
||||||
|
createFRE()
|
||||||
.then(({ erc721Address, datatokenAddress }) => {
|
.then(({ erc721Address, datatokenAddress }) => {
|
||||||
console.log(`DataNft address ${erc721Address}`);
|
console.log(`DataNft address ${erc721Address}`);
|
||||||
console.log(`Datatoken address ${datatokenAddress}`);
|
console.log(`Datatoken address ${datatokenAddress}`);
|
||||||
@ -113,8 +126,28 @@ data_nft = ocean.create_data_nft(
|
|||||||
)
|
)
|
||||||
print(f"Created dataNFT. Its address is {data_nft.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
|
||||||
|
|
||||||
datatoken = data_nft.create_datatoken("Datatoken 1", "DT1", from_wallet=web3_wallet)
|
# 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}")
|
print(f"Created datatoken. Its address is {datatoken.address}")
|
||||||
|
|
||||||
|
|
||||||
@ -126,6 +159,7 @@ exchange_id = ocean.create_fixed_rate(
|
|||||||
)
|
)
|
||||||
|
|
||||||
print(f"Created fixed rate exchange with ID {exchange_id.hex()}")
|
print(f"Created fixed rate exchange with ID {exchange_id.hex()}")
|
||||||
|
|
||||||
```
|
```
|
||||||
{% endcode %}
|
{% endcode %}
|
||||||
|
|
||||||
|
@ -14,28 +14,34 @@ Create a new file in the same working directory where configuration file (`confi
|
|||||||
{% tab title="ocean.js" %}
|
{% tab title="ocean.js" %}
|
||||||
{% code title="mint_datatoken.js" %}
|
{% code title="mint_datatoken.js" %}
|
||||||
```javascript
|
```javascript
|
||||||
|
// Import dependencies
|
||||||
const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
|
const { NftFactory, Datatoken } = require('@oceanprotocol/lib');
|
||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const { web3Provider, oceanConfig } = require('./config');
|
const { web3Provider, oceanConfig } = require('./config');
|
||||||
|
|
||||||
|
// Create a web3 instance
|
||||||
const web3 = new Web3(web3Provider);
|
const web3 = new Web3(web3Provider);
|
||||||
|
|
||||||
// Change this
|
// Change this
|
||||||
const datatokenAddress = "0xD3542e5F56655fb818F9118CE219e1D10751BC82"
|
const datatokenAddress = "0xD3542e5F56655fb818F9118CE219e1D10751BC82"
|
||||||
const receiverAddress = "0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"
|
const receiverAddress = "0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e"
|
||||||
|
|
||||||
|
// Create a function which will take `datatokenAddress` and `receiverAddress` as parameters
|
||||||
const mintDatatoken = async (datatokenAddress, receiverAddress) => {
|
const mintDatatoken = async (datatokenAddress, receiverAddress) => {
|
||||||
const accounts = await web3.eth.getAccounts();
|
const accounts = await web3.eth.getAccounts();
|
||||||
const publisherAccount = accounts[0];
|
const publisherAccount = accounts[0];
|
||||||
|
|
||||||
|
// Create datatoken instance
|
||||||
const datatoken = new Datatoken(web3);
|
const datatoken = new Datatoken(web3);
|
||||||
|
|
||||||
|
// Get current datatoken balance of receiver
|
||||||
let receiverBalance = await datatoken.balance(
|
let receiverBalance = await datatoken.balance(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
receiverAddress
|
receiverAddress
|
||||||
);
|
);
|
||||||
console.log(`Receiver balance before mint: ${receiverBalance}`);
|
console.log(`Receiver balance before mint: ${receiverBalance}`);
|
||||||
|
|
||||||
|
// Mint datatoken
|
||||||
await datatoken.mint(
|
await datatoken.mint(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
@ -43,6 +49,7 @@ const mintDatatoken = async (datatokenAddress, receiverAddress) => {
|
|||||||
receiverAddress
|
receiverAddress
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Get new datatoken balance of receiver
|
||||||
receiverBalance = await datatoken.balance(
|
receiverBalance = await datatoken.balance(
|
||||||
datatokenAddress,
|
datatokenAddress,
|
||||||
receiverAddress
|
receiverAddress
|
||||||
@ -50,6 +57,7 @@ const mintDatatoken = async (datatokenAddress, receiverAddress) => {
|
|||||||
console.log(`Receiver balance after mint: ${receiverBalance}`);
|
console.log(`Receiver balance after mint: ${receiverBalance}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Call mintDatatoken(...) function defined above
|
||||||
mintDatatoken(datatokenAddress, receiverAddress)
|
mintDatatoken(datatokenAddress, receiverAddress)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
process.exit((err) => {
|
process.exit((err) => {
|
||||||
@ -85,6 +93,7 @@ datatoken = ocean.get_datatoken(datatoken_address)
|
|||||||
|
|
||||||
print(f"Balance before mint: {datatoken.balanceOf(receiver_address)}")
|
print(f"Balance before mint: {datatoken.balanceOf(receiver_address)}")
|
||||||
|
|
||||||
|
# Mint datatokens
|
||||||
datatoken.mint(
|
datatoken.mint(
|
||||||
account_address=receiver_address,
|
account_address=receiver_address,
|
||||||
value=ocean.to_wei("1"),
|
value=ocean.to_wei("1"),
|
||||||
|
@ -6,6 +6,10 @@ This tutorial will guide you to update an existing asset published on-chain usin
|
|||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
{% 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 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.  
|
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.  
|
||||||
@ -14,6 +18,7 @@ Create a new file in the same working directory where configuration file (`confi
|
|||||||
{% tab title="ocean.js" %}
|
{% tab title="ocean.js" %}
|
||||||
{% code title="updateMetadata.js" %}
|
{% code title="updateMetadata.js" %}
|
||||||
```javascript
|
```javascript
|
||||||
|
// Import dependencies
|
||||||
const {
|
const {
|
||||||
Nft,
|
Nft,
|
||||||
ProviderInstance,
|
ProviderInstance,
|
||||||
@ -24,7 +29,10 @@ const { SHA256 } = require('crypto-js');
|
|||||||
const Web3 = require('web3');
|
const Web3 = require('web3');
|
||||||
const { web3Provider, oceanConfig } = require('./config');
|
const { web3Provider, oceanConfig } = require('./config');
|
||||||
|
|
||||||
|
// Create a web3 instance
|
||||||
const web3 = new Web3(web3Provider);
|
const web3 = new Web3(web3Provider);
|
||||||
|
|
||||||
|
// Create Aquarius instance
|
||||||
const aquarius = new Aquarius(oceanConfig.metadataCacheUri);
|
const aquarius = new Aquarius(oceanConfig.metadataCacheUri);
|
||||||
const nft = new Nft(web3);
|
const nft = new Nft(web3);
|
||||||
const providerUrl = oceanConfig.providerUri;
|
const providerUrl = oceanConfig.providerUri;
|
||||||
@ -32,10 +40,12 @@ const providerUrl = oceanConfig.providerUri;
|
|||||||
// replace the did here
|
// replace the did here
|
||||||
const did = "did:op:a419f07306d71f3357f8df74807d5d12bddd6bcd738eb0b461470c64859d6f0f";
|
const did = "did:op:a419f07306d71f3357f8df74807d5d12bddd6bcd738eb0b461470c64859d6f0f";
|
||||||
|
|
||||||
|
// This function takes did as a parameter and updates the data NFT information
|
||||||
const setMetadata = async (did) => {
|
const setMetadata = async (did) => {
|
||||||
const accounts = await web3.eth.getAccounts();
|
const accounts = await web3.eth.getAccounts();
|
||||||
const publisherAccount = accounts[0];
|
const publisherAccount = accounts[0];
|
||||||
|
|
||||||
|
// Fetch ddo from Aquarius
|
||||||
const ddo = await aquarius.resolve(did);
|
const ddo = await aquarius.resolve(did);
|
||||||
|
|
||||||
// update the ddo here
|
// update the ddo here
|
||||||
@ -47,6 +57,7 @@ const setMetadata = async (did) => {
|
|||||||
const encryptedResponse = await providerResponse;
|
const encryptedResponse = await providerResponse;
|
||||||
const metadataHash = getHash(JSON.stringify(ddo));
|
const metadataHash = getHash(JSON.stringify(ddo));
|
||||||
|
|
||||||
|
// Update the data NFT metadata
|
||||||
await nft.setMetadata(
|
await nft.setMetadata(
|
||||||
ddo.nftAddress,
|
ddo.nftAddress,
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
@ -58,6 +69,7 @@ const setMetadata = async (did) => {
|
|||||||
`0x${metadataHash}`
|
`0x${metadataHash}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Check if ddo is correctly udpated in Aquarius
|
||||||
await aquarius.waitForAqua(ddo.id);
|
await aquarius.waitForAqua(ddo.id);
|
||||||
|
|
||||||
console.log(`Resolved asset did [${ddo.id}]from aquarius.`);
|
console.log(`Resolved asset did [${ddo.id}]from aquarius.`);
|
||||||
@ -67,6 +79,7 @@ const setMetadata = async (did) => {
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Call setMetadata(...) function defined above
|
||||||
setMetadata(did).then(() => {
|
setMetadata(did).then(() => {
|
||||||
process.exit();
|
process.exit();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user