Skip to content

Token Gate

Background

The token gating contracts offered through Sediment enable a wide variety of checks that can be used either within other smart contracts or directly within a dApp.

Additionally, the primary token gating contract offers a set of abstractions to make common checks quick and easy.

There are currently four types of gates:

  1. Token Gate - Application level abstracts to check for holders
  2. ERC-20 Gate - Token gating based only on ERC-20
  3. ERC-721 Gate - Token gating based only on ERC-721
  4. ERC-1155 Gate - Token gating based only on ERC-1155

Installation

Terminal window
npm add @dirtroad/sediment

API

Solidity API

TokenGate

A contract that provides functions to check if an address holds specific tokens

This contract inherits from the TokenChecker contract

isHolder

function isHolder(address user, address token) external view returns (bool)

Check if a user holds a given ERC-20 or ERC-721 token

Parameters

NameTypeDescription
useraddressThe address of the user to check
tokenaddressThe address of the token contract

Return Values

NameTypeDescription
[0]boolbool True if the user holds the token, false otherwise

isNFTHolder

function isNFTHolder(address user, address token, uint256 tokenId) external view returns (bool)

Check if a user holds a specific ERC-721 or ERC-1155 token ID

Parameters

NameTypeDescription
useraddressThe address of the user to check
tokenaddressThe address of the token contract
tokenIduint256The ID of the token to check

Return Values

NameTypeDescription
[0]boolbool True if the user holds the token ID, false otherwise

isERC1155Holder

function isERC1155Holder(address user, address token, uint256[] ids) external view returns (bool)

Check if a user holds any of the specified ERC-1155 token IDs

Parameters

NameTypeDescription
useraddressThe address of the user to check
tokenaddressThe address of the ERC-1155 token contract
idsuint256[]An array of token IDs to check

Return Values

NameTypeDescription
[0]boolbool True if the user holds any of the token IDs, false otherwise

isERC721Holder

function isERC721Holder(address user, address token, uint256[] ids) external view returns (bool)

Check if a user holds any of the specified ERC-721 token IDs

Parameters

NameTypeDescription
useraddressThe address of the user to check
tokenaddressThe address of the ERC-721 token contract
idsuint256[]An array of token IDs to check

Return Values

NameTypeDescription
[0]boolbool True if the user holds any of the token IDs, false otherwise