Planet Zephyros Trading Card Game
Posted: Thu Dec 11, 2025 9:54 pm
This code enabled me to map TokenId from Electroneum block explorer to the metadata json files that don't map 1=1 due to randomMint in the Verdant Kin NFT contract:
Code: Select all
const { ethers } = require("ethers");
const fs = require("fs");
const RPC = "https://rpc.ankr.com/electroneum";
const contractAddress = "0x3fc7665B1F6033FF901405CdDF31C2E04B8A2AB4";
const maxSupply = 474;
const abi = [
"function tokenURI(uint256 tokenId) view returns (string)"
];
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function fetchWithRetry(contract, id, retries = 3) {
for (let attempt = 1; attempt <= retries; attempt++) {
try {
const uri = await contract.tokenURI(id);
if (uri && typeof uri === "string" && uri.length > 0) {
return uri;
}
throw new Error("Empty URI");
} catch (err) {
console.log(`Token ${id}: attempt ${attempt} failed (${err.message}).`);
if (attempt < retries) {
await sleep(500);
}
}
}
return null;
}
async function main() {
const provider = new ethers.JsonRpcProvider(RPC);
const contract = new ethers.Contract(contractAddress, abi, provider);
let rows = ["token_id,token_uri"];
for (let id = 1; id <= maxSupply; id++) {
console.log(`Processing token ${id}/${maxSupply}…`);
const uri = await fetchWithRetry(contract, id);
if (!uri) {
rows.push(`${id},ERROR`);
console.log(`❌ Token ${id} failed after all retries.`);
continue;
}
const fileName = uri.split("/").pop();
rows.push(`${id},${fileName}`);
console.log(`✅ Token ${id} → ${fileName}`);
}
fs.writeFileSync("mapping.csv", rows.join("\n"));
console.log("mapping.csv generated with retries.");
}
main();
Stake CORE, build teams, battle NFTs! Who's in? COMING SOON