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,

3
  • Would be helpful if you stated which line of code throws this exception. Feb 28, 2019 at 13:25
  • It's the line with "await" keyword.
    – Adrien B.
    Feb 28, 2019 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). Feb 28, 2019 at 14:26

1 Answer 1

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 and acknowledge that you have read and understand our privacy policy and code of conduct.

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