1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Wait a promise end before continue

Discussion in 'Finance' started by Adrien B., Aug 2, 2020 at 8:42 AM.

  1. Adrien B.

    Adrien B. Guest

    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,

    Login To add answer/comment
     

Share This Page