I am doing a project that involves getting data from blockchain and sending data to it as well. However, I am a beginner on NodeJs and was stuck on an issue.
A certain portion of code roughly looks like this:
try {
for await (let user of users) { //users is an array with details of 5k+ users
var balance = await callBlockChainFunction(payload); //Get data from blockchain
//Do certain operations on balance
txHash = await callBlockChainFunction2(balance); //Post data to blockchain
}
} catch (e) {
console.log(e);
} finally {
//upload log to S3 bucket
}
The callBlockChainFunction2 function takes around 5 seconds or more for response and overall this code takes 3 hours+ to run. How do I optimize this? Any points or guides to relevant resources would help a lot. Thanks.