This is my code:

   function send() {
    Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send;
    var web3 = new Web3("http://localhost:8545");
    var data = web3.eth.getHashrate();

when i run the send() function I am getting this error: "TypeError: this.provider.sendAsync is not a function"


The default websocket port is 8546

You could try

var web3 = new Web3("ws://localhost:8546");

Or connecting to the HTTP JSON RPC

var web3 = new Web3("http://localhost:8545");
  • changed as said still getting same type error "TypeError: this.provider.sendAsync is not a function" – Haren Sarma Apr 20 '18 at 19:52

I think here is a similar issue on github https://github.com/ethereum/web3.js/issues/1119

the idea is to use

Web3.providers.HttpProvider.prototype.sendAsync = Web3.providers.HttpProvider.prototype.send

before creating new instance. Besides, as spoted by @cleanunicorn you should set the default ws port 8546 unless you have defined it differently when you've runed geth.

This error might be caused by a connection problem so run geth with the following options

--ws --wsport 8546 --wsaddr "" --wsorigins="*" 
  • updated the code (question) as said and still same issue – Haren Sarma Apr 20 '18 at 19:54
  • have you changed the port too? – Badr Bellaj Apr 20 '18 at 19:57
  • yes, i did that too. – Haren Sarma Apr 20 '18 at 20:01
  • check my update – Badr Bellaj Apr 20 '18 at 20:01
  • I am using JSON RPC now. should I change port to 8545 ? – Haren Sarma Apr 20 '18 at 20:05

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.