2

I'm working on a simple Ethereum project, but since I'm not certain whether the issue I'm having is to do with Web3 or Async/Await, I decided to post this question to both Stackoverflow and Ethereum Stackexchange. I'm using javascript with Web3 for this project.

Essentially, I'm running with three async functions, one of which is meant to call the others before performing some calculations and returning the results of its efforts:

async function getFounder() {
    console.log("getFounder method");
        try{
           console.log("just before whoIsFounder");
           whoIsFounder = await promisify(RegionalContract2.getFounder);
        }catch(err) {
           console.log(err)
        }

            console.log("This Election's Founder is : " + whoIsFounder);

        return whoIsFounder;        

    }

async function getCurrentAccount(){   <<<<<<The problem method
console.log("getCurrentAccount method");
currentAccount = await web3.eth.getAccounts();    
return currentAccount;
}

async function isItYours(){
   try{
    console.log("Inside the isItYours method");
        currentAccount = await getCurrentAccount();
        founder = await getFounder();
        console.log("The getFounder method has resolved completely");
        console.log("founder is " + founder);
      if (founder != null){
            if (founder === currentAccount) {//if the Founder is the same as the value entered.
            alert("You are in fact the owner of this Election.");
            var x = document.getElementById("hidden");
            x.style.display = "block";
            }
            else {
            alert("You are NOT the owner of this Election. The value sent in was " + currentAccount);
            }
      }
      else {
        alert("Founder can't be null. Either you're not logged into Metamask, or your account somehow isn't linked up properly.");
      }
     }catch (err) {
        console.log(err)
     }
}
isItYours();

When I tried to run this code, however, I got the following error:

Uncaught TypeError: e is not a function
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at i (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at s (inpage.js:1)
    at inpage.js:1

The full console log is:

The founder is:
inpage.js:1 null "0x59a09d00eb11caa5fa70484bf4d78015d10938bc"
admin.html:340 Inside the isItYours method
admin.html:331 getCurrentAccount method
admin.html:305 getFounder method
admin.html:318 just before whoIsFounder
***the aforementioned error from the previous segment***
This Election's Founder is : 0x59a09d00eb11caa5fa70484bf4d78015d10938bc
admin.html:344 The getFounder method has resolved completely
admin.html:345 founder is 0x59a09d00eb11caa5fa70484bf4d78015d10938bc

This leads me to think that the problem lies with getCurrentAccount(), since it employs web3.eth.getAccounts(), rather than a custom method, to return its value. Does anyone know why this might be happening? Thanks.

Your Answer

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

Browse other questions tagged or ask your own question.