Token Gating

A more detailed look at our token-gating solution

Overview

As Web3 brings new experiences to users, token gating is exploding in popularity. This new authorization method provides access to static or dynamic content based on the user’s ownership of one or more tokens. It can be used to access private discord channels, Shopify perks, digital content, and exclusive IRL events. As brands adopt Web3 and the Metaverse continues to expand, more and more projects will need to implement their own gating mechanism. From an end user's perspective, the experience of unlocking a gate should be silky smooth: a one-click process that takes milliseconds to complete. Unfortunately, in many cases today this standard isn't quite met, and as token-gating becomes more common, users will increasingly demand a 10x faster experience than traditional log-in systems.

Implementing token gating should also be effortless for developers. However, this isn't always as simple as it seems. Need to check how long a user has held a specific token? Are multiple NFT collections involved? Is the collection a Rarible or OpenSea contract with millions of different projects? Each of these scenarios require rolling your own logic and takes time away from your actual goal: bringing a delightful experience to your users.

With 3mint's token gating API, developers can create even the most complicated gating mechanics with a single call and end users are guaranteed fast response times.

If you would like to request an API key please reach out at dev@3mint.io or fill out this form!

Example Use Cases

Gate access to:

  • Single article or blog post

  • Website

  • Product on an eCommerce site

  • Webinar

  • Account

  • Live event

  • Virtual experience

Example Gating Conditions

  • User owns an NFT with a specific TokenID

  • User owns one or more NFTs within a collection

  • User holds at least 0.1 ETH or other ERC-20s

  • User has held an NFT within a collection for at least 6 months

  • User has an NFT with specific metadata attributes

How it all works

Contract Checking

Once the backend receives the list of requirements the address must meet, the tool verifies each condition individually by calling the respective Smart Contract endpoints.

Checking ERC721 balance

export const contract = new ethers.Contract(
  PROJECT_CONTRACT_ADDRESS,
  genericErc721Abi,
  getDefaultProvider([NETWORK], [PROVIDER_KEY])
)

export const walletOwnsToken = async (address: string) => {
  const [balance]: [BigNumber] = await contract.functions.balanceOf(address)
  return balance._hex >= [MIN_AMOUNT]
}

Checking ERC1155 balance

export const contract = new ethers.Contract(
  PROJECT_CONTRACT_ADDRESS,
  genericErc1155Abi,
  getDefaultProvider([NETWORK], [PROVIDER_KEY])
)

export const walletOwnsToken = async (address: string) => {
  const [balance]: [BigNumber] = await contract.functions.balanceOf(address)
  return balance._hex >= [MIN_AMOUNT]
}

Checking ERC20 balance

const ethers = require('ethers')

export const contract = new ethers.Contract(
  TOKEN_CONTRACT_ADDRESS,
  genericErc20Abi,
  getDefaultProvider([NETWORK], [PROVIDER_KEY])
)

export const walletOwnsToken = async (address: string) => {
  const [balance]: [BigNumber] = await contract.functions.balanceOf(address)
  const formatedBalance = ethers.utils.formatUnits(balance, [TOKEN_DECIMALS])
  return formatedBalance >= [MIN_AMOUNT]
}

Checking Eth balance

const ethers = require('ethers')

const network = [NETWORK]
const provider = ethers.getDefaultProvider(network, [PROVIDER_KEY])
const address = [USER_ADDRESS]

provider.getBalance(address).then((balance) => {
 // convert a currency unit from wei to ether
 const balanceInEth = ethers.utils.formatEther(balance)
 return balanceInEth >= [MIN_AMOUNT]
})

Checking time requirements

Time requirements cannot be used for requests that have a Type of "combo", it must be used with "ercnft", "erc20", "coin", etc.

For minTime and minTimestamp conditions, we pull all transfer events related to the specific NFT, token, or native coin for the wallet address included in the request and ensure the balance expected stays the same throughout these events.

Speedy Responses

We cache all long-running requests and verify their conditions asynchronously to ensure speedy response times for even the most complicated token gating requirements.

Last updated