1.0.4 • Published 2 years ago

vechain-update-metadata v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

vechain-update-metadata Module

vechain-update-metadata Module is a module that implements server environment for updating metatdata attributes. The backend server is based on Express JS + Node JS. Since it is working on VeChain, we recommend to use connex rather than Web3.js to connect to VeChain node.

How to implement

This module implements the following logic to update the attribute of metadata in Pinata. 1. Get the Token URI of the specific token whose metadata attribute should be changed. 2. Download the token's metadata in the destination folder with the Token URI. 3. Update the metadata with new attribute value and Save it. 4. Upload that metadata file to Pinata using Pinata API Key and Secret API Key. 5. Get the new CID from Pinata and update the Token's URI with the new CID by calling method of NFT Smart Contract.

Packages

As it works with connex to sync the backend and the VeChain node, it always works along with the package @vechain/connex-driver, @vechain/connex-framework.

npm i @vechain/connex-framework @vechain/connex-driver

Setup the node server environment with the following packages.

npm i express cors dotenv node-fetch@2.0 url 

Last but not least, we need to download Pinata SDK package into the project.

npm i @pinata/sdk

Code Structure

To create a Framework instance:

import { Framework } from '@vechain/connex-framework'
import { Driver, SimpleNet } from '@vechain/connex-driver'

const net = new SimpleNet('https://testnet.veblocks.net/');
const wallet = new SimpleWallet();

// Store Admin Wallet on the connex instance.
wallet.import(process.env.PRIVATE_KEY);
const driver = await Driver.connect(net, wallet);
const connex = new Framework(driver)

// Create a new Connex Instance with deployer's wallet
const accForNFT = connex.thor.account(NFT_ADDRESS)

// Create Contract Method Instance to be called for set new Token's uri 
const setTokenURIMethod = accForNFT.method(findMethodABI(NFT_ABI, "setTokenURI"))

/* Update token's specific attribute
	@param tokenID TokenID to update metadata   Ex: 1
	@param attributeName Attribute Index to update  Ex: Background
	@param attributeValue Attribute Value to replace    Ex: Deep Space White
	@param destination The temp folder's name where to download file from Pinata    Ex: download
	@param pinataGateway The Gateway URL of the Pinata    Ex: https://example.mypinata.cloud/ipfs/
*/
await updateToken(tokenID, attributeName, attributeValue, setTokenURIMethod, destination, pinataGateway);

Usage / Installation

  • Installation

    npm i vechain-update-metadata@1.0.0
  • Usage

    var updateMeta = require('vechain-update-metadata');
    /* Update token's specific attribute
    		@param tokenID TokenID to update metadata   Ex: 1
    		@param attributeName Attribute Index to update  Ex: Background
    		@param attributeValue Attribute Value to replace    Ex: Deep Space White
    		@param destination The temp folder's name where to download file from Pinata    Ex: download
    		@param pinataGateway The Gateway URL of the Pinata    Ex: https://example.mypinata.cloud/ipfs/
    */
    updateMeta.updateMetadata(tokenID, attributeName, attributeValue, destination, pinataGateway);

Warning

You need to create and save .env file with your NFT Smart Contract Deployer wallet's public key, Pinata Secrete API key, Pinata API key in the root folder. The updateToken.js file in node_modules has to be modified with 3 parts according to your logic:

  • You need to implement the way how you get the Tokenuri to download it from Pinata.
  • You need to implement the way how you update the metadata according to your requirement. The index.js file and abi.js file in node_modules has to be modified.
  • In abi.js file, you need to copy your NFT SC address and ABI.
  • In index.js, you need to set the VeChain node you're connecting and import correct ABI and method for setting new token uri.

License

This package is licensed under the GNU Lesser General Public License v3.0, also included in LICENSE file in the repository.