I am trying to get all the token id for a given erc721 contract address. What would be the best way of doing this? I have tried using the web3 library with the following code but get response size limit exceeded.
const Web3Eth = require("web3-eth");
const URL =
"wss://eth-mainnet.alchemyapi.io/v2/XXXXXXXX";
const web3Eth = new Web3Eth(Web3Eth.givenProvider || URL);
const smartContractAddress = "0x06012c8cf97bead5deae237070f9587f8e7a266d";
const contract = new web3Eth.Contract(abi_, smartContractAddress);
async function fetchTokens() {
return contract.getPastEvents(
"Transfer",
{
fromBlock: 0,
toBlock: "latest",
},
function (error, events) {
if (!error) {
for (var i = 0; i < events.length; i++) {
console.log(events[i].returnValues.tokenId);
}
}
}
);
}
fetchTokens();
Error:
(node:13891) UnhandledPromiseRejectionWarning: Error: Returned error: Log response size exceeded. You can make eth_getLogs requests with up to a 2K block range and no limit on the response size, or you can request any block range with a cap of 10K logs in the response.