- Notifications
You must be signed in to change notification settings - Fork41
solana-developers/compressed-nfts
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
At a high level, state compression is a technique in which off-chain data is secured by the Solanaledger, using a hashing algorithm to "fingerprint" theoff-chain data and storing it inside aspecialon-chain Merkle tree, called a Concurrent Merkle Tree.
With this technology, compressed NFTs can be created on-chain in a similar manner as before, but fora fraction of the cost as before. As a frame of reference of on-chain cost reduction, take a 1million NFT collection:
- traditional NFTs (aka non-compressed):
- 1 million NFTs ~= 12,000 SOL
- compressed NFTs:
- 1 million NFTs ~= 5 SOL
- Solana Docs forState Compression
- written guideminting compressed NFTs (whichis based on this repo)
- uses TypeScript and NodeJS
- yarn (as the node package manager)
- Clone this repo to your local system
- Install the packages via
yarn install - Rename the
example.envfile to be named.env - Update the
RPC_URLvariable to be the cluster URL of a supporting RPC provider
If you have the Solana CLI installed locally: update theLOCAL_PAYER_JSON_ABSPATH environmentvariable to be theabsolute path of your local testing wallet keypair JSON file.
After setting up locally, I recommend exploring the code of the following files (in order):
After reviewing the code, then running each of these scripts in the same order.
Note: Running each of these scripts will save some bits of data to a
.local_keysfolderwithin this repo for use by the other scripts later in this ordered list. Therefore, running themin a different order will result in them not working as written. You have been warned :)
Once you're setup locally, you will be able to run the scripts included within this repo:
yarn demo ./scripts/<script>Performs all the following actions:
- create a new Merkle tree on-chain
- create a new NFT collection
- mint two compressed NFTs (to different addresses)
Functionally the same asscripts/createAndMint.ts. This script adds extra console logging andcomments for explanation purposes.
Uses the ReadApifetchAssetsByOwner method to fetch the NFTs owners by the two addresses.
Uses the ReadApifetchAssetsByGroup method to fetch the NFTs belonging to the same collection,compressed or otherwise.
Performs the complete process to transfer compressed NFTs. Specifically:
- fetching the NFT asset data from the RPC
- fetching the asset's proof from the RPC
- verifying the RPC provided proof on the client side
- builds the compressed NFT transfer function
Mint additional compressed NFTs into an already existing collection and/or tree.
This repo also contains code examples of how to use the@metaplex-foundation/js sdk to work withcompressed NFTs, including reading and transferring them.
After setting up locally, I recommend exploring the code of the following metaplex specific files(in order):
./metaplex/mintToCollection.ts./metaplex/transferNFT.ts./metaplex/fetchNFTsByOwner.ts./metaplex/simpleProofVerification.ts
Mint a single compressed NFT to an existing tree and collection, using the metaplex sdk. Thisrequires you to create your tree and collection ahead of time. See the./scripts/verboseCreateAndMint.ts script for details on howto create a tree and collection.
Transfer a compressed NFT using the metaplex sdk. This method only requires you to know theassetId of the compressed NFT to transfer.
Uses the ReadApifetchAssetsByOwner method to fetch the NFTs owned by a single address.
Uses the ReadApifetchAssetsByGroup method to fetch the NFTs belonging to the same collection,compressed or otherwise.
Mint additional compressed NFTs into an already existing collection and/or tree.
- Solana Docs:
- State Compression
- Guide for compressed NFTs(which is based on this repo)
- Account Compression SPL Program:
- Metaplex Read API:
- Metaplex Compression examples:
About
Example code to use compressed NFTs (using state compression) on Solana
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.