MetadataTree

Class: MetadataTree

Properties overview

  • height: readonly height: number;
  • root: readonly root: Field;
  • values: readonly values: {
    key: bigint;
    value: Field;
    }[];
  • key: bigint;
  • value: Field;
  • Returns: {
    height: number;
    root: string;
    values: {
    key: string;
    value: string;
    }[];
    }
  • height: number;
  • root: string;
  • values: {
    key: string;
    value: string;
    }[];

Methods overview

Defined in: packages/nft/src/metadata/tree.ts:13

Represents a metadata tree using a Merkle tree structure.

The MetadataTree class is used to manage a set of key-value pairs representing metadata,
storing them in a Merkle tree for efficient verification and integrity checks.

This class is a utility within the NFT standard on Mina Protocol, enabling secure and verifiable
storage of metadata. By leveraging the Merkle tree, clients can prove the inclusion of specific
metadata entries without exposing the entire dataset.

Constructors

new MetadataTree()

new MetadataTree(height: number, values: {
  key: bigint;
  value: Field;
 }[]): MetadataTree

Defined in: packages/nft/src/metadata/tree.ts:42

Constructs a new MetadataTree with the specified height and key-value pairs.

Parameters

height

number

The height of the Merkle tree (must be between 1 and 254).

values

{
key: bigint;
value: Field;
}[]

An array of key-value pairs to store in the tree.

Returns

MetadataTree

Throws

Will throw an error if the number of values exceeds the maximum capacity of the tree.

Throws

Will throw an error if any key is out of bounds for the tree height.

Properties

height

readonly height: number;

Defined in: packages/nft/src/metadata/tree.ts:25

The height of the Merkle tree.
Determines the maximum number of elements the tree can hold.


root

readonly root: Field;

Defined in: packages/nft/src/metadata/tree.ts:31

The root of the Merkle tree.
Used for verifying the integrity of the tree and its contents.


values

readonly values: {
  key: bigint;
  value: Field;
 }[];

Defined in: packages/nft/src/metadata/tree.ts:19

The list of key-value pairs stored in the tree.
Each key is a bigint representing the index in the Merkle tree,
and each value is a Field element from o1js.

key

key: bigint;

value

value: Field;

Methods

toJSON()

toJSON(): {
  height: number;
  root: string;
  values: {
     key: string;
     value: string;
    }[];
}

Defined in: packages/nft/src/metadata/tree.ts:71

Serializes the MetadataTree to a JSON object.

Returns

{
  height: number;
  root: string;
  values: {
     key: string;
     value: string;
    }[];
}

An object containing the tree's height, root, and values.

height
height: number;
root
root: string;
values
values: {
  key: string;
  value: string;
 }[];

fromJSON()

static fromJSON(json: {
  height: number;
  root: string;
  values: {
     key: string;
     value: string;
    }[];
 }): MetadataTree

Defined in: packages/nft/src/metadata/tree.ts:95

Deserializes a JSON object into a MetadataTree instance.

Parameters

json

The JSON object containing the tree data.

height

number

root

string

values

{
key: string;
value: string;
}[]

Returns

MetadataTree

A new MetadataTree instance constructed from the JSON data.

Throws

Will throw an error if the JSON data is invalid or inconsistent.