Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InfuraProvider throws an Error #868

Closed
lalexgap opened this issue Jun 4, 2020 · 14 comments
Closed

InfuraProvider throws an Error #868

lalexgap opened this issue Jun 4, 2020 · 14 comments
Labels
discussion Questions, feedback and general information.

Comments

@lalexgap
Copy link

lalexgap commented Jun 4, 2020

I'm attempting to use the InfuraProvider to connect to the ropsten network but I get an error when doing so.

Doing this

const provider = new InfuraProvider(
  "ropsten",
  "780797e7832148289ef283af4ade0a58"
);
provider.getBlockNumber().then(console.log);

results in the following error:

index.js:165 Uncaught (in promise) Error: missing response (serverError={}, url="https://ropsten.infura.io/v3/780797e7832148289ef283af4ade0a58", code=SERVER_ERROR, version=web/5.0.0-beta.141)
    at Logger.makeError (index.js:165)
    at Logger.throwError (index.js:174)
    at index.js:100
    at Generator.throw (<anonymous>)
    at rejected (index.js:6)

As a sanity check using I made sure I could access the Infura endpoint with my project id using curl which works

curl -X POST \   
-H "Content-Type: application/json" \
--data '{"jsonrpc": "2.0", "id": 1, "method": "eth_blockNumber", "params": []}' \
"https://ropsten.infura.io/v3/780797e7832148289ef283af4ade0a58"

Note: Infura project ID is a throw-away that will be deleted once this is resolved :)

@zemse
Copy link
Collaborator

zemse commented Jun 5, 2020

@lalexgap can you confirm if you are getting this error on the latest ethers/5.0.0-beta.191 version?

@ricmoo
Copy link
Member

ricmoo commented Jun 5, 2020

@lalexgap Yeah, can you confirm this is still happening? I just tried on ethers/5.0.0-beta.191 (using @ethersproject/web@5.0.0-beta.141) and cannot reproduce this.

Was there maybe a short INFURA hiccup when you tried this?

@ricmoo ricmoo added the discussion Questions, feedback and general information. label Jun 5, 2020
@lalexgap
Copy link
Author

lalexgap commented Jun 6, 2020

@lalexgap can you confirm if you are getting this error on the latest ethers/5.0.0-beta.191 version?

Yup here's a repo where I'm able to reproduce it using 5.0.0-beta.191. I've just verified that I'm still seeing the same behavior this morning using the repo above.

The project where we originally ran into this is using 5.0.0-beta.187.

@lalexgap
Copy link
Author

lalexgap commented Jun 6, 2020

Ah I think I found the culprit. We were importing InfuraProvider like this

import { InfuraProvider } from "@ethersproject/providers";

When I import providers from ethers things work:

import { providers } from "ethers";
const provider = new providers.InfuraProvider...

We probably shouldn't be importing from anything but ethers but I think we did that so we could import InfuraProvider directly instead of providers.

Slightly surprised that one would fail and the other wouldn't.

@ricmoo
Copy link
Member

ricmoo commented Jun 6, 2020

I’m surprised that makes a difference, but perhaps it has to do with the bundling? Looks like your app is a React something-something? Maybe it needs the browser version which the ethers package automatically bundles and maybe it isn’t grabbing the browser version from the sub-package?

@ricmoo
Copy link
Member

ricmoo commented Jun 6, 2020

(also, what file is that in? I couldn’t find it. I don’t check out and install repos on my computer, so I was trying to figure out how to repo it in a single file)

@lalexgap
Copy link
Author

lalexgap commented Jun 6, 2020

(also, what file is that in? I couldn’t find it. I don’t check out and install repos on my computer, so I was trying to figure out how to repo it in a single file)

https://github.com/lalexgap/repro-ethers-issue/blob/1c7f22efde6d2942a738da96d6cfc5ff7b85c581/src/index.js#L6

Specifically

import { InfuraProvider } from "@ethersproject/providers";
const provider = new InfuraProvider(
  "ropsten",
  "780797e7832148289ef283af4ade0a58"
);
provider.getBlockNumber().then(console.log);

@ricmoo
Copy link
Member

ricmoo commented Jun 12, 2020

Can you try out 5.0.0-beta.192 and see if you still have any problems? It might be related to a similar URL shim.

@ricmoo
Copy link
Member

ricmoo commented Jul 5, 2020

I think this was fixed with changing the call signature to the URL library (the library pulled in by some bundlers mimics the node 6 API), so I'm going to close this now, but if it is still a problem, please re-open.

Thanks! :)

@ricmoo ricmoo closed this as completed Jul 5, 2020
@extramilegit
Copy link

This is the response i get when i want to fetch balance using Infura. Please what is wrong

[Unhandled promise rejection: Error: bad response (status=400, headers={"vary":"Origin","content-type":"application/json","date":"Tue, 08 Jun 2021 15:01:22 GMT","content-length":"74"}, body="{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid json request"}}", requestBody="{"method":"eth_getBalance","params":["0x77ab999d1e9f152156b4411e1f3e2a42dab8cd6d","latest"],"id":42,"jsonrpc":"2.0"}", requestMethod="POST", url="https://mainnet.infura.io/v3/c3db1af154164**************9", code=SERVER_ERROR, version=web/5.3.0)]

@extramilegit
Copy link

My lines of code
const network = "mainnet";
const provider = new ethers.providers.InfuraProvider(network, {
projectId: "c3db272c665f70df0d9",
projectSecret: "1b326380e58328ea6"
});

const getBalanceAsync = async (address) => {
let rawBalance = await provider.getBalance(address);
return (rawBalance);
}

@dcsan
Copy link

dcsan commented Aug 29, 2021

I see this all the time with a project built with eth-scaffold.
is there anyway to catch this error from blowing up the front-end ?

missing response (requestBody="{"method":"eth_getBalance","params":

@lopezdp
Copy link

lopezdp commented May 15, 2022

This is the response i get when i want to fetch balance using Infura. Please what is wrong

[Unhandled promise rejection: Error: bad response (status=400, headers={"vary":"Origin","content-type":"application/json","date":"Tue, 08 Jun 2021 15:01:22 GMT","content-length":"74"}, body="{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid json request"}}", requestBody="{"method":"eth_getBalance","params":["0x77ab999d1e9f152156b4411e1f3e2a42dab8cd6d","latest"],"id":42,"jsonrpc":"2.0"}", requestMethod="POST", url="https://mainnet.infura.io/v3/c3db1af154164**************9", code=SERVER_ERROR, version=web/5.3.0)]

I get same error and same configuration

im using nodejs14.x from a serverless lambda

@TheKnightCoder
Copy link

This is the response i get when i want to fetch balance using Infura. Please what is wrong
[Unhandled promise rejection: Error: bad response (status=400, headers={"vary":"Origin","content-type":"application/json","date":"Tue, 08 Jun 2021 15:01:22 GMT","content-length":"74"}, body="{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid json request"}}", requestBody="{"method":"eth_getBalance","params":["0x77ab999d1e9f152156b4411e1f3e2a42dab8cd6d","latest"],"id":42,"jsonrpc":"2.0"}", requestMethod="POST", url="https://mainnet.infura.io/v3/c3db1af154164**************9", code=SERVER_ERROR, version=web/5.3.0)]

I get same error and same configuration

im using nodejs14.x from a serverless lambda

I managed to resolve this by making sure I bundle with cjs and not esm. Esm was causing me problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Questions, feedback and general information.
Projects
None yet
Development

No branches or pull requests

7 participants