0

I am playing around with Metamask and the web3.js API using the Google Chrome console. However, I have two issues:

1) I am trying to send a simple transaction using Ganache GUI (localhost 7545) and I am entering the code below:

> ethereum.enable()

> web3.currentProvider.selectedAddress

<."0xb8662b66584ae08a88341df0d2b3fa7a65eb158c"
> var transaction = {
    from: web3.currentProvider.selectedAddress,
    to: "0xA8b62F503181D9A56683129de1B98ea4Bf143a40",
    value: web3.toWei("1", "ether")
}
> web3.eth.sendTransaction(transaction)

Then I am getting the error message below:

> Uncaught Error: The MetaMask Web3 object does not support synchronous methods like eth_sendTransaction 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.
    at MetamaskInpageProvider._sendSync (inpage.js:1)
    at MetamaskInpageProvider.send (inpage.js:1)
    at Proxy.t.send (inpage.js:1)
    at a.send (inpage.js:1)
    at w.e [as sendTransaction] (inpage.js:1)
    at <anonymous>:1:10

2) Also note that the web3.version seems to be 0.20.7 whereas when I check this website https://web3js.readthedocs.io/en/v1.2.4/, the new version of the web3.js API seem to be 1.2.4. Is there a way to update the web3.js API version in the chrome console while using the Metamask extension? Note that I have tried to enter this in the console web3 = new Web3(web3.currentProvider) but the web3.version remains 0.20.7.

In terms of priority 1) is more critical I believe.

Could you please assist.

Thank you

1
  • You should make another question for your second question. Jan 3, 2020 at 13:27

1 Answer 1

1

The answer to your first question seems to be quite straight forward: you need to provide a callback to the function. It is what the error tells you to do, moreover, the documentation says a callback can be added.

Example

web3.eth.sendTransaction(transaction, () => {
// your callback
})
2
  • Thank you very much for clarifying the situation. I have followed your recommendations and it worked nicely. FYI to close the thread, I have used the code below web3.eth.sendTransaction(transaction, function(error, hash){ if (error) console.error(error); else { console.log(hash); res.json(hash); } });
    – user32379
    Jan 5, 2020 at 1:28
  • @Weisel2095 if the answer is correct, please mark it as the correct answer. Jan 6, 2020 at 8:26

Your Answer

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

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