1

I'm using:

  • web3 v0.20.6
  • web3-providers-ws v1.0.0-beta.34

First question - can web3-providers-ws be used with web3 v0.20.*?

Second question (problem) - I get an error when probably trying to send transaction (reading and watching events through this provider is totally fine).

Pull request: https://github.com/ethereum-alarm-clock/timenode-core/pull/146

Working HTTP provider E2E tests:

https://travis-ci.org/ethereum-alarm-clock/timenode-core/jobs/406823597

Failing WS provider E2E tests:

https://travis-ci.org/ethereum-alarm-clock/timenode-core/jobs/406823603

Actual error:

5 passing (4s)
  3 failing
  1) ScheduleTx
       schedules a basic transaction:
     TypeError: Cannot set property 'method' of undefined
      at WebsocketProvider._addResponseCallback (node_modules/web3-providers-ws/src/index.js:197:39)
      at WebsocketProvider.send (node_modules/web3-providers-ws/src/index.js:252:10)
      at RequestManager.send (node_modules/web3/lib/web3/requestmanager.js:58:32)
      at Eth.get [as accounts] (node_modules/web3/lib/web3/property.js:107:62)
      at Object.<anonymous> (test/e2e/TestScheduleTx.ts:75:34)
      at Generator.next (<anonymous>)
      at fulfilled (test/e2e/TestScheduleTx.ts:4:58)
      at <anonymous>
      at process._tickCallback (internal/process/next_tick.js:188:7)

The only difference between HTTP provider and WS provider is using ws://localhost:5454 instead of http://localhost:8545. RPC I'm talking to is ganache-cli 6.1.6.

1

Make sure you have ganache-cli@beta installed

You have to hack around the send and sendAsync issue when setting provider.

so:

export const setProvider = (provider: any) => 
    Contracts.concat(HumanFriendlyToken).forEach((contract) => {
        contract.setProvider(provider)
        if (typeof contract.currentProvider.sendAsync !== "function") {
            contract.currentProvider.sendAsync = function() {
                return contract.currentProvider.send.apply(contract.currentProvider, arguments)
            }
        }
    })

^ Make sure NOT to use an arrow () => function above as it binds this to the scope and we dont want that.

Should work after that

1

Are you aware that the API for RPC and WS is different? Not sure if ganache supports this, with the "normal" geth you need to start it like geth --ws. That will bind the websocket API to port 8546 per default.

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.