Solana: Error using concurrent merkle tree: Invalid root recomputed from proof when use updateMetadata

A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

As a CNFT creator on Blockchain Solana, metadata updating can be a simple process. However, meeting an error that involves re-computing a Merkle Tree has left many frustrated creators. In this article,

Error

Metadata for a CNFT on Blockchain Solana. The “UpdateMatata” method is called proof. This can lead to an inconsistent state on the network and cause problems with CNFT functionality.

Here are the reference materials you use:

  • [API Solana documentation] (

  • [CNFT documentation on Solana] (

Code example

For demonstrative purposes, suppose we have a CNFT contract with the following code:

`Solana

Import {program} from "solar-program";

Import {updatemetAdata} from "../lib/update-metadata";

Async function Main () {

// initializes metadata

Consist metadate = wait for the GetmetAdata ();

Try {

// update the metadata

Wait for updatemetata (metadata);

} Catch (error) {

IF (error instance error && error.message.includes ("invalid root") {

// manage the error by re-calculating the root from a proof

Consist of proof = waiting for getproofforupdate ();

Const root = waiting for computeremerkletree (proof);

Try {

// update the metadata with the new root

Wait for updatemetata (metadata, root);

} Catch (error) {

// Manage any errors that appear during the metadata update

Console.error (error);

}

} Else {

Throwing error;

}

}

}

The ASYNC GETMETATAd () function {

// returns a few sample of data metadata

Return [

"

"Other information about metadata",

];

}

// help functions to generate proof and calculation of Merkle tree

GETPROFFORUPdate function () {

// generates random proof for updating metadata

Returns the new promise (resolve => settimeout (() => resolves (New Uint8array (32)), 100);

}

ASYNC FUNCT COMPATHERKLETE (proof) {

// Calculate the Merkle shaft from proof

Returns the new promise (resolve => settimeout (() => resolves (New Uint8array (256)), 200));

}

Slender ();

Solution

The root from a proof only when updating the metadata. This can be obtained by introducing a new variable that keeps track of if an update is in progress

` Solana

Import {program} from “solar-program”;

Import {updatemetAdata} from “../lib/update-metadata”;

CLASS CNTF {

private updateinprogress = false;

Private Proferatindex = 0;

async gitmetata () {

IF (this.updateinprogress) returns null; // update is in progress, do not proceed

this.proofindex ++;

Consist metadate = waiting for GetmetAdatAfromromroof ();

Return metadata;

}

async updatemetAdata (metadata) {

IF (this.updateinprogress) throws a new error (“Invalid root re -evidence”);

This.Updateinprogress = True;

Try {

// update metadata using metadata

Wait for updatemetata (metadata);

} Catch (error) {

IF (error instance error && error.message.includes (“invalid root”) {

// Manage the error by re-calculating the root from a proof

Const protectshindex = this.proofindex;

Const protect = wait getprooffromindex (proofleindex);

Try {

this.updateinprogress = false; // Reset the update flag

this.

Role Predictive Modeling Prices

Sign up for our Newsletter

Your Voice Matters: Share Your Session Experience!

Thanks for contacting us! We will get in touch with you shortly.

Your Voice Matters: Share Your Session Experience!

Please Login to submit your Feedback!

Confirm Booking

CONFIRMATION

Date

Time Slot

Session Type

Session Mode

Additional Info

UPGRADE TO UNLOCK MORE FEATURES!

You currently have limited access to our AI Career Counselor and Career Expert Sessions. Upgrade your plan to enjoy more comprehensive career guidance and support.

Upgrade Options:

  • Standard Plan: Access personalized career assessment, 50 AI-powered sessions, weekly career expert sessions, and more.
  • Elite Plan: Includes everything in the Starter Plan plus exclusive career development resources and webinars.
  • Elite Plus Plan: Enjoy all features including unlimited one-on-one sessions, AI career assistance, and priority support.

"Share this amazing job opportunity!"

WhatsApp
LinkedIn
Facebook
Instagram

No subject snapshot found for the current user.

Would you like to take the subject profile assessment again?

Would you like to take the subject profile assessment again?

No core snapshot found for the current user.

Would you like to take the value profile assessment again?

Would you like to take the value profile assessment again?

No skill snapshot found for the current user.

Would you like to take the skill profile assessment again?

Would you like to take the skill profile assessment again?

No interest snapshot found for the current user.

Would you like to take the Interest profile assessment again?

Would you like to take the Interest profile assessment again?

No personality snapshot found for the current user.

Would you like to take the personality assessment again?

Would you like to take the personality assessment again?