import { ERC721 } from "@0xcert/ethereum-erc721/build/erc721.json" ; import Web3 from "web3" ; import * as dotenv from "dotenv" ; dotenv . config ( ) ; const CONTRACT_ACCOUNT = "0x25ed58c027921E14D86380eA2646E3a1B5C55A8b" ; const CONTRACT_START = 13153967 ; const INFURA_URL = process . env . INFURA_URL ; if ( ! INFURA_URL ) throw new Error ( "Please set INFURA_URL in .env - register at https://infura.io/" ) ; const fs = require ( "fs" ) ; const web3 = new Web3 ( new Web3 . providers . HttpProvider ( INFURA_URL ) ) ; const erc721 = ERC721 ; const contract = new web3 . eth . Contract ( erc721 . abi as any , CONTRACT_ACCOUNT ) ; const idToNumber = { } ; console . info ( "Fetching transfers..." ) ; contract . getPastEvents ( "Transfer" , { fromBlock : CONTRACT_START } ) . then ( ( events ) => { events . forEach ( ( event ) => { if ( ! idToNumber [ event . returnValues . _to ] ) { idToNumber [ event . returnValues . _to ] = 1 ; } else { idToNumber [ event . returnValues . _to ] = idToNumber [ event . returnValues . _to ] + 1 ; } if ( idToNumber [ event . returnValues . _from ] ) { idToNumber [ event . returnValues . _from ] = idToNumber [ event . returnValues . _from ] - 1 ; } } ) ; const filteredArr = [ ] ; Object . entries ( idToNumber ) . forEach ( ( item ) => { if ( item [ 1 ] !== Number ( 0 ) ) { filteredArr . push ( item [ 0 ] ) ; } } ) ; fs . writeFileSync ( "./snapshot.json" , JSON . stringify ( filteredArr ) ) ; } ) ;