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:
Token Gate - Application level abstracts to check for holders
ERC-20 Gate - Token gating based only on ERC-20
ERC-721 Gate - Token gating based only on ERC-721
ERC-1155 Gate - Token gating based only on ERC-1155
Installation
npm add @dirtroad/sediment
yarn add @dirtroad/sediment
pnpm 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
Name Type Description user address The address of the user to check token address The address of the token contract
Return Values
Name Type Description [0] bool bool 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
Name Type Description user address The address of the user to check token address The address of the token contract tokenId uint256 The ID of the token to check
Return Values
Name Type Description [0] bool bool 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
Name Type Description user address The address of the user to check token address The address of the ERC-1155 token contract ids uint256[] An array of token IDs to check
Return Values
Name Type Description [0] bool bool 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
Name Type Description user address The address of the user to check token address The address of the ERC-721 token contract ids uint256[] An array of token IDs to check
Return Values
Name Type Description [0] bool bool True if the user holds any of the token IDs, false otherwise
Solidity API
ERC20Gate
This contract allows checking the balance of ERC20 tokens for a given user.
token
minBalance
constructor
constructor ( contract IERC20 _token , uint256 _minBalance ) public
Constructor to initialize the contract with the ERC20 token and minimum balance requirements.
Parameters
Name Type Description _token contract IERC20 The address of the ERC20 token contract. _minBalance uint256 The minimum balance required for certain operations.
hasSufficientBalance
function hasSufficientBalance ( address user ) external view returns ( bool )
Checks if the user has a balance of ERC20 tokens greater than or equal to the specified minimum balance.
Parameters
Name Type Description user address The address of the user to check.
Return Values
Name Type Description [0] bool A boolean indicating whether the user has the required balance or not.
isHolder
function isHolder ( address user ) external view returns ( bool )
Checks if the user has a balance of ERC20 tokens greater than -
Parameters
Name Type Description user address The address of the user to check.
Return Values
Name Type Description [0] bool A boolean indicating whether the user is a holder.
Solidity API
ERC721Gate
This contract allows checking various conditions related to ERC721 tokens.
token
minBalance
constructor
constructor ( contract IERC721 _token , uint256 _minBalance ) public
Constructor to initialize the contract with the ERC721 token and minimum balance requirements.
Parameters
Name Type Description _token contract IERC721 The address of the ERC721 token contract. _minBalance uint256 The minimum balance required for certain operations.
hasSufficientBalance
function hasSufficientBalance ( address user ) external view returns ( bool )
Checks if the user has a balance of ERC721 tokens greater than or equal to the specified minimum balance.
Parameters
Name Type Description user address The address of the user to check.
Return Values
Name Type Description [0] bool A boolean indicating whether the user has the required balance or not.
isOwner
function isOwner ( address user , uint256 tokenId ) external view returns ( bool )
Checks if a user is the owner of a specific ERC721 token.
Parameters
Name Type Description user address The address of the user to check. tokenId uint256 The ID of the ERC721 token to check ownership for.
Return Values
Name Type Description [0] bool A boolean indicating whether the user is the owner of the specified token or not.
isHolder
function isHolder ( address user ) external view returns ( bool )
Checks if a user holds at least one ERC721 token.
Parameters
Name Type Description user address The address of the user to check.
Return Values
Name Type Description [0] bool A boolean indicating whether the user holds at least one ERC721 token.
Solidity API
ERC1155Gate
This contract allows checking various conditions related to ERC1155 tokens.
token
tokenIds
constructor
constructor ( contract IERC1155 _token , uint256 [] _tokenIds ) public
Constructor to initialize the contract with the ERC1155 token and token IDs.
Parameters
Name Type Description _token contract IERC1155 The address of the ERC1155 token contract. _tokenIds uint256[] An array of token IDs to track.
isHolder
function isHolder ( address user ) external view returns ( bool )
Checks if the user holds at least one instance of any of the tracked token IDs.
Parameters
Name Type Description user address The address of the user to check.
Return Values
Name Type Description [0] bool A boolean indicating whether the user holds at least one instance of any tracked token.
isHolderInRange
function isHolderInRange ( address user , uint256 [] ids ) external view returns ( bool )
Checks if the user holds at least one instance of any of the token IDs within a specified range.
Parameters
Name Type Description user address The address of the user to check. ids uint256[] An array of token IDs to check within the range.
Return Values
Name Type Description [0] bool A boolean indicating whether the user holds at least one instance of any tracked token within the range.
isHolderByToken
function isHolderByToken ( address user , uint256 tokenId ) external view returns ( bool )
Checks if the user holds at least one instance of a specific token ID.
Parameters
Name Type Description user address The address of the user to check. tokenId uint256 The token ID to check.
Return Values
Name Type Description [0] bool A boolean indicating whether the user holds at least one instance of the specified token ID.
isBalanceSufficient
function isBalanceSufficient ( address user , uint256 tokenId , uint256 minimumAmount ) external view returns ( bool )
Checks if the user’s balance of a specific token ID is greater than or equal to a specified minimum amount.
Parameters
Name Type Description user address The address of the user to check. tokenId uint256 The token ID to check. minimumAmount uint256 The minimum amount required for the token balance.
Return Values
Name Type Description [0] bool A boolean indicating whether the user’s balance of the specified token ID meets the minimum amount requirement.