-1

I have a web3 call to the smart contract which returns true or false. According to the returned value, the current element of the array is deleted or not. However this isn't working well (since web3 calls are asynchronous i guess) as the loop doesn't wait until the contract call returns the value before it continues executing.

let counter = 0;
for(var value of array) { 
web3call{
     if(result == false){
       array.splice(counter,1)
    }
}
counter++; }
0

If your web3 call is returning a promise you can simply await it:

async function doThing() {
  //...
  const result = await web3call()
  if(!result){
    // Do whatever...
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.