Otterspace Docs
  • Overview
    • ๐ŸฆฆIntro to Otterspace
    • ๐Ÿ”‘Key Concepts
      • ๐Ÿ”ฅBurning and revocation
      • โณExpiration
      • ๐Ÿค“Metadata schemas
    • โ“F.A.Q
  • Documentation
    • ๐Ÿ”ŒAPI
      • ๐Ÿ”Authentication
    • ๐Ÿ™Subgraph
    • ๐Ÿ› ๏ธContracts
      • ๐ŸŽจCreate a Badge Spec
      • ๐Ÿช‚Airdrop a Badge
      • โœ…Adding to allowlist
      • ๐ŸคMinting allowlisted Badges
      • โž•Add/Remove Admins
  • Guides
    • ๐Ÿ”Token-gating using badges
  • Integrations
    • Using badges with Snapshot
    • Guild.xyz for token gating
    • Using with Gnosis Safe
    • On OpenSea, Metamask etc
  • Get Help
    • ๐Ÿ•บDiscord/Twitter
Powered by GitBook
On this page
  • Finding the badge spec id
  • Fetching all the holders of a badge spec
  • Does an address hold a Badge belonging to this spec?
  • Filtering out expired and revoked Badges
  • Filtering by community

Was this helpful?

  1. Guides

Token-gating using badges

PreviousAdd/Remove AdminsNextUsing badges with Snapshot

Last updated 1 year ago

Was this helpful?

Token gating by Badge spec implies that only holders of Badges belonging to one or more specs are able to get through the token gate.

Finding the badge spec id

First, you need to get the id of the Badge Spec that you used to issue badges to different addresses.

You can find the Badge spec id in the url of the Badge page.

https://beta.otterspace.xyz/badges/bafyreifcjs56sk5gseb75e45rjebh4kwln3trwi6aphhacf727lkshq74e 

Fetching all the holders of a badge spec

You can use our to fetch all the badge owners of that spec

{
  badgeSpec(id: "bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e") {
    id
    metadata {
      name
      description
      image
      expiresAt
    }
    totalBadgesCount
    badges {
      id
      owner
      createdAt
    }
  }
}

Does an address hold a Badge belonging to this spec?

If you already know the address of a user, you can simply check if this address owns a badge with the spec that you intend to gate. For example, see the query below. Here weโ€™re checking if the address 0x77B476429826C5ba77885D08F272d89D8F1Ed0e4 owns a Pioneer badge issued by the Otterspace Raft.

{
  badges(where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4", spec: "bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e"}) {
    id
    createdAt
    owner
    createdAt
    spec {
      id
      metadata {
        name
      }
      raft {
        id
        metadata {
          name
        }
      }
    }
  }
}

And if youโ€™d like to check if an address owns one of the badges, simply use spec_in filter

{
  badges(
    where: {owner: "0x77B476429826C5ba77885D08F272d89D8F1Ed0e4", spec_in: ["bafyreicl3unvw6tvzjfduvrhxbfi74gsob6mpf6ekn3s2nkopqz2phtx7e","bafyreia2lnu2jmr6sqqijzd3xt6fw2qriyy2vbq57zikzrkeyxfvlpqp3i"]}
  ) {
    id
    createdAt
    owner
    createdAt
    spec {
      id
      metadata {
				name
			}
      raft {
        id
        metadata {
					name 
				}
      }
    }
  }
}

Filtering out expired and revoked Badges

One thing that makes Badges different from other NFTs is that they can expire. Expired Badges shouldnโ€™t be able to be used to access spaces and resources. You can check if a Badge is expired by looking at the expiry date in the metadata.

Filtering by community

If you are building a token-gating UI, you probably want to allow an account admin to select from the Badge Specs belonging to that account.

The unique identifier of a Raft is the Token Id of an ERC721 token which is airdropped to the community during its formation. The Raft Id can be found in the communityโ€™s profile url.

https://beta.otterspace.xyz/communities/1

๐Ÿ”
subgraph