I am writing a function to sync all transactions on a particular contract from a particular account in my local database to build a dashboard for account owners. I need to fetch all the past transfer events from the blockchain but I am getting the error that the call returned more than 10000 results sync function
syncTransactions(contract_address, owner_address, max_block) {
const contract = new web3.eth.Contract(abi, contract_address);
const from_block = max_block - 1000 >= 0 ? max_block - 1000 : 0;
contract.getPastEvents(
"Transfer",
{
fromBlock: from_block,
toBlock: max_block,
},
(err, events) => {
if (err) {
console.log(err);
}
for (let i = 0; i < events.length; i++) {
// check if 'to' or 'from' is equal to owner_account, if yes, add it to local database
}
syncTransactions(contract_address, owner_address, from_block - 1);
}
);
}
I haven't gotten to the point of filtering transactions using the given owner account. How can I avoid this error? Is there a better way to do this?
P.S. I have tried using both https and web socket URLs provided by Infura but getting the same error.
web3.eth.getPastLogswithcontract.getPastEvents, and apply all required subsequent fixes (input parameters, etc). – goodvibration Jul 29 '20 at 10:46