Web3js – MetaMask Web3 Object Error: Does Not Support Synchronous Methods Without Callback Parameter

angular2ethereumjsweb3js

im using web3j with angular 5 connection working perfectly and balance showing perfectly. but when i write transfer function it throw error

var tx = this._web3.eth.sendTransaction({ 
  from: this._account,
  gasPrice: "20000000000",
  gas: "21000",
  to: textetheraddress, 
  value: textetheramount,
  data: ""
 }).then(function(err, transactionHash) {
  if (!err)
    console.log(transactionHash); 
});

error

ERROR Error: The MetaMask Web3 object does not support synchronous methods like personal_newAccount without a callback parameter. See https://github.com/MetaMask/faq/blob/master/DEVELOPERS.md#dizzy-all-async—think-of-metamask-as-a-light-client for details.

Best Answer

You are trying to make a synchronous call and expect to receive a promise.

It's probably just exactly as the error says:

Usually, to make a method call asynchronous, add a callback as the last argument to a synchronous method. See the Ethereum wiki on "using callbacks"(https://github.com/ethereum/wiki/wiki/JavaScript-API#using-callbacks)

Since sync functions are not supported you need to use the async one.

So I suppose in this case your code needs to pass a callback instead of waiting for a promise and should look something like this:

var tx = this._web3.eth.sendTransaction({ 
  from: this._account,
  gasPrice: "20000000000",
  gas: "21000",
  to: textetheraddress, 
  value: textetheramount,
  data: ""
 }, function(err, transactionHash) {
  if (!err)
    console.log(transactionHash); 
})
Related Topic