3

I am executing a function with Web3 like this:

MyContract.deployed().then(function (contractInstance) {    
      return contractInstance.MyFunction(parameter1, parameter2, { gas: 200000, from: web3.eth.accounts[0] })
    })

This works fine running the app on http://localhost:8080 with Chrome in incognito (so there's no MetaMask, which I have installed) - so the web3.eth.accounts[0] that executes the function will be the account I setup in Geth.

However, if I run the app in a normal Chrome window, where MetaMask will be active (thus it'll be using a different account) the following error will occur:

Uncaught (in promise) Error: invalid address

Removing the web3.eth.accounts[0] part, so I run the function like this:

return contractInstance.SetMessage(key, string1, string2, string3, string4, { gas: 200000})

Also fails. How should this be done correctly?

  • I'm running this on the ropsten test network for now if that's relevant – ZhouW Jul 21 '17 at 11:29
1

If you already have geth installed, I'd suggest connecting the Metamask to your geth instance running on http://localhost:8545. There is an option for that in Metamask in the list of available networks.

  • I get the invalid address error whether I have the ropsten network selected in MetaMask or localhost:8545 – ZhouW Jul 21 '17 at 11:48
  • And what account does the Metamask UI show when you are connected to localhost? Is it the same as web3.eth.accounts[0]? – Jakub Wojciechowski Jul 21 '17 at 12:15
  • MetaMask doesn't seem to connect to localhost:8545 when it's the ropsten test network running in Geth (my command for connecting to ropsten is something like "geth --testnet --syncmode "fast" --rpc --rpcapi db,eth,net,web3,personal --cache=1024 --rpcport 8545 --rpcaddr 127.0.0.1 --rpccorsdomain "*""), only when I have a private blockchain running – ZhouW Jul 21 '17 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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