MplBubblegum.Tree (mpl_bubblegum_lib v0.1.0)

View Source

Functions for managing Merkle tree configurations for compressed NFTs on Solana.

Overview

This module provides functionality to create and manage Merkle trees, which are essential data structures for storing compressed NFTs. The Merkle tree is a fundamental component of Solana's state compression feature, allowing thousands of NFTs to be stored at a fraction of the cost of traditional NFTs.

Merkle Trees for Compressed NFTs

Merkle trees in Solana:

  • Act as on-chain storage containers for compressed NFTs
  • Allow for cryptographic verification of NFT ownership and data
  • Significantly reduce the storage costs by keeping most data off-chain
  • Require creation before minting any compressed NFTs

Prerequisites

Before creating a Merkle tree:

  1. A connection must be established using MplBubblegum.Connection.create_connection/2
  2. Your wallet must have sufficient SOL to cover the tree creation cost (typically 0.01-0.05 SOL depending on tree size)

Example Usage

# First establish a connection with your wallet's private key
MplBubblegum.Connection.create_connection(secret_key, rpc_url)

# Then create a new Merkle tree
merkle_tree_address = MplBubblegum.Tree.create_tree_config()

# The returned address can now be used for minting compressed NFTs

Summary

Functions

Creates a new Merkle tree configuration for storing compressed NFTs.

Functions

create_tree_config()

@spec create_tree_config() :: binary()

Creates a new Merkle tree configuration for storing compressed NFTs.

This function creates an on-chain Merkle tree that can store compressed NFTs. The creation process involves:

  1. Building a tree configuration transaction
  2. Sending the transaction to the Solana network
  3. Returning the address of the created Merkle tree

Returns

  • binary() - The Merkle tree address as a base58 string

Error Handling

This function will raise errors in the following cases:

Costs

Creating a Merkle tree requires SOL to cover:

  • The rent-exempt balance for the tree account
  • Transaction fees

The exact cost depends on the tree's maximum depth and buffer size, which determines how many NFTs it can store.

Examples

# Create a new Merkle tree
merkle_tree_address = MplBubblegum.Tree.create_tree_config()

# Use the tree address for minting compressed NFTs
signature = MplBubblegum.Mint.mint_v1(
  merkle_tree_address,
  "My NFT",
  "MNFT",
  "https://arweave.net/my-metadata-uri",
  creator_address,
  "100"
)