6

I want to use bubblegum, Metaplex's compressed NFT standard in my project.

I want to have token-gated functions that check the balance of token accounts for compressed NFTs.

Do I have to redeem the NFTs? Can I just create a temporary voucher? Is there a proof I can use to check leaf ownership?

1 Answer 1

6

Quick answers:

To quickly and specifically answer your questions:

  • you do not have to redeem NFTs
  • you do not need a voucher or anything similar
  • you can use the ReadApi to see what compressed NFTs an address owns (or even check an entire collection's owners)

Background

With compressed NFTs, you will have to use an RPC provider that supports the new Digital Asset Standard Read Api (ReadApi for short). The ReadApi adds extra RPC endpoints you can send requests to in order to get tons of information on NFTs (both compressed and traditional/uncompressed NFTs). But these "extra" RPC endpoints won't work on non-supporting providers.

Right now, a few common providers have support. Like Helius, Triton, and SimpleHash.

You can use the ReadApi playground to see the current RPC methods available and the data you can get from them.

Details

For your use case of trying to do some token gating, I would use either the getAssetsByOwner and/or getAssetsByGroup endpoints on the ReadApi. These will return a list of assets that you can parse and determine how you want to set the access restrictions for your app.

An example asset response might look like this:

{
      interface: 'V1_NFT',
      id: 'FX1wWj25bNQJh4gZquH5EMEQtooxg7CzkBxXmziBgeay',
      content: [Object],
      authorities: [Array],
      compression: [Object],
      grouping: [],
      royalty: [Object],
      creators: [],
      ownership: [Object],
      supply: [Object],
      mutable: false
}

I would also recommend paying special attention to these values:

  • id - (aka assetId) this is effectively your compressed NFTs address. sort of. see below.
  • grouping - can tell you the collection address that the NFT belongs to. The collection address will be the group_value.
  • ownership - gives you the NFT owner's address (and also if the NFT has delegated authority to another address)
  • compression - tells you if this NFT is actually using compression or not. This will also give you the tree address that is storing the compressed NFT on chain. This could be useful for token gating, but would depend on your implementation.

NOTE: Some of the values will be empty if the NFT is not a compressed NFT. (such as many of the compression fields). So keep that in mind.

The assetId

If the asset returned is a traditional/uncompressed NFT, this value will be the actual NFTs address viewable via an explorer.

If the asset returned is a compressed NFT, the value is NOT an actual account. It is the leaf node's label within the tree. Due to how merkle trees work, this "address looking value" is not viewable using an explorer the same way a regular Solana address is.

The two are not the same. Once explorers add better support for compressed NFTs, I'm sure we will be able to better explore compressed NFTs. (PS: this was written in March of 2023)

Example of these more useful data fields:

assetId: 5q7qQ4FWYyj4vnFrivRBe6beo6p88X8HTkkyVPjPkQmF
ownership: {
  frozen: false,
  delegated: false,
  delegate: null,
  ownership_model: 'single',
  owner: '3aDhr6bXvXAoZg2DtgvxcPa29fydTvHaCNQPYrwcuoSP'
}
grouping: [
  {
    group_key: 'collection',
    group_value: 'G3Tc3QphQK1EjSdLKcgPjtbQyssr2EXDtzeZevzg4tMS'
  }
]
compression: {
  eligible: false,
  compressed: true,
  data_hash: 'D57LAefACeaJesajt6VPAxY4QFXhHjPyZbjq9efrt3jP',
  creator_hash: '6Q7xtKPmmLihpHGVBA6u1ENE351YKoyqd3ssHACfmXbn',
  asset_hash: 'F3oDH1mJ47Z7tNBHvrpN5UFf4VAeQSwTtxZeJmn7q3Fh',
  tree: 'BBUkS4LZQ7mU8iZXYLVGNUjSxCYnB3x44UuPVHVXS9Fo',
  seq: 3,
  leaf_id: 0
}

PS: This is from a devnet collection, tree, and NFT. You could lookup the account addresses on an explorer if you want.

Checkout this demo repo and code examples

You can also checkout this demo repo on the Solana Developers GitHub: https://github.com/solana-developers/compressed-nfts

It has a bunch of example code on how to do quite a bit with compressed NFTs, and lots of comments to explain things throughout the files.

4
  • This is a really great answer!
    – ngundotra
    Mar 31, 2023 at 13:39
  • Thanks @ngundotra!
    – nickfrosty
    Mar 31, 2023 at 15:50
  • Thanks a lot for this incredible answers but I was mostly curious about the on-chain use case where I want to know the balance of a compressed token from a program Apr 3, 2023 at 23:04
  • The balance would always be 1 since these are compressed nfts
    – nickfrosty
    Apr 7, 2023 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.