mirror of
https://github.com/oceanprotocol/docs.git
synced 2024-11-26 19:49:26 +01:00
GITBOOK-317: change request with no subject merged in GitBook
This commit is contained in:
parent
e581503593
commit
f3e394f6b2
@ -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 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 %}
|
{% tabs %}
|
||||||
{% tab title="ocean.js" %}
|
{% tab title="ocean.js" %}
|
||||||
{% code title="updateMetadata.js" %}
|
{% code title="updateMetadata.js" %}
|
||||||
```javascript
|
```javascript
|
||||||
// Import dependencies
|
// Note: Make sure .env file and config.js are created and setup correctly
|
||||||
const {
|
const { oceanConfig } = require('./config.js');
|
||||||
Nft,
|
const { ZERO_ADDRESS, NftFactory, getHash, Nft } = require ('@oceanprotocol/lib');
|
||||||
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
|
// 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
|
// 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 publisherAccount = accounts[0];
|
const publisherAccount = await oceanConfig.publisherAccount.getAddress();
|
||||||
|
|
||||||
// Fetch ddo from Aquarius
|
// 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
|
// update the ddo here
|
||||||
ddo.metadata.name = "Sample dataset v2";
|
ddo.metadata.name = "Sample dataset v2";
|
||||||
ddo.metadata.description = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam";
|
ddo.metadata.description = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam";
|
||||||
ddo.metadata.tags = ["new tag1", "new tag2"];
|
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 encryptedResponse = await providerResponse;
|
||||||
const metadataHash = getHash(JSON.stringify(ddo));
|
const metadataHash = getHash(JSON.stringify(ddo));
|
||||||
|
|
||||||
@ -65,7 +52,7 @@ const setMetadata = async (did) => {
|
|||||||
ddo.nftAddress,
|
ddo.nftAddress,
|
||||||
publisherAccount,
|
publisherAccount,
|
||||||
0,
|
0,
|
||||||
providerUrl,
|
process.env.OCEAN_NETWORK_URL,
|
||||||
'',
|
'',
|
||||||
'0x2',
|
'0x2',
|
||||||
encryptedResponse,
|
encryptedResponse,
|
||||||
@ -73,7 +60,7 @@ const setMetadata = async (did) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check if ddo is correctly udpated in Aquarius
|
// 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(`Resolved asset did [${ddo.id}]from aquarius.`);
|
||||||
console.log(`Updated name: [${ddo.metadata.name}].`);
|
console.log(`Updated name: [${ddo.metadata.name}].`);
|
||||||
@ -89,7 +76,6 @@ setMetadata(did).then(() => {
|
|||||||
console.error(err);
|
console.error(err);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
```
|
```
|
||||||
{% endcode %}
|
{% endcode %}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user