Features
Updating Compressed NFTs
The Update instruction can be used to modify the metadata of a Compressed NFT. The Merkle root is updated to reflect the propagated hash of the data, and RPC providers who conform to the Metaplex DAS API will update their index of the cNFTs.
The metadata can be updated by one of two authorities, depending on if the compressed NFT is a verified item in a collection.
As the Tree Owner
If there is no verified collection set, the Tree Owner is the authority that is permissioned to call Update
Update a Compressed NFT as the Tree Owner
import {
updateMetadata,
UpdateArgsArgs,
getCurrentRoot,
} from '@metaplex-foundation/mpl-bubblegum'
// Then we can use it to update metadata for the NFT.
const updateArgs: UpdateArgsArgs = {
name: some('New name'),
uri: some('https://updated-example.com/my-nft.json'),
}
await updateMetadata(umi, {
leafOwner,
merkleTree,
root: getCurrentRoot(merkleTreeAccount.tree),
nonce: leafIndex,
index: leafIndex,
currentMetadata: metadata,
proof: [],
updateArgs,
}).sendAndConfirm(umi);
This can also be done using the getAssetWithProof
helper method:
Transaction size
If you encounter transaction size errors, consider using { truncateCanopy: true }
with getAssetWithProof
. See the FAQ for details.
Update a Compressed NFT as the Tree Owner using Helper Method
import {
getAssetWithProof,
updateMetadata,
UpdateArgsArgs,
} from '@metaplex-foundation/mpl-bubblegum'
// Use the helper to fetch the proof.
const assetWithProof = await getAssetWithProof(umi, assetId, {truncateCanopy: true});
// Then we can use it to update metadata for the NFT.
const updateArgs: UpdateArgsArgs = {
name: some('New name'),
uri: some('https://updated-example.com/my-nft.json'),
}
await updateMetadata(umi, {
...assetWithProof,
leafOwner,
currentMetadata: metadata,
updateArgs,
}).sendAndConfirm(umi)
As the Collection Update Authority
If the verified collection is set, then the Collection Update Authority is the only authority that is permissioned to call Update
Update a Compressed NFT as the Collection Update Authority
import {
updateMetadata,
UpdateArgsArgs,
getCurrentRoot,
} from '@metaplex-foundation/mpl-bubblegum'
import { findMetadataPda } from '@metaplex-foundation/mpl-token-metadata'
// Then we can use it to update metadata for the NFT.
const updateArgs: UpdateArgsArgs = {
name: some('New name'),
uri: some('https://updated-example.com/my-nft.json'),
}
await updateMetadata(umi, {
leafOwner,
merkleTree,
root: getCurrentRoot(merkleTreeAccount.tree),
nonce: leafIndex,
index: leafIndex,
currentMetadata: metadata,
proof: [],
updateArgs,
authority: collectionAuthority,
collectionMint: collectionMint.publicKey,
}).sendAndConfirm(umi)
This can also be done using the getAssetWithProof
helper method:
Update a Compressed NFT as the Collection Update Authority using Helper Method
import {
getAssetWithProof,
updateMetadata,
UpdateArgsArgs,
} from '@metaplex-foundation/mpl-bubblegum'
import { findMetadataPda } from '@metaplex-foundation/mpl-token-metadata'
// Use the helper to fetch the proof.
const assetWithProof = await getAssetWithProof(umi, assetId, {truncateCanopy: true});
// Then we can use it to update metadata for the NFT.
const updateArgs: UpdateArgsArgs = {
name: some('New name'),
uri: some('https://updated-example.com/my-nft.json'),
}
await updateMetadata(umi, {
...assetWithProof,
leafOwner,
currentMetadata: metadata,
updateArgs,
authority: collectionAuthority,
collectionMint: collectionMint.publicKey,
}).sendAndConfirm(umi)