From ea9bf245004cf749f234b9d7eec498d660a7882b Mon Sep 17 00:00:00 2001 From: Akshay Patel Date: Mon, 25 Jul 2022 10:17:51 +0000 Subject: [PATCH] GitBook: [#6] No subject --- SUMMARY.md | 7 +- .../create-datatoken-with-fixed-pricing.md | 126 ++++++++++++++++++ .../using-ocean-libraries/mint-datatoken.md | 89 +++++++++++++ .../using-ocean-libraries/update-metadata.md | 17 +++ 4 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 building-with-ocean/using-ocean-libraries/create-datatoken-with-fixed-pricing.md create mode 100644 building-with-ocean/using-ocean-libraries/mint-datatoken.md create mode 100644 building-with-ocean/using-ocean-libraries/update-metadata.md diff --git a/SUMMARY.md b/SUMMARY.md index 066ca53a..3cbaf3e8 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -23,8 +23,11 @@ * [Building with ocean](building-with-ocean/README.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) - * [Configuration](building-with-ocean/using-ocean-libraries/configuration.md) - * [Creating a dataNFT](building-with-ocean/using-ocean-libraries/creating_dataNFT.md) + * [Configuration](building-with-ocean/using-ocean-libraries/configuration.md) + * [Creating a dataNFT](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 datatoken](building-with-ocean/using-ocean-libraries/mint-datatoken.md) + * [Update metadata](building-with-ocean/using-ocean-libraries/update-metadata.md) * [Publish assets using hosting services](building-with-ocean/asset-hosting.md) * [Binance Smart Chain (BSC)](building-with-ocean/bsc-bridge.md) * [Set Up a Marketplace](building-with-ocean/marketplace.md) diff --git a/building-with-ocean/using-ocean-libraries/create-datatoken-with-fixed-pricing.md b/building-with-ocean/using-ocean-libraries/create-datatoken-with-fixed-pricing.md new file mode 100644 index 00000000..86736d5d --- /dev/null +++ b/building-with-ocean/using-ocean-libraries/create-datatoken-with-fixed-pricing.md @@ -0,0 +1,126 @@ +# Create Datatoken with fixed pricing + +#### Configuration + +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. + +{% tabs %} +{% tab title="ocean.js" %} +{% code title="create_datatoken_with_fre.js" %} +```javascript +const { NftFactory, Datatoken } = require('@oceanprotocol/lib'); +const Web3 = require('web3'); +const { web3Provider, oceanConfig } = require('./config'); + +const web3 = new Web3(web3Provider); + +const createDataNFT = async () => { + const Factory = new NftFactory(oceanConfig.erc721FactoryAddress, web3); + + const accounts = await web3.eth.getAccounts(); + const publisherAccount = accounts[0]; + + const nftParams = { + name: '72120Bundle', + symbol: '72Bundle', + templateIndex: 1, + tokenURI: 'https://example.com', + transferable: true, + owner: publisherAccount + }; + + const erc20Params = { + templateIndex: 1, + cap: '100000', + feeAmount: '0', + 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: '1', + marketFee: '0', + allowedConsumer: publisherAccount, + withMint: false + } + + const result = await Factory.createNftErc20WithFixedRate( + publisherAccount, + nftParams, + erc20Params, + fixedPriceParams + ); + + const erc721Address = result.events.NFTCreated.returnValues[0]; + const datatokenAddress = result.events.TokenCreated.returnValues[0]; + + return { + erc721Address, + datatokenAddress + }; +}; + +createDataNFT() + .then(({ erc721Address, datatokenAddress }) => { + console.log(`DataNft address ${erc721Address}`); + console.log(`Datatoken address ${datatokenAddress}`); + process.exit(1); + + }) + .catch((err) => { + console.error(err); + process.exit(1); + }); +teatatokfreicreate_datatoken_with_fre.js +``` +{% endcode %} +{% 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}") + + +datatoken = data_nft.create_datatoken("Datatoken 1", "DT1", from_wallet=web3_wallet) +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 %} + + +{% endtab %} +{% endtabs %} + diff --git a/building-with-ocean/using-ocean-libraries/mint-datatoken.md b/building-with-ocean/using-ocean-libraries/mint-datatoken.md new file mode 100644 index 00000000..16774ebb --- /dev/null +++ b/building-with-ocean/using-ocean-libraries/mint-datatoken.md @@ -0,0 +1,89 @@ +# Mint datatoken + +#### Configuration + +See [this](configuration.md) guide on defining a `.env` file and a configuration file + +#### Create a script to mint datatokens + +{% tabs %} +{% tab title="ocean.js" %} +{% code title="mint_datatoken.js" %} +```javascript +const { NftFactory, Datatoken } = require('@oceanprotocol/lib'); +const Web3 = require('web3'); +const { web3Provider, oceanConfig } = require('./config'); + +const web3 = new Web3(web3Provider); + +// Change this +const datatokenAddress = "0xD3542e5F56655fb818F9118CE219e1D10751BC82" +const receiverAddress = "0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e" + +const mintDatatoken = async (datatokenAddress, receiverAddress) => { + const accounts = await web3.eth.getAccounts(); + const publisherAccount = accounts[0]; + + const datatoken = new Datatoken(web3); + + let receiverBalance = await datatoken.balance( + datatokenAddress, + receiverAddress + ); + console.log(`Receiver balance before mint: ${receiverBalance}`); + + await datatoken.mint( + datatokenAddress, + publisherAccount, + '1', + receiverAddress + ); + + receiverBalance = await datatoken.balance( + datatokenAddress, + receiverAddress + ); + console.log(`Receiver balance after mint: ${receiverBalance}`); +}; + +mintDatatoken(datatokenAddress, receiverAddress) + .then(() => { + process.exit((err) => { + console.error(err); + process.exit(1); + }); + }) + .catch((err) => { + console.error(err); + process.exit(1); + }); +``` +{% endcode %} +{% 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)}") + +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 %} +{% endtab %} +{% endtabs %} diff --git a/building-with-ocean/using-ocean-libraries/update-metadata.md b/building-with-ocean/using-ocean-libraries/update-metadata.md new file mode 100644 index 00000000..3b3792b2 --- /dev/null +++ b/building-with-ocean/using-ocean-libraries/update-metadata.md @@ -0,0 +1,17 @@ +# Update metadata + +#### Configuration + +See [this](configuration.md) guide on defining a `.env` file and a configuration file + +#### Create a script to update the metadata + +{% tabs %} +{% tab title="ocean.js" %} + +{% endtab %} + +{% tab title="ocean.py" %} + +{% endtab %} +{% endtabs %}