*!
As a CNFTS Developer Solana Blockchain, the renewal off metadata can be a sample. However, When Confronted with a Mistake of Repeated Compposition of the Merkle Tree, many creators were disappointed. In this article, we walk into this problem and make recommenations on the resolve it.
Consider
Error occursa in an adding to update Solan block circuit CNFT metadata. The UPDATEMETAADADATE Method is calling with an invalid root is repeateddly calllaculated from the evidence. This can be to inconsistent network status and can cause CNFT function problem.
Here is the reference of material you doe:
- [Solana API documentation] ( metadata///index.html)
- [CNFT documentation “Solana”] (
CODE EXAMPLE
Demonstration purposes, say we have ads a CNFT with a contract with this code:
`Solan
import {program} from Solan-Program;
Import {update metadata} for the “../lib/Update metadata”;
async Function Main () {
// Initiate metadata
CONS metadata = waiting for Getmethadata ();
try {
// Update metadata
wait for upy metadata (methata);
} catch (error) {
If (rearing instance from specialty && different.message.includes (“wrong root”) {
// Arrange the different by re-connecting the root off proof
CEOF = wait for Get Prooforupdate ();
CONST ROT = Wait for Computemellelleree (proof);
try {
// Update metadata with new roots
wait for upy metadata (methata, root);
} catch (error) {
if
console.error (arror);
}
} ELSE {
throw an earror;
}
}
}
Async’s feature off Getmethata () {
// Return several sample metadata data
to return
“Some aller information about metadata”
]
}
if
Function off GetProoff Porpdate () {
if
the return a new promise (resolve => setmeout (() => resolve (New Uint8Rray (32)), 100);
}
Async’s feature off Computermerslletree (proof) {
// Calculate the Markele Trees
the return a new promise (Resolve => Setter () => Resolve (New Uint8Rray (256)), 200);
}
basic ();
`
Solution
To Solve this problem, welfare the evigence on the metadata the metadata. This can be achieved by entering a new variables to see the theme.
`Solan
import {program} from Solan-Program;
Import {update metadata} for the “../lib/Update metadata”;
CNTF Class {
Private update Progress = FALSE;
private proof = 0;
async of getmethata () {
IF. // is upgraded, do not plate
This.Prowdex ++;
CONST METADATA = waiting for the getmethatafromproof ();
the return metadata;
}
Async upgrade metadata (methata) {
IF (this.Updatein progress) Discard a new earror (“wrong roots move from the proof”);
this.Updatein progressor = TRUE;
try {
// Update metadata wesing metadata
wait for upy metadata (methata);
} catch (error) {
If (rearing instance from specialty && error.message.includes (“wrong root”) {
// Arrange the different by re-connecting the root off proof
CONST proffix = this.prowenindex;
CEOFDATA = waiting for Getprooffromindex (Porochididex);
try {
this.Updatein progressor = false; // reset the up
That.
Leave a Reply