title: How to get a value from a "Promise" object
body: <p>I started learning ethereum and web3js and noticed some functions on Web3js are asynchronous. What i want to achieve is get the account balance of a wallet and use the data for something else. My code below</p>
  
  <pre><code>function getAccountBalance2(address){
              var wei, balance
              //address = document.getElementById("addy").value
              return new Promise(function(resolve, reject){
                  web3.eth.getBalance(address, function(error, wei){
                      if(error){
                          console.log("Error with address");
                      }else{
                          var balance = web3.fromWei(wei, "ether");
                          var bal = resolve(balance);
                          //console.log(bal);
                          console.log(balance.toNumber());
                          return balance.toNumber();
                      }
                  });
              });
          }
  </code></pre>
  
  <p>and i am trying to use the returned value in this function below</p>
  
  <pre><code>function interTransfer(){
              var from, to, amount, fromWallet, toWallet
              from = document.getElementById("from").value
              to = document.getElementById("to").value
              amount = document.getElementById("amount").value
  
              if(isWalletValid(from) &amp;&amp; isWalletValid(to)){
                  fromWallet = getAccountBalance2(from);
                  toWallet = getAccountBalance2(to);
              }else{
                  console.log("Something is wrong")
              }
  
              console.log(fromWallet + " "+ toWallet)
          }
  </code></pre>
  
  <p>The output</p>
  
  <p><a href="https://i.stack.imgur.com/EBtVb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EBtVb.jpg" alt="it gives a promise object"></a></p>
  
  <p>How do i get the actual value and use it in the <code>interTransfer()</code> function</p>