I'm a newcomer to Ethereum, working on a project that requires a certain piece of data from a contract, in order to populate a list in my HTML frontend. However, as you might expect, the calls to the Contracts, not being instantaneous, aren't finishing before the rest of the code is executed, resulting in the relevant values being filled in with UNDEFINED. From the Console, I know that these values come through eventually - it's just that they're out of order. I'm well aware that something like this requires Promises, or Callbacks, or some variant of such, but I am simply having no luck getting any such thing to work, and I'm not sure how they work with Ethereum. I've scoured for tutorials, guides, etc, but I've still not had any joy. I've got a few calls but since they're all pretty much the same (just calling different methods and getting slightly different response variables), I'll just post one:
try{
RegionalContract.areYouInList(codeInput.value, function(error, res){
if(!error) {
var areWeAllowed = res
console.log("Are we allowed to vote? : " + areWeAllowed)
}
});
}catch (err) {
console.log(err)
}
How would I go about setting up a Promise, et al, to make the page wait until this method had returned? Thanks a bunch.