Skip to content
This repository has been archived by the owner on Jun 14, 2018. It is now read-only.

Error TypeError: Cannot read property 'bind' of undefined when specifying your own provider in truffle.js #12

Open
nosuchip opened this issue Oct 25, 2017 · 3 comments

Comments

@nosuchip
Copy link

nosuchip commented Oct 25, 2017

var originalSendAsync = provider.sendAsync.bind(provider);

Prerequisites: having node that serves JSON RPC on secured port (HTTPS).

When specifyng provider following way got error:

      provider: function() {
        const url = (this.schema || 'http') + '://' + this.host + ':' + this.port;
        const provider = new Web3.providers.HttpProvider(url);
        return provider;
      }
@Freyert
Copy link

Freyert commented Mar 12, 2018

I also see this error when I have:

const Web3 = require('web3');
  
module.exports = {
    networks: {
        petshop: {
            provider: new Web3("https://mynetwork.net"),
            network_id: "*"

        }
    }
};

Using node --inspect-brk /xxxx/bin/truffle migrate --network petshop we can see that the provider is not connected. At least for me.


Eh, after more poking it seems that web3 does not have a send method.

My version of Web3 that I can run independently of truffle is: ^1.0.0-beta.30
This module has a dependency on: ^0.20.1


More poking, the provider is supposed to have a send method

https://github.com/ethereum/web3.js/blob/62dd77c7f43522eb568a001cf4c4df726f8efa69/lib/web3/requestmanager.js#L51

Provider.create() which also "wraps" the provider.

Wrapper expects send to be a top level key, but it is actually inside of provider._provider.


OK, so my first problem was that send was undefined. Now I'm at sendAsync.

sendAsync definitely does not exist on the prototype:

JSON.stringify(Object.keys(Object.getPrototypeOf(provider)))
"["_prepareRequest","send"]"

The problem I think is that the module web3-providers-http overwrites the prototype for HttpProvider.

➜  PetShop npm ls web3-providers-http
[email protected] /Users/fultonbyrne/Desktop/PetShop
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └── [email protected] 

Something isn't right here . . .

Version 0.19.0 I still have to reference Web3()._provider, but I get this error instead:

Could not connect to your Ethereum client. Please check that your Ethereum client:
    - is running
    - is accepting RPC connections (i.e., "--rpc" option is used in geth)
    - is accessible over the network
    - is properly configured in your Truffle configuration file (truffle.js)

Both methods do exist in 0.19:

JSON.stringify(Object.keys(Object.getPrototypeOf(provider)))
"["prepareRequest","send","sendAsync","isConnected"]"

@Freyert
Copy link

Freyert commented Mar 12, 2018

@nosuchip here's a summary of what I've found:

  1. You must pass in Web3()._provider to the provider field.
  2. Newer versions of web3 overwrite the prototype and remove sendAsync. Locking to 0.19 the latest stable release should help you out.
  3. I need to hunt down this error message and see how it's checking "connectivity".

My personal problem is now:

Occurs when calling net_version.

Invalid JSON RPC response: ""

Which happens here: https://github.com/trufflesuite/truffle-provider/blob/develop/wrapper.js#L69

-_-
{"protocol":"http:","slashes":true,"auth":null,"host":"undefined","port":null,"hostname":"undefined","hash":null,"search":null,"query":null,"pathname":"/:undefined","path":"/:undefined","href":"http://undefined/:undefined"}

@Freyert
Copy link

Freyert commented Mar 12, 2018

OK, I've got this fixed for myself:

it's pretty much what @nosuchip is doing in his first comment, but on version 0.19

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants