1

The sample Truffle Dapp doesn't work when Metamask active. I'm running testrpc, I imported the tesrpc account's private key to Metamask and Metamask is connecting to the local testrpc according to chrome console log:

Using web3 detected from external source. If you find that your accounts don't appear or you have 0 MetaCoin, ensure you've configured that source properly. If using MetaMask, see the following link. Feel free to delete this warning. :) http://truffleframework.com/tutorials/truffle-and-metamask

However Metamask doesn't show any ether balance on the account and the Dapp page shows empty string for Metacoin balance.

I debugged it and it seems web.3eth.getBalance never calls the callback function when Metamask is active:

  web3.eth.getBalance(myAccount, web3.eth.defaultBlock,
        function(error,result){
          if(error) {
            console.error("Error while retrieving the balance for address["+myAccount+"]: "+err);
          } else {
            var balance = web3.fromWei(result.toNumber());
            console.debug("Balance for address["+myAccount+"]: "+balance);

          }
        }
      ); 

It works perfectly when Metamask isn't active.

4 Answers 4

0

Reinstall Metamask, create a new Metamask account then import the same testrcp account private key will resolve the issue.

I'm unsure what was the cause. The same code started to work after Metamask reinstall. I did not even restart testrpc or redeployed the code.

1
  • Not working for me.
    – Rexcirus
    Jun 30, 2017 at 16:26
0

Another possibility would be to start testrpc with the -m and the -u options. The -m option requires a string of the words you got when you first installed the Metamsk. The -u option unlocks the account. The command line to start testrpc would look something like this:

# testrpc -m "Insert your unlock words here" -u 0 -u 1

If you start testrpc like this you will see that the first account under "Available Accounts" will be the first account of your Metamsk.

1
  • I used the -m option to launch testrpc to always have the same accounts which I've imported to Metamask. I've not tried to launch testrpc with unlocked accounts. However getBalance doesn't require the account to be unlocked so I doubt that would have solve the issue.
    – szerte
    May 7, 2017 at 20:31
0

Parity being installed with Metamask causes things to break. Disable Parity and it should work. I spent an hour figuring this out, but I still don't know why it works.

0

I was facing the same issue and any of the answers helped me, I tried something and it solved.

  1. Install Metamask
  2. Run TestRPC network and connect to TestRPC (Localhost:8545) in Metamask
  3. Import the account private key in Metamask and select the account
  4. Open another terminal and migrate the contract again "Truffle Migrate"
  5. Refresh the page and you'll see the 10000 Meta

It did work to me.

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.