Update NFT Token Metadata
Here we'll update an already existing NFT's metadata
Construct NFT Token Builder
Here we'll construct an instance of the TokenBuilder, then we'll get the existing data, to then change the metadata. Finally we'll call update and update the metadata for that token.
import { NftTokenBuilder } from "@1o1art/sdk";
const client = ClientFactory.makeClient(PRIV_KEY, RPC_URL);
const contractAddr = "your contract address";
const tokenBuilder = NftTokenBuilder(client.signer, contractAddr);
// tokenId that we're looking for
const tokenId: number = 2;
// get the existing token metadata from the tokenURI
const tokenMetadata = await tokenBuilder.getMetadata(tokenId);
const tokenData = {
tokenName: "New Token Name",
tokenDesc: tokenMetadata.desc,
tokenAttributes: tokenMetadata.attributes,
};
await tokenBuilder.updateMetadata(tokenId, tokenData);
const updatedMetadata = await tokenBuilder.getMetadata(tokenId);
console.log(updatedMetadata);