DEV Community

Cover image for Token Gating Websites with Collab.Land
Ekene Eze (Kenny)
Ekene Eze (Kenny)

Posted on • Originally published at mirror.xyz

Token Gating Websites with Collab.Land

Token gating is the idea of using tokens as a means of verifying membership or access to a community or resource. This can be done by requiring users to possess certain tokens in order to join a community or access certain resources.

This concept has gained significant traction in recent years, particularly within decentralized autonomous organizations (DAOs) and non-fungible token (NFT) communities. At its core, token gating involves using tokens to grant or restrict access to a community or resource. In this blog post, we'll explore the history, use cases, advantages, challenges, and future of token gating. We’ll also explore the possibilities of extending its current usage to cater for developers building for the web.

Yesterday, Collab.Land announced a new /access-control endpoint for its token gating API that allows developers to control access to their websites and web applications based on the possession of specific tokens.

The endpoint accepts two parameters:

account - The wallet address of the user.

rules - The token gating rules that specifies the token(s) to look for in the users address.

For each rule, Collab.Land will return a response indicating whether or not the rule has been granted or denied for the user. Here’s a sample request to the Collab.Land /access-control endpoint:

POST: https://api.collab.land/access-control/check-roles

BODY:

{
  "account": "0x01c20350ad8f434bedf6ea901203ac4cf7bca295",
  "rules": [
    {
      "type": "ERC721",
      "chainId": 1,
      "minToken": "1",
      "contractAddress": "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d",
      "roleId": "001"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Where account represents the users wallet address and rules is an array of objects representing each rule to be checked against the users wallet.

This call would return a sample response like this:

{
  "roles": [
    {
      "id": "001",
      "granted": true
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

To learn more about the Collab.Land token gating APIs, please read the official documentation or dive into a practical tutorial to build a gated website in minutes. You can also get your hands dirty with the Github repo. Want to build a token-gated website with JavaScript? here’s a sample code snippet to call the Collab.Land TGR endpoint using fetch:

const res = await fetch(`https://api.collab.land/access-control/check-roles`, {
method: 'POST',
headers: new Headers({
    Accept: 'application/json',
    'X-API-KEY': process.env.COLLABLAND_KEY,
    'Content-Type': 'application/json',
}),
body: JSON.stringify({
    account: myWalletAddr,
    rules: [
      {},
      {}
    ]
  })
});
Enter fullscreen mode Exit fullscreen mode

Using the website token gating APIs, Collab.Land extends the successful patterns of token-granted access to communities and DAOs to the web. You can learn how to build a token-gated website here or watch the video tutorial below

Top comments (0)