Code Snippets

Different ways to token gate

SDK Coming Soon

With the release of our SDK, you'll be able to easily integrate all features within your framework of choice.

Demo API key

You can test the token gating API endpoint using "demo" as the API key. This will work for test networks and is rate limited. This cannot yet be used for airdrop and wallets APIs.

NFT Ownership

User owns 2 ERC721 NFTs

This example verifies that an address holds exactly 2 NFTs from the Bored Ape Yacht Club collection.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "type": "erc721",
               "contractAddress": "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
               "minBalance": 2,
               "maxBalance": 2
           }
         ] 
       }'

User owns at least 1 ERC1155 with a specific token ID

This example verifies that an address holds at least one NFT from the Crypto Baristas collection.

Since the smart contracts that OpenSea and Rarible provide have thousands of different NFT projects listed on them, the only way to accurately token gate something is by including the different IDs that a user should own.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "type": "erc1155",
                "contractAddress": "0xf6793da657495ffeff9ee6350824910abc21356c",
                "tokenIds": [
                    9720425186420365222353899819497168751076639606951250294350818944954633551881,
                    9720425186420365222353899819497168751076639606951250294350818944954633551883,
                    9720425186420365222353899819497168751076639606951250294350818944954633551885,
                    ...
                ],
                "minBalance": 1
            }
         ] 
       }'

User owns multiple ERC721 NFTs from different collections

This example verifies that an address holds at least 1 Bored Ape and two ApeDocs NFT.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
                "type": "erc721",
                "contractAddress": "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
                "minBalance": 1
            },
            {
                "logic": "and",
                "type": "erc721",
                "contractAddress": "0x552a43cb61bc127d81b1f280bc39f62e5a51c0c2",
                "minBalance": 2
            }
         ] 
       }'

User owns 1 ERC721 NFT for at least 6 months and 10 days

You cannot have both minTime and minBalance parameters set in the same object request.

This example verifies that an address has held 1 NFT from the Bored Ape Yacht Club collection for at least 6 months and 10 days.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "contractType": "erc721",
               "contractAddress": "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
               "minBalance": 1,
               "minTime": "0.6.10.0.0" //format: "years.months.days.hours.minutes"
            },
         ] 
       }'

User owns 1 ERC721 NFT since the beginning of 2022

minTimestamp must follow format in example below (e.g., 2014-09-08T08:02:17.160Z)

This example verifies that an address has held 1 NFT from the Bored Ape Yacht Club collection since the beginning of 2022.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "type": "erc721",
               "contractAddress": "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
               "minBalance": 1,
               "minTimestamp": "2022-01-01T00:00:00.000Z"
            },
         ] 
       }'

User owns 1 ERC721 NFT with specific metadata attributes

This example verifies that an address holds at least 1 Crypto Punk with two attribute types.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
                "type": "erc721",
                "contractAddress": "0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D",
                "minBalance": 1,
                "attributes": [
                    {
                        "traitType": "Type",
                        "value": "Female 2"
                    },
                    {
                        "traitType": "Attribute",
                        "value": "Wild Blonde"
                    }
                ],
            },
         ] 
       }'

Token Ownership

Token balance amounts can include decimals.

Address owns at least 2 WETH

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "type": "erc20",
               "contractAddress": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
               "minBalance": 2
            },
         ] 
       }'

Address has held at least 2 WETH for 30 days

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "type": "erc20",
               "contractAddress": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
               "minBalance": 2,
               "minTime": "0.0.30.0.0"
            },
         ] 
       }'

Coin Ownership

Coin balance amounts can include decimals.

Address owns at least 2.5 ETH

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "type": "coin",
               "chain": "ethereum"
               "network": "mainnet",
               "minBalance": 2.5
            },
         ] 
       }'

Combos

Combos can be deeply nested (i.e., you can have a combo within a combo). This allows you to do complex token gating mechanisms, like:

if ((A and B) or (C and (D or E))), then...

User owns 5 ETH or 2 WETH plus 1 to 4 ERC721 NFTs

This example verifies that an address holds at least 5 ETH or 2 WETH and 1 to 4 ApeDocs NFTs.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "0x958fb436dB50DB2F689C364712113cc226b38151",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
            {
                "type": "coin",
                "minBalance": 5
            },
            {
                "logic": "or",
                "type": "combo",
                "requirements": [
                    {
                        "type": "erc20",
                        "contractAddress": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
                        "minBalance": 2
                    },
                    {
                        "logic": "and",
                        "type": "erc721",
                        "contractAddress": "0x552a43cb61bc127d81b1f280bc39f62e5a51c0c2",
                        "minBalance": 1,
                        "maxBalance": 4
                    }
                ]
            }
        ]
   }'

Last updated