4

After switching to testnet from the dropdown in Metamask, the address used is still my Mainnet address.

web3.eth.getAccounts(function(a,b) {
      Merchant.accounts = b;
      console.log("Merchant accounts: " + Merchant.accounts);
      let x = web3.eth.getBalance;
      console.log(x);
    });

shows 0xc27a6adac593d1c02355f307ea92f6261269566d, my mainnet address.

I've tried sending funds via truffle console:

truffle(development)> ma
'0xc27a6adac593d1c02355f307ea92f6261269566d'
truffle(development)> web3.eth.sendTransaction({from: web3.eth.accounts[1], to: ma, value: 10000000000000})
'0x9c59733f9e8bed3f13d6f96589894239a43af6a5e387b40e7a9fad4e0157aaa7'

I don't see the balance change in MetaMask.

How do I add funds to my test Metamask?

1
  • 1
    Assuming both MetaMask and Truffle are speaking to the same test network, I would expect what you're doing to work. (You could also just import the private key of the account you already have into MetaMask.)
    – user19510
    Commented Jan 16, 2018 at 1:29

4 Answers 4

2

First there is not such thing as a "mainnet address". All addresses are just private keys, which mathematically transformed into ethereum addresses.

Which means you can use the same addresses on any network. But Metamask will just show you the funds your address has on the current active network.

In order to see your founds, make sure Metamask points to the same network.

E.g: if you are using Ganache (previously test-rpc) make sure you Metamask points to the right network to see the founds:

enter image description here

You may use truffle console to send founds from your (unlocked) addresses to any other address on the same network.

web3.eth.sendTransaction({
 from:web3.eth.coinbase,
 to: '0xaEC98826319EF42aAB9530A23306d5a9b113E23D',
 value: web3.toWei(10, "ether")
})
1
  • You may also import your Ganache account into Metamask by Account-->import-->Private Key Commented Feb 20, 2018 at 14:53
0

Depending on which testnet you're working on, you can get ether from testnet faucets. This is a working Rinkeby faucet, which I've used in the past: https://www.rinkeby.io/#faucet and a working Ropsten faucet: http://faucet.ropsten.be:3001/

You might also consider resetting MetaMask’s state:

  • Make sure you have your seed phrase backed up.
  • Lock MetaMask (in the top right menu)
  • Click “Forgot my Password (import)”
  • Enter your seed phrase.
  • You should be able to submit transactions again.

These steps are taken directly from https://github.com/MetaMask/faq/blob/master/USERS.md

0

This is also a simple and useful MetaMask faucet for Ropsten.

0

For testing purpose, I am using ganache-cli and I get eth into my wallet with the following code. It is web3.py but it is easy to transpose into web3.js.

def add_ether(address, amount):
    ''' Add ether to a wallet. This is only for testing purpose. Of course, this does not work on mainnet.

    >>> a = w3.eth.account.create('test')
    >>> add_ether(a.address, 10)
    >>> w3.eth.getBalance(a.address)
    10'''

    sender = w3.eth.coinbase
    if amount > w3.eth.getBalance(sender):
        raise ValueError("The sender does not have enough coins.")
    w3.eth.sendTransaction({'from': sender,
                              'to': address,
                              'value': amount})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.