Emblem Vault
  • 👋Introduction
  • Information
    • 💡Explainer
    • 📜History
    • 📈COVAL
    • 🦄Collections
    • 📲Apply
  • How it Works
    • ⏩Vault Creation
    • 🔄Vault Minting
    • ⏪Unvaulting
  • Features & Products
    • 📈Emblem Markets
    • 🔒Emblem Vision
    • 🛒Bulk Features
    • ⬆️Jump
    • 🐃Migration
    • 🥷Stealth Vaults
    • ⏰Time-locked Vaults
    • 🚀Vaultpad
  • Tools
    • 💿Emblem SDK
    • 📓API Documentation (Legacy)
      • 🤝Get Vaults by owner
      • 📬By Deposit Address
      • 📃Get Metadata
      • 💵Get Vault Balance
      • 📜Get Projects
      • 📜Get Chains
      • ✅Get Verified Vaults
      • ✅Get Vaults by type
      • 🛠️Create un-minted vault
      • 📜Get ERC1155 Data
      • Demonstrations
        • Demo: Token gate
        • Demo: ERC1155 holdings
        • Demo: Fraud Vaults
        • Deep Link Vaulting
    • 🖋️Inscription Tool
      • demo
    • 🗳️Wallet Partnerships
  • Use Cases
    • 🎨DeFi
    • 👾Gaming
    • 🖥️NFTs
  • Blockchains
    • 🟡Binance Smart Chain
    • 🔵Ethereum
    • 🟣Polygon
  • Supported Networks
    • 🎒Bellscoin
    • 🎒Bitcoin
    • 🎒Bitcoin Cash/SLP
    • 🎒Bitcoin Ordinals
    • 🎒Bitcoin Stamps
    • 🎒BRC20
    • 🎒Counterparty
    • 🎒Digibyte
    • 🎒Dogecoin
    • 🎒Dogeparty
    • 🎒Ethereum
    • 🎒Ethscriptions
    • 🎒Litecoin
    • 🎒Litecoin Ordinals
    • 🎒Namecoin
    • 🎒Monacoin
    • 🎒Monaparty
    • 🎒Solana
    • 🎒Stacks
    • 🎒Tezos
  • Tutorials
    • 🧠Bitcoin Ordinals
    • 🧠Bitcoin Stamps
    • 🧠Bellscoin
    • 🧠BRC20
    • 🧠Counterparty
    • 🧠Curated Collections
    • 🧠Cursed Ordinals
    • 🧠Dogeparty
    • 🧠Emblem Markets
    • 🧠Emblem Vision
    • 🧠Ethscriptions
    • 🧠Emblem Legacy [Migration]
    • 🧠Litecoin Ordinals
    • 🧠Monaparty
    • 🧠Namecoin
    • 🧠Polygon
    • 🧠Stacks
  • FAQs
    • 🎨Artists, Creators, and Collectors
    • ❓Common Questions
    • 🔷Namecoin Help
    • 😡Troubleshooting
    • 🔐Vaulting & Unvaulting
    • 🔦Verifying Assets (Emblem Open )
  • Deep Dive
    • Smart Contracts: Github
    • How its done
  • Terms of Service
Powered by GitBook
On this page
  1. Tools
  2. API Documentation (Legacy)
  3. Demonstrations

Demo: Token gate

Token gating is a popular way to grant or prevent access to some web property like a webpage, or chat room.

Here we define an address for the owner we want to check, and the target asset of SATOSHIDICE Next we get 20 of the unclaimed vaults owned by the defined address using the Get Vaults by ownerendpoint

Next we loop through each and using the Get Vault Balance endpoint check the contents of each vault for a SATOSHIDICE

NOTE: This is a simplistic example meant to illustrate how combining different endpoints you can make complex applications. Under real world conditions you would handle paginating through a user's entire collection of vaults.

EXTRA: You can also check for the existence of claimed vaults within a user's account.

const request = require('request');

const baseUrl = 'https://metadata.emblemvault.io';
const ownerAddress = '0x3B31925EeC78dA3CF15c4503604c13b0eEBC57e5';
const chainId = 1;
const vaultType = 'unclaimed';
const size = 20;
const start = 0;
const targetAsset = 'SATOSHIDICE'

const options = {
    url: `${baseUrl}/myvaults/${ownerAddress}?start=${start}&size=${size}`,
    headers: {
        'chainId': chainId,
        'VaultType': vaultType
    }
};

function getVaultBalance(vault, callback) {
    const balanceOptions = {
        url: `${baseUrl}/meta/${vault.tokenId}?live=true`
    };

    request(balanceOptions, (error, response, balanceBody) => {
        if (!error && response.statusCode === 200) {
            const balanceData = JSON.parse(balanceBody);
            for (const asset of balanceData.values) {
                if (asset.name === targetAsset) {
                    return callback(true);
                }
            }
            return callback(false);
        } else {
            console.log('Error:', error);
            console.log('Status Code:', response.statusCode);
            console.log('Body:', balanceBody);
            return callback(false);
        }
    });
}

function checkVaultsForAsset(vaults, index, callback) {
    if (index >= vaults.length) {
        return callback(false);
    }
    getVaultBalance(vaults[index], (hasAsset) => {
        if (hasAsset) {
            return callback(true);
        } else {
            checkVaultsForAsset(vaults, index + 1, callback);
        }
    });
}

request(options, (error, response, body) => {
    if (!error && response.statusCode === 200) {
        const parsedBody = JSON.parse(body);
        checkVaultsForAsset(parsedBody, 0, (hasTargetAsset) => {
            console.log(hasTargetAsset);
        });
    } else {
        console.log('Error:', error);
        console.log('Status Code:', response.statusCode);
        console.log('Body:', body);
    }
});
PreviousDemonstrationsNextDemo: ERC1155 holdings

Last updated 1 year ago

📓