diff --git a/developers/ocean.js/update-metadata.md b/developers/ocean.js/update-metadata.md index 3e07cd61..b2b00061 100644 --- a/developers/ocean.js/update-metadata.md +++ b/developers/ocean.js/update-metadata.md @@ -15,48 +15,35 @@ The variable **AQUARIUS\_URL** and **PROVIDER\_URL** should be set correctly in #### 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.js`) and `.env` files are present, and copy the code as listed below. {% 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; +// Note: Make sure .env file and config.js are created and setup correctly +const { oceanConfig } = require('./config.js'); +const { ZERO_ADDRESS, NftFactory, getHash, Nft } = require ('@oceanprotocol/lib'); // 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]; + + const publisherAccount = await oceanConfig.publisherAccount.getAddress(); // Fetch ddo from Aquarius - const ddo = await aquarius.resolve(did); + const ddo = await await oceanConfig.aquarius.resolve(did); + + const nft = new Nft(oceanConfig.ethersProvider); // 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 providerResponse = await oceanConfig.ethersProvider.encrypt(ddo, process.env.OCEAN_NETWORK_URL); const encryptedResponse = await providerResponse; const metadataHash = getHash(JSON.stringify(ddo)); @@ -65,7 +52,7 @@ const setMetadata = async (did) => { ddo.nftAddress, publisherAccount, 0, - providerUrl, + process.env.OCEAN_NETWORK_URL, '', '0x2', encryptedResponse, @@ -73,7 +60,7 @@ const setMetadata = async (did) => { ); // Check if ddo is correctly udpated in Aquarius - await aquarius.waitForAqua(ddo.id); + await oceanConfig.aquarius.waitForAqua(ddo.id); console.log(`Resolved asset did [${ddo.id}]from aquarius.`); console.log(`Updated name: [${ddo.metadata.name}].`); @@ -89,7 +76,6 @@ setMetadata(did).then(() => { console.error(err); process.exit(1); }); - ``` {% endcode %}