3mint
  • 👋Welcome to 3mint
  • 💻3mint Platform
    • Introduction
    • Deploy a contract
    • Upload your NFT data
    • Create checkout links
    • Add customers
    • Monitor your links
  • ⌨️Developer Guides
    • Introduction
    • Contracts
      • Contract Architecture
      • End-to-end Example
    • Mint
      • How To
      • End-to-end Example
      • Code Snippets
    • Wallets
      • End-to-end Example
      • Mobile Pass
        • Creating Passes
    • Token Gating
      • End-to-end Example
      • Code Snippets
  • 📖API Reference
    • Overview
    • Contracts
      • Deploy Contract
      • Get Contract
    • Collectibles
      • Get All Templates
      • Mint Collectible
    • Wallets
      • Create Wallet
      • Get Wallet
    • Customers
      • Create Customer
      • Get Customer
      • Delete Customer
    • Claim Links
      • Create Link
      • Update Link
    • Token Gating
      • Create Gate
  • ❓FAQ
    • Web3 101
    • Platform
Powered by GitBook
On this page
  • 1. Get your API keys
  • 2. Check Ownership
  1. Developer Guides
  2. Token Gating

End-to-end Example

Programmatic gating for customers holding an Ethereum ERC1155 NFT

PreviousToken GatingNextCode Snippets

Last updated 2 years ago

To token gate an article, your users first need to hold the right NFT. If you want to create this NFT and send it to them, please check our example above!

1. Get your API keys

Create a account and find your API key on the Settings page.

Your API requests are authenticated using API keys. Any request that doesn't include an API key will return an error.

The key received should remain secret, which means it should only be accessed on the back end. Authorization to the API is performed via the X-API-KEY header.

2. Check Ownership

To verify whether a user has the right NFT, send an authenticated request to the tokenGate endpoint from your website. If you would like to add over parameters (length of time held, quantity held, metadata attributes, please check our Token Gating guide)

Every API request must include Content-Type and X-API-KEY headers.

curl -X POST https://api.3mint.io/api/v1/tokenGate   
   -H "Content-Type: application/json"
   -H "X-API-KEY: [YOUR_API_KEY]"
   -d '{"walletAddress": "[WALLET_OF_USER]",
       "chain": "ethereum",
       "network": "mainnet",
       "requirements": [
           {
               "type": "erc721",
               "contractAddress": "[PROJECT_CONTRACT_ADDRESS]",
               "minBalance": 1,
           }
         ] 
       }'
import axios from 'axios';

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

// Include conditions to verify
const ownerAddress = '[WALLET_OF_USER]'
const contractAddress = '[PROJECT_CONTRACT_ADDRESS]'

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

axios(config)
.then(response => console.log(response))
.catch(error => console.log(error));
import fetch from 'node-fetch';

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

// Include conditions to verify
const ownerAddress = '[WALLET_OF_USER]'
const contractAddress = '[PROJECT_CONTRACT_ADDRESS]'

var requestBody = JSON.stringify({
  'walletAddress': `${ownerAddress}`,
  'chain': 'ethereum',
  'network': 'mainnet',
  'requirements': [
         {
             'type': 'erc721',
             'contractAddress': `${contractAddress}`,
             'minBalance': 1,
         }
     ]
});

var requestOptions = {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-KEY': `${apiKey}`
  },
  body: requestBody,
};

// Make the request and print the formatted response:
fetch(fetchURL, requestOptions)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(error => console.log('error', error));

Response (by default)

{ "result" : true }
⌨️
Airdrop an NFT
3mint
The key displayed is for demonstration purposes only and will not work in production