CNFT is an Elixir library for handling Compressed NFT (cNFT) transactions on the Solana blockchain. It provides a native interface through Rustler for efficient creation, minting, and transfer of compressed NFTs using the Metaplex Bubblegum protocol.
Add cnft
to your list of dependencies in mix.exs
:
def deps do
[
{:cnft, "~> 0.1.6"}
]
end
The first step in working with compressed NFTs is creating a Merkle tree configuration:
# Configure your Solana connection
rpc_client = "https://api.mainnet-beta.solana.com" # Or your preferred RPC endpoint
# Configure the payer account (must be funded)
payer = "Base58 encoded key or [bytes_array_of_private_key]"
# Configure tree parameters
# https://developers.metaplex.com/bubblegum/create-trees
max_depth = 14
max_buffer_size = 64
# Create the tree
{signature, tree_address} = CNFT.create_tree_transaction(
rpc_client,
payer,
max_depth,
max_buffer_size
)
Once you have a tree configured, you can mint compressed NFTs:
# Tree address from the creation step
tree = "treePubkeyHere123456789abcdef"
# NFT recipient
owner = "recipientPubkeyHere123456789"
# NFT metadata
name = "My Awesome NFT"
symbol = "AWESOME"
uri = "https://arweave.net/yourMetadataJson" # Should point to JSON matching Metaplex standard
seller_fee_basis_points = 500 # 5% royalty (500 basis points = 5%)
is_mutable = true # Can metadata be updated later?
nonce = 0 # Uniquely identifies this mint, increment for each subsequent mint
# mint transaction
{signature, asset_id} = CNFT.mint_v1(
rpc_client,
tree,
owner,
payer,
name,
symbol,
uri,
seller_fee_basis_points,
is_mutable,
nonce
)
Transfer an existing compressed NFT to a new owner:
receiver = "RECEIVER_PUBLIC_KEY" # The account that will receive the NFT
asset_id = "assetpublickeyaddress" # Asset ID from minting step
transfer_sign = CNFT.transfer(rpc_client, asset, owner, payer, receiver)
Returns the information of a compressed asset.
asset_id = "assetIdToLookup"
asset_details = CNFT.get_asset(rpc_client, asset_id)
Returns the merkle tree proof information for a compressed asset.
asset_id = "assetIdToLookup"
asset_prrof = CNFT.get_proof(rpc_client, asset_id)
- Store tree addresses and asset IDs securely - they're needed for all future operations.
- Increment the nonce value for each mint to the same tree.
- Verify transactions after submission by checking their status.
- Consider compression ratio when designing your collection size.

- Clone the repository
git clone https://github.com/thrishank/cnfts-elixir
cd cnfts-elixir
- Install dependencies with
mix deps.get
mix deps.get
- Ensure Rust is installed for native compilation
mix compile
- update the varaible in test/cnfts_test.exs
@rpc_client ""
@private_key ""
@owner_key ""
@receiver_key ""
- Run tests
mix test
This project is licensed under the MIT License.