0

i try to create a map with (address => bool) with web3js. I want to know if the address is a contract owner. So, i have to call "owners" function in my solidity contract. As you can see below :

let allAccountInfo = new Map();
let localAccount = web3.eth.accounts;

    for(account in localAccount){

        MyContract.owners(localAccount[account],function(error,result){

            if(error){
                console.log(error);
            }
            else {
                allAccountInfo.set(account,result);
            }

        });

    }
    console.log(allAccountInfo);

Because MyContract.Function return a promise, this code don't work. I have to wait the promises end before loop... with "await" ?

 let allAccountInfo = new Map();
 let localAccount = web3.eth.accounts;

     for(account in localAccount){
            result = await MyContract.owners(localAccount[account])
            allAccountInfo.set(account,result);
     }
  console.log(allAccountInfo);

But when i do this, i get this error :

Error: The MetaMask Web3 object does not support synchronous methods like eth_call without a callback parameter.

Do you know a solution ? Thanks,

  • Would be helpful if you stated which line of code throws this exception. – goodvibration Feb 28 at 13:25
  • It's the line with "await" keyword. – Adrien B. Feb 28 at 13:33
  • I'm pretty sure that you need to add .call(...) or .send(...) at the end of that line (depending on whether this function is constant or state-changing). – goodvibration Feb 28 at 14:26
0

Finally, i've decided to switch to Web3js 1.0 that handle await correctly.

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.