I’m pretty new to Ethereum, but have been making great progress, using Infura so I don’t have to host a node… until today.
I am getting the following error:
2019-11-21 16:50:21 - XXX(0x1addbb6462cb45c91f0dd116c6480aa586de0a29)
(node:51654) UnhandledPromiseRejectionWarning: Error: Returned error: invalid argument 1: json: cannot unmarshal number into Go value of type string
at Object.ErrorResponse (/Users/u1h/Project/bp_chainNode/node_modules/web3-core-helpers/src/errors.js:29:16)
at Object.<anonymous> (/Users/u1h/Project/bp_chainNode/node_modules/web3-core-requestmanager/src/index.js:140:36)
at /Users/u1h/Project/bp_chainNode/node_modules/web3-providers-ws/src/index.js:127:44
at Array.forEach (<anonymous>)
at W3CWebSocket.WebsocketProvider.connection.onmessage (/Users/u1h/Project/bp_chainNode/node_modules/web3-providers-ws/src/index.js:104:36)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/u1h/Project/bp_chainNode/node_modules/yaeti/lib/EventTarget.js:107:17)
at W3CWebSocket.onMessage (/Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/W3CWebSocket.js:234:14)
at WebSocketConnection.<anonymous> (/Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/W3CWebSocket.js:205:19)
at WebSocketConnection.emit (events.js:210:5)
at WebSocketConnection.processFrame (/Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/WebSocketConnection.js:554:26)
at /Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/WebSocketConnection.js:323:40
at processTicksAndRejections (internal/process/task_queues.js:75:11)
(node:51654) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
The error looks like Infura are running Geth and this is the error Geth is giving directly to them. I think this because it talks about “Go value of type string”.
I created a simplest example program to prove the error:
/Project/bp_chainNode$ node test_call.js
X1
X2
X3
(node:92621) UnhandledPromiseRejectionWarning: Error: Returned error: invalid argument 1: json: cannot unmarshal number into Go value of type string
at Object.ErrorResponse (/Users/u1h/Project/bp_chainNode/node_modules/web3-core-helpers/src/errors.js:29:16)
at Object.<anonymous> (/Users/u1h/Project/bp_chainNode/node_modules/web3-core-requestmanager/src/index.js:140:36)
at /Users/u1h/Project/bp_chainNode/node_modules/web3-providers-ws/src/index.js:127:44
at Array.forEach (<anonymous>)
at W3CWebSocket.WebsocketProvider.connection.onmessage (/Users/u1h/Project/bp_chainNode/node_modules/web3-providers-ws/src/index.js:104:36)
at W3CWebSocket._dispatchEvent [as dispatchEvent] (/Users/u1h/Project/bp_chainNode/node_modules/yaeti/lib/EventTarget.js:107:17)
at W3CWebSocket.onMessage (/Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/W3CWebSocket.js:234:14)
at WebSocketConnection.<anonymous> (/Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/W3CWebSocket.js:205:19)
at WebSocketConnection.emit (events.js:210:5)
at WebSocketConnection.processFrame (/Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/WebSocketConnection.js:554:26)
at /Users/u1h/Project/bp_chainNode/node_modules/websocket/lib/WebSocketConnection.js:323:40
at processTicksAndRejections (internal/process/task_queues.js:75:11)
Hi @prographo welcome to the community and thank you for a very detailed report.
While we dig into why this specific functionality isn’t working, I would recommend trying to send your getBalance request using HTTP instead of WSS. We typically recommend non-subscription based requests to go through HTTP. WSS primary use is for subscriptions.
Technically requesting that data over WSS or HTTP shouldn’t behave any different. However there could be different handling in place inside the library you are using that prefers subscription based connections for WSS. I would use WSS for subs only unless you are writing the connection yourself without the use of a Web3 library.
We looked into this further, it is possible that the web3 library is sending the block number as a number instead of as a hex string. We have not confirmed this though.
I guess the problem with using the latest block is that it is unstable, i find that it is often changed in a re-org, so I get something from infura, the next block backs it out, the following block has it again… if I could use the previous to last block this would happen very often.
We do recommend lagging 2-3 blocks for this case. We have discussed adding block hash support to more methods which would be more reliable, but by default the nodes do not support this.
To make sure I understand your usage flow, you are asking eth_blockNumber for the latest block number and than feeding that into eth_getBalance for a specific address? Is there another piece that you’re connecting here based on the latest block number?
Ok looked back through your code and the issue seems to be that Web3.js is sending the block parameter as an integer and not a hex string. We recommend reaching out to them to confirm.