Key Terms

Badge Spec The blueprint of a Badge, from which several Badges can be minted.
Badge The actual EIP4973 NFT held in someone’s wallet.
Raft What we call communities and sub-communities at Otterspace
Raft Token The ERC721 token used to identify a community. The token id is the unique identifier of the community.

Finding the Badge Spec id

You can easily build token gate for your community or your tool using Otterspace Badges. Firstly 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 subgraph 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 community. Note, communities are expressed as Rafts in Otterspace.

{
  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 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