0

I'm exploring web3 following instructions from the docs and running the code below. The function throws with the error message being: Error: Invalid JSON RPC response: ""

For context the code below works when running a local node script, but gives me the error when running in a Node 8 environment hosted by firebase.

What am I doing wrong and can anyone explain what it means?

const web3 = new Web3(new Web3.providers.HttpProvider("https://mainnet.infura.io/v3/<project ID>"))
const weiBalance = await web3.eth.getBalance("0x52bc44d5378309EE2abF1539BF71dE1b7d7bE3b5")
console.log(weiBalance)
3
  • Perhaps you need to substitute a specific <project ID> in the first line?
    – Mad Jackal
    Dec 29 '20 at 17:19
  • Just so you know, web3.eth.getBalance returns a Promise object, which you need to resolve in order to get the actual balance of the input address. Dec 29 '20 at 17:34
  • yes sorry to not be more specific here. <project ID> serves as a placeholder here I added my id in the actual code. Also I added an await for the promise to resolve. That was not related to the error
    – FreddyCoen
    Dec 29 '20 at 18:11
1

Ok i figured this out. Had to upgrade to paid plan in firebase.

2
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review Dec 30 '20 at 18:58
  • 1
    @ShaneFontaine It does answer the question: it doesn't work in firebase free tiers.
    – Ismael
    Jan 2 at 14:36

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.