⚙️Indexer

// v1 indexer using Hiro API
// valid inscriptions using p="onchaintrophy_v1" in metatags
// must be located in OnChain Trophy wallet & inscribed by OnChain Trophy
// wallet bc1prv4hplrp0fefmqspwq07fd5mt7u6dl39n5t5lapsd4mmhh95urqqhw8p7f

let allIds = [];

async function fetchData(offset = 0) {
    try {
        const response = await fetch(`https://api.hiro.so/ordinals/v1/inscriptions?address=bc1prv4hplrp0fefmqspwq07fd5mt7u6dl39n5t5lapsd4mmhh95urqqhw8p7f&genesis_address=bc1prv4hplrp0fefmqspwq07fd5mt7u6dl39n5t5lapsd4mmhh95urqqhw8p7f&mime_type=text%2Fhtml&limit=60&offset=${offset}`);
        
        if (!response.ok) {
            throw new Error("Error fetching data");
        }
        
        const data = await response.json();

        const ids = data.results.map(result => result.id);
        allIds.push(...ids);

        if (data.total > offset + 60) {
            await fetchData(offset + 60);
        }

    } catch (error) {
        console.error("An error occurred:", error);
    }
}

fetchData().then(() => {
    let metaResults = [];

    async function fetchMetaForId(id) {
        try {
            const response = await fetch(`https://api.hiro.so/ordinals/v1/inscriptions/${id}/content`);
            if (!response.ok) {
                throw new Error(`Error fetching content for ID: ${id}`);
            }

            const html = await response.text();
            const parser = new DOMParser();
            const doc = parser.parseFromString(html, "text/html");

            const metaElements = Array.from(doc.querySelectorAll('meta[p="onchaintrophy_v1"]'));

            for (let meta of metaElements) {
                const op = meta.getAttribute('op');
                const name = meta.getAttribute('name');
                const parent = meta.getAttribute('parent');

                metaResults.push({
                    id: id, 
                    op: op,
                    name: name,
                    parent: parent
                });
            }
        } catch (error) {
            console.error("An error occurred:", error);
        }
    }

    async function fetchAllMeta() {
        for (let id of allIds) {
            await fetchMetaForId(id);
        }
        console.log(metaResults);
    }

    fetchAllMeta();
});

Last updated