# Code Snippets

{% hint style="info" %}
**SDK Coming Soon**

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

{% hint style="info" %}
**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.**
{% endhint %}

## NFT Ownership

### User owns 2 ERC721 NFTs

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

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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
           }
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
            'type': 'erc721',
            'contractAddress': '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
            'minBalance': 2,
            'maxBalance': 2
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));
```

{% endcode %}
{% endtab %}
{% endtabs %}

### 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.

{% hint style="info" %}
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.
{% endhint %}

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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
            }
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
            'type': 'erc1155',
            'contractAddress': '0xf6793da657495ffeff9ee6350824910abc21356c',
            'tokenIds': [
                9720425186420365222353899819497168751076639606951250294350818944954633551881,
                9720425186420365222353899819497168751076639606951250294350818944954633551883,
                9720425186420365222353899819497168751076639606951250294350818944954633551885,
                ...
            ],
            'minBalance': 1
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));
```

{% endcode %}
{% endtab %}
{% endtabs %}

### User owns multiple ERC721 NFTs from different collections

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

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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
            }
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
          'type': 'erc721',
          'contractAddress': '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
          'minBalance': 1
          },
          {
          'logic': 'and',
          'type': 'erc721',
          'contractAddress': '0x552a43cb61bc127d81b1f280bc39f62e5a51c0c2',
          'minBalance': 2
          },
       ]
    }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));
```

{% endcode %}
{% endtab %}
{% endtabs %}

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

{% hint style="warning" %}
You cannot have both minTime and minBalance parameters set in the same object request.
{% endhint %}

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.

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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"
            },
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    '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'
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));
```

{% endcode %}
{% endtab %}
{% endtabs %}

### User owns 1 ERC721 NFT since the beginning of 2022

{% hint style="warning" %}
minTimestamp must follow format in example below (e.g., 2014-09-08T08:02:17.160Z)
{% endhint %}

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

{% tabs %}
{% tab title="cURL" %}

```json
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"
            },
         ] 
       }'
```

{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
            'type': 'erc721',
            'contractAddress': '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
            'minBalance': 1,
            'minTimestamp': '2022-01-01T00:00:00.000Z'
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));
```

{% endcode %}
{% endtab %}
{% endtabs %}

### 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.

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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"
                    }
                ],
            },
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
            'type': 'erc721',
            'contractAddress': '0xBC4CA0EdA7647A8aB7C2061c2E118A18a936f13D',
            'minBalance': 1,
            'attributes': [
                {
                    'traitType': 'Type',
                    'value': 'Female 2'
                },
                {
                    'traitType': 'Attribute',
                    'value': 'Wild Blonde'
                }
            ],
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));javascr
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Token Ownership

{% hint style="info" %}
Token balance amounts can include decimals.
{% endhint %}

### Address owns at least 2 WETH

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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
            },
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
            'type': 'erc20',
            'contractAddress': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
            'minBalance': 2
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));javascr
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Address has held at least 2 WETH for 30 days

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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"
            },
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
            'type': 'erc20',
            'contractAddress': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
            'minBalance': 2,
            'minTime': '0.0.30.0.0'
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));javascr
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Coin Ownership

{% hint style="info" %}
Coin balance amounts can include decimals.
{% endhint %}

### Address owns at least 2.5 ETH

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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
            },
         ] 
       }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    'walletAddress': '0x958fb436dB50DB2F689C364712113cc226b38151',
    'chain': 'ethereum',
    'network': 'mainnet',
    'requirements': [
         {
            'type': 'coin',
            'minBalance': 2.5,
        },
     ]
   }
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));javascr
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Combos

{% hint style="info" %}
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...
{% endhint %}

### User owns 5 ETH or 2 WETH plus 1 to 4 ERC721 NFTs&#x20;

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

{% tabs %}
{% tab title="cURL" %}
{% code lineNumbers="true" %}

```json
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
                    }
                ]
            }
        ]
   }'
```

{% endcode %}
{% endtab %}

{% tab title="Axios (JS)" %}
{% code lineNumbers="true" %}

```javascript
import axios from 'axios';

// replace with your 3mint api key
const apiKey = 'demo';
const url = 'https://api.3mint.io/api/v1/tokenGate';

var requestOptions = {
  method: 'POST',
  url: `${url}`,
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  data: {
    '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
                }
            ]
        },
     ]
  } 
};

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));javascr
```

{% endcode %}
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.3mint.io/developer-guides/token-gating/code-snippets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
