I am developing a 脨app that uses multiple accounts. Most of the time (but not always), after I switch from one account to another in MetaMask, I get an "invalid address" error when I try to sign a transaction. Sometimes it helps to reload the page, sometimes restarting chrome is required to get it to work again. Detailed error message below.
Context:
Error: invalid address
at inputAddressFormatter (http://localhost:8080/static/bundle.js:19935:11)
at inputTransactionFormatter (http://localhost:8080/static/bundle.js:19761:20)
at http://localhost:8080/static/bundle.js:21033:28
at Array.map (native)
at Method.../app-contracts/node_modules/web3/lib/web3/method.js.Method.formatInput (http://localhost:8080/static/bundle.js:21032:32)
at Method.../app-contracts/node_modules/web3/lib/web3/method.js.Method.toPayload (http://localhost:8080/static/bundle.js:21058:23)
at Eth.send [as sendTransaction] (http://localhost:8080/static/bundle.js:21083:30)
at SolidityFunction.../app-contracts/node_modules/web3/lib/web3/function.js.SolidityFunction.sendTransaction (http://localhost:8080/static/bundle.js:20125:15)
at SolidityFunction.../app-contracts/node_modules/web3/lib/web3/function.js.SolidityFunction.execute (http://localhost:8080/static/bundle.js:20208:37)
at http://localhost:8080/static/bundle.js:14954:16
_callee3$ @ fulfill-request.js:143
tryCatch @ runtime.js:64
invoke @ runtime.js:355
prototype.(anonymous function) @ runtime.js:116
step @ asyncToGenerator.js:17
(anonymous) @ asyncToGenerator.js:30
Promise.reject (async)
(anonymous) @ contract.js:154
Promise.resolve (async)
(anonymous) @ contract.js:480
detectNetwork @ contract.js:475
(anonymous) @ contract.js:153
_callee3$ @ fulfill-request.js:141
tryCatch @ runtime.js:64
invoke @ runtime.js:355
prototype.(anonymous function) @ runtime.js:116
step @ asyncToGenerator.js:17
(anonymous) @ asyncToGenerator.js:28
Promise.resolve (async)
(anonymous) @ contract.js:480
detectNetwork @ contract.js:475
val.then @ contract.js:420
Sounds like your app isn't recognizing when you change users. You can do this either with your dapp itself:
https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#ear-listening-for-selected-account-changes
Or if this is just for development, you might just use multiple chrome profiles with different accounts selected.
Does that solve your issue?
Right, I forgot about that section. I'll see if I can apply that. By the way, I think this is an antipattern, and should be replaced with an event/subscription model :)
I'm glad you agree, a new web3 API is being written as we speak. :)
Closing unless you think there's anything else to this issue.
@svdo you can suggest a new rpc subscription method here https://github.com/ethereum/interfaces/issues/new
Oh by the way, maybe also interesting for others: in our app we don't explicitly pass accounts to web3 calls. Instead, we set the transaction defaults:
MyContract.defaults({
from: web3.eth.accounts[0]
})
The nice thing is that our React component don't have to know about web3 accounts, and we now only have to update these defaults when the account changes; in many cases we don't even need to reload the UI.