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: ERC1155 holdings

This script first fetches the backing data from the Emblem Vault, gets the live addresses and the target asset name. It then fetches the balances for each live address and checks if the balance contains the expected asset.

const request = require('request');

const tokenId = '14348293833920273912990111611620811208434744638373632813897914200493984998646';
const baseUrl = 'https://v2.emblemvault.io';
const apiKey = 'your_api_key_here'; // Replace with your actual API key

const options = {
    url: `${baseUrl}/allBackingIdsForTokenId/${tokenId}`,
    headers: {
        'x-api-key': apiKey,
    },
};

request(options, (error, response, body) => {
    if (!error && response.statusCode === 200) {
        const parsedBody = JSON.parse(body);
        const liveAddresses = parsedBody.liveAddresses;
        const liveIds = parsedBody.liveIds;
        const targetAssetName = parsedBody.live[0].targetAsset.name;
        console.log('\nAsset Name:', targetAssetName);
        liveAddresses.forEach((address, index) => {
            getTokenBalances(address, balance => {
                console.log('\nVault Token ID:', liveIds[index]);
                console.log('Address:', address);
                console.log('Balance contains the target asset:', balanceContainsExpectedAsset(balance, targetAssetName));
            });
        });
    } else {
        console.log('Error:', error);
        console.log('Status Code:', response.statusCode);
        console.log('Body:', body);
    }
});

function getTokenBalances(address, cb) {
    const options = {
        method: 'GET',
        url: 'https://xchain.io/api/balances/' + address,
        headers: {
            'cache-control': 'no-cache',
            'accept': 'application/json, text/javascript, */*; q=0.01',
        },
    };

    request(options, (error, response) => {
        if (error) throw new Error(error);
        if (response.body && !response.body.includes('<!DOCTYPE html>')) {
            return cb(JSON.parse(response.body));
        } else {
            return cb({});
        }
    });
}

function balanceContainsExpectedAsset(balance, expectedAssetName) {
    const assets = balance.data;
    return assets.some(asset => asset.asset === expectedAssetName);
}

Results:

Asset Name: ZOMBIEPEPES

Vault Token ID: 78617344381428201
Address: 1Gwr7dmaVTJbV2j5zc7UnKQeTwdjzUt95k
Balance contains the target asset: true

Vault Token ID: 29243500604579471
Address: 1BhkPipt2EHczAPQVqKXxJ7J97NDUTbUAJ
Balance contains the target asset: true
PreviousDemo: Token gateNextDemo: Fraud Vaults

Last updated 1 year ago

📓