1

When I put my script in a docker container, I can no longer connect to Infura:

Error: Cannot find module 'websocket'

in package.json

"web3": "^1.0.0-beta.34"

in my script:

const Web3 = require('web3');
const web3 = new Web3(new Web3.providers.WebsocketProvider('wss://ropsten.infura.io/ws'));

myContract.events.Transfer({    // Transfer, allEvents, getPastEvents
    fromBlock: 0
}, function (error, event) {
    if (error) {
        console.log("error: " + error);
    } else {
        // console.log("event: " + JSON.stringify(event, null, 2));
        console.log("event: " + event);
    }
})

My Dockerfile is pretty standard.

Any idea of what my problem is ?

3

It seems inside a docker container, nodejs has problem getting the websocket from github. So I just add the websocket library directly in my app:

npm install --save websocket
| improve this answer | |
  • I just ran into this as well. For whatever reason, inside of docker "web3": "^1.0.0-beta.34" doesn't install the "websocket" package. Seems like a bug in web3 or npm, no? – Brannon Jul 23 '18 at 16:26

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.