It was originally raised at https://github.com/ensdomains/ensjs/issues/36
In the issue, it was throwing an error at web3.eth.net.getId
but looks like the same error happens in any function call (the test code below is calling getBlockNumber
).
const Web3 = require('web3')
const Web3Legacy = require('web3legacy')
console.log('web3 version', (new Web3()).version)
console.log('web3 legacy version', (new Web3Legacy()).version)
// Do "export INFURA_PROJECT_ID=YOURPROJECTID" on your terminal
const projectid = process.env.INFURA_PROJECT_ID
const endpoint = 'https://mainnet.infura.io/v3/' + projectid
const provider = new Web3.providers.HttpProvider(endpoint)
const web3 = new Web3(provider)
const web3legacy = new Web3Legacy(provider)
async function call(){
console.log('latest web3')
console.log('blocknumber', await web3.eth.getBlockNumber())
console.log('lagacy web3')
console.log('blocknumber', await web3legacy.eth.getBlockNumber())
}
call()
The above script shows the same error message
web3 version 1.0.0-beta.55
web3 legacy version 1.0.0-beta.37
latest web3
blocknumber 7732404
lagacy web3
(node:57809) UnhandledPromiseRejectionWarning: Error: Node error: {"code":-32600,"message":"invalid json request"}
at Function.validate (/Users/makoto/work/ens/tmp/ethereum-ens-versions/node_modules/web3-providers/dist/web3-providers.cjs.js:114:18)
at HttpProvider._callee$ (/Users/makoto/work/ens/tmp/ethereum-ens-versions/node_modules/web3-providers/dist/web3-providers.cjs.js:710:61)
at tryCatch (/Users/makoto/work/ens/tmp/ethereum-ens-versions/node_modules/regenerator-runtime/runtime.js:45:40)
at Generator.invoke [as _invoke] (/Users/makoto/work/ens/tmp/ethereum-ens-versions/node_modules/regenerator-runtime/runtime.js:271:22)
at Generator.prototype.(anonymous function) [as next] (/Users/makoto/work/ens/tmp/ethereum-ens-versions/node_modules/regenerator-runtime/runtime.js:97:21)
at asyncGeneratorStep (/Users/makoto/work/ens/tmp/ethereum-ens-versions/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
at _next (/Users/makoto/work/ens/tmp/ethereum-ens-versions/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)
at processTicksAndRejections (internal/process/task_queues.js:86:5)
(node:57809) 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)
(node:57809) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Here is the gist of the code and package.json which should be enough to replicate the issue.
It would be great if you can support version 35~37 as they were relatively stable versions and I believe many projects still use the version. We will eventually upgrade web3.js to the latest version but the latest version has lots of breaking changes and need a bit more time to support.