You're missing the last argument to sendTransaction
, the callback function(error, transactionHash) { ... }
The MetaMask FAQ states:
All Async - Think of MetaMask as a light client
The user does not have the full blockchain on their machine and so
data lookups can be a little slow. For this reason, we are unable to
support most synchronous methods. The exception to this is:
eth_accounts (web3.eth.accounts)
eth_coinbase (web3.eth.coinbase)
Usually a method call can be made async by simply adding a callback as
the last argument to a synchronous method.
See ethereum wiki on "using callbacks"
Not only is this a technical limitation, it's also a user experience
issue. When you use synchronous calls, you block the user's interface,
and so it's a generally bad practice anyways. Think of this API
restriction as a gift to your users.
So all calls to web3.js should have a callback as their last argument: the only calls where that's not needed are for web3.eth.accounts
and web3.eth.coinbase
. The generic form of the callback is function(error, result)
.