Skip to content

Instantly share code, notes, and snippets.

@nhancv
Created July 26, 2023 03:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhancv/007118596fcededef03d3aa1c4099834 to your computer and use it in GitHub Desktop.
Save nhancv/007118596fcededef03d3aa1c4099834 to your computer and use it in GitHub Desktop.
Export NFT ids of owner to text file
const fs = require('fs');
const fetchNFTIDs = async () => {
const NFT_ADDRESS='';
const OWNER_ADDRESS='';
const ETHERSCAN_APIKEY='';
const res = await fetch(`https://api.etherscan.io/api?module=account&action=addresstokennftinventory&address=${OWNER_ADDRESS}&contractaddress=${NFT_ADDRESS}&page=1&offset=1000&apikey=${ETHERSCAN_APIKEY}`);
if (res.ok) {
const data = await res.json();
const file = `nfts-${OWNER_ADDRESS}-${Date.now()}.txt`;
console.log(`Writing ${data.result.length} NFTs to file ${file}`);
fs.writeFileSync(file, JSON.stringify(data.result.map(v => v.TokenId)));
console.log('Done.');
}
};
fetchNFTIDs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment