{"id":13454830,"url":"https://github.com/solana-developers/compressed-nfts","last_synced_at":"2025-08-22T00:32:01.562Z","repository":{"id":158254251,"uuid":"618113024","full_name":"solana-developers/compressed-nfts","owner":"solana-developers","description":"Example code to use compressed NFTs (using state compression) on Solana","archived":false,"fork":false,"pushed_at":"2024-01-18T14:24:41.000Z","size":230,"stargazers_count":119,"open_issues_count":1,"forks_count":38,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-12-11T12:43:25.474Z","etag":null,"topics":["compressed-nfts","compression","metaplex","nfts","solana","state-compression"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/solana-developers.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-23T19:27:12.000Z","updated_at":"2024-12-02T00:59:10.000Z","dependencies_parsed_at":"2024-01-18T16:32:21.669Z","dependency_job_id":"7e7ee092-9ba0-4be3-a8ca-3b519d7f9569","html_url":"https://github.com/solana-developers/compressed-nfts","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solana-developers%2Fcompressed-nfts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solana-developers%2Fcompressed-nfts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solana-developers%2Fcompressed-nfts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/solana-developers%2Fcompressed-nfts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/solana-developers","download_url":"https://codeload.github.com/solana-developers/compressed-nfts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230542288,"owners_count":18242332,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compressed-nfts","compression","metaplex","nfts","solana","state-compression"],"created_at":"2024-07-31T08:00:58.304Z","updated_at":"2024-12-20T06:07:04.045Z","avatar_url":"https://github.com/solana-developers.png","language":"TypeScript","readme":"# State Compression and Compressed NFTs\n\nAt a high level, state compression is a technique in which off-chain data is secured by the Solana\nledger, using a hashing algorithm to \"fingerprint\" the _off-chain_ data and storing it inside a\nspecial _on-chain_ Merkle tree, called a Concurrent Merkle Tree.\n\nWith this technology, compressed NFTs can be created on-chain in a similar manner as before, but for\na fraction of the cost as before. As a frame of reference of on-chain cost reduction, take a 1\nmillion NFT collection:\n\n- traditional NFTs (aka non-compressed):\n  - 1 million NFTs ~= 12,000 SOL\n- compressed NFTs:\n  - 1 million NFTs ~= 5 SOL\n\n## Quick links to learn more\n\n- Solana Docs for [State Compression](https://docs.solana.com/learn/state-compression)\n- written guide\n  [minting compressed NFTs](https://solana.com/developers/guides/javascript/compressed-nfts) (which\n  is based on this repo)\n\n## Tech stack of this repo\n\n- uses TypeScript and NodeJS\n- yarn (as the node package manager)\n\n## Setup locally\n\n1. Clone this repo to your local system\n2. Install the packages via `yarn install`\n3. Rename the `example.env` file to be named `.env`\n4. Update the `RPC_URL` variable to be the cluster URL of a supporting RPC provider\n\nIf you have the Solana CLI installed locally: update the `LOCAL_PAYER_JSON_ABSPATH` environment\nvariable to be the **_absolute path_** of your local testing wallet keypair JSON file.\n\n## Recommended flow to explore this repo\n\nAfter setting up locally, I recommend exploring the code of the following files (in order):\n\n1. [`./scripts/verboseCreateAndMint.ts`](./scripts/verboseCreateAndMint.ts)\n2. [`./scripts/fetchNFTsByOwner.ts`](./scripts/fetchNFTsByOwner.ts)\n3. [`./scripts/transferNFT.ts`](./scripts/transferNFT.ts)\n\nAfter reviewing the code, then running each of these scripts in the same order.\n\n\u003e **Note:** Running each of these scripts will save some bits of data to a `.local_keys` folder\n\u003e within this repo for use by the other scripts later in this ordered list. Therefore, running them\n\u003e in a different order will result in them not working as written. You have been warned :)\n\n### Running the included Scripts\n\nOnce you're setup locally, you will be able to run the scripts included within this repo:\n\n```\nyarn demo ./scripts/\u003cscript\u003e\n```\n\n#### `scripts/createAndMint.ts`\n\nPerforms all the following actions:\n\n- create a new Merkle tree on-chain\n- create a new NFT collection\n- mint two compressed NFTs (to different addresses)\n\n#### `scripts/verboseCreateAndMint.ts`\n\nFunctionally the same as `scripts/createAndMint.ts`. This script adds extra console logging and\ncomments for explanation purposes.\n\n#### `scripts/fetchNFTsByOwner.ts`\n\nUses the ReadApi `fetchAssetsByOwner` method to fetch the NFTs owners by the two addresses.\n\n#### `scripts/fetchNFTsByCollection.ts`\n\nUses the ReadApi `fetchAssetsByGroup` method to fetch the NFTs belonging to the same collection,\ncompressed or otherwise.\n\n#### `scripts/transferNFT.ts`\n\nPerforms the complete process to transfer compressed NFTs. Specifically:\n\n- fetching the NFT asset data from the RPC\n- fetching the asset's proof from the RPC\n- verifying the RPC provided proof on the client side\n- builds the compressed NFT transfer function\n\n#### `scripts/mintToCollection.ts`\n\nMint additional compressed NFTs into an already existing collection and/or tree.\n\n## Metaplex sdk examples\n\nThis repo also contains code examples of how to use the\n[`@metaplex-foundation/js`](https://www.npmjs.com/package/@metaplex-foundation/js) sdk to work with\ncompressed NFTs, including reading and transferring them.\n\nAfter setting up locally, I recommend exploring the code of the following metaplex specific files\n(in order):\n\n1. [`./metaplex/mintToCollection.ts`](./metaplex/mintToCollection.ts)\n2. [`./metaplex/transferNFT.ts`](./metaplex/transferNFT.ts)\n3. [`./metaplex/fetchNFTsByOwner.ts`](./metaplex/fetchNFTsByOwner.ts)\n4. [`./metaplex/simpleProofVerification.ts`](./metaplex/simpleProofVerification.ts)\n\n#### `metaplex/mintToCollection.ts`\n\nMint a single compressed NFT to an existing tree and collection, using the metaplex sdk. This\nrequires you to create your tree and collection ahead of time. See the\n[`./scripts/verboseCreateAndMint.ts`](./scripts/verboseCreateAndMint.ts) script for details on how\nto create a tree and collection.\n\n#### `metaplex/transferNFT.ts`\n\nTransfer a compressed NFT using the metaplex sdk. This method only requires you to know the\n`assetId` of the compressed NFT to transfer.\n\n#### `metaplex/fetchNFTsByOwner.ts`\n\nUses the ReadApi `fetchAssetsByOwner` method to fetch the NFTs owned by a single address.\n\n#### `metaplex/fetchNFTsByGroup.ts`\n\nUses the ReadApi `fetchAssetsByGroup` method to fetch the NFTs belonging to the same collection,\ncompressed or otherwise.\n\n#### `metaplex/simpleProofVerification.ts`\n\nMint additional compressed NFTs into an already existing collection and/or tree.\n\n## Resources on State Compression and Compressed NFTS\n\n- Solana Docs:\n  - [State Compression](https://edge.docs.solana.com/learn/state-compression)\n  - [Guide for compressed NFTs](https://edge.docs.solana.com/developing/guides/compressed-nfts)\n    (which is based on this repo)\n- Account Compression SPL Program:\n  - Documentation - https://spl.solana.com/account-compression\n  - Repository -\n    https://github.com/solana-labs/solana-program-library/tree/master/account-compression\n- Metaplex Read API:\n  - open spec:\n    https://github.com/metaplex-foundation/api-specifications/tree/main/specifications/read_api\n  - Playground - https://metaplex-read-api.surge.sh/\n- Metaplex Compression examples:\n  - https://github.com/metaplex-foundation/compression-read-api-js-examples\n  - Bubblegum program - https://github.com/metaplex-foundation/mpl-bubblegum\n","funding_links":[],"categories":["TypeScript","Compression"],"sub_categories":["Gaming"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolana-developers%2Fcompressed-nfts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsolana-developers%2Fcompressed-nfts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsolana-developers%2Fcompressed-nfts/lists"}