Closed justinmchase closed 6 years ago
Actually using any api seems to not work. I'm using INFURA now instead of a local docker container and even the simplest examples from the main README don't seem to work. It seems like there is a version mismatch somewhere, any advice here on which versions of things I should be using to match up?
var Web3 = require('web3')
var web3 = new Web3()
web3.setProvider(new web3.providers.HttpProvider('https://ropsten.infura.io/...'))
console.log('coinbase:', web3.eth.coinbase) // Error: invalid JSON RPC response
I managed to get it to work but it was a bit of an ordeal. First off I installed the latest 1.0 release:
npm install web3@1.0.0-beta.28
Next I was missing the --shh
flag in my docker compose command, which is apparently necessary since whisper is still an experimental feature. Here is my docker-compose.yml
file:
eth:
image: ethereum/client-go
stdin_open: true
tty: true
ports:
- "8545:8545" # rpc
- "8546:8546" # ws
- "30303:30303"
command: --fast --cache=512 --shh --ws --wsaddr=0.0.0.0 --wsorigins *
Then finally, which I'm a little embarassed to admit but the fact that ws
and rpc
use different ports by 1 took me too long to figure out. Thus listing both ports above and my below finally working script:
var Web3 = require('web3')
var type = 'ws' // 'rpc'
var connectionString = type === 'ws'
? 'ws://localhost:8546'
: 'http://localhost:8545'
var web3 = new Web3(Web3.givenProvider || connectionString)
web3.shh.getVersion((err, version) => {
if (err) return console.error(err.message)
console.log(version)
})
Its now working! And it prints out 5.0
Hello!
I'm trying to simply test out using the whisper api. I'm very new to this but what I am doing is running a local ethereum node using docker and using nodejs to attempt to communicate with that server. I am getting some errors though and I'm not sure what I'm doing wrong.
Here is my basic docker-compose file:
And my basic nodejs script:
And then to run:
The errors I am getting are:
What am I doing wrong?