The params array inside the json rpc call should not contain an empty object when creating subscription to "newBlockHeaders". The call should be:
{"method":"eth_subscribe","params":["newHeads"],"id":1,"jsonrpc":"2.0"}
When creating the subscription for "newBlockHeaders", the json rpc call sends in the params array an extra parameter, to be more specific an empty object:
{"method":"eth_subscribe","params":["newHeads", {}],"id":1,"jsonrpc":"2.0"}
Therefor Parity returns the following error:
{"code":-32602,"message":"Couldn't parse parameters: newHeads","data":"\"Expected no parameters.\""}
On Geth it's working and no errors are returned, but Parity seems more strict.
const Web3 = require('web3');
const web3 = new Web3("ws://localhost:8546"); // This needs to be a Parity node
web3.eth.subscribe('newBlockHeaders', (error, result) => {
if (!error) {
console.log(result);
return;
}
console.error(error);
}).on("data", (blockHeader) => {
console.log(blockHeader);
}).on("error", (error) => {
console.error(error)
});
Error: Provider error: Error: Node error: {"code":-32602,"message":"Couldn't parse parameters: newHeads","data":"\"Expected no parameters.\""}
at /debug-app/node_modules/web3-providers/dist/web3-providers.cjs.js:334:15
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:189:7)
Parity 2.2.8-stable and 2.2.9-stable
NPM 6.4.1
Node 8.15.0
Web3js 1.0.0-beta.46
OS Ubuntu 18.04
Using Web3js 1.0.0-beta.37, the pre-migration to ES6 version is working. I did a quick verification and the rpc call does not contain the extra empty object in the params array when creating the above mentioned subscription.
Thanks for submitting this issue I鈥檒l fix it asap.
Tested it with a parity node and the version beta.46 and it works without a problem. Are you sure that you are using version beta.46 of the Web3.js lib?
Yes, I am sure it was beta.46. Retested now with a clean "npm install" and no more errors.
It is odd indeed, the issue can be closed, thank you.