Why cant I authenticate my infura project with my secret key?

Yeah I just tried that it gave me this
{"jsonrpc":"2.0","error":{"code":-32600,"message":"invalid json request"}}
There shouldn’t be any problems on my end as im just making a request correct? I should just be getting ‘answers’ or in this case the blocknumber in the terminal.

Yes you should be getting a hex number back as a response. That error means that you are sending invalid JSON in your data payload. Double check your data payload by pasting it at jsonlint.com and make sure there isn’t some utf-8 character or some other typo.

If you share you code or the full curl request we can take a look at it for you.

curl -u :MYSECRET  -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' https://mainnet.infura.io/v3/myid

I just used the line above as you said and replaced my credentials in the placeholders. I had already verified that my JSON was valid. Not really sure what the problem is here. If I deliberately mess up my secret or project ID I get an authentication error so at least I know its successfully attempting to connect the infura API.

Continuing the discussion from Why cant I authenticate my infura project with my secret key?:

I got it to work. Tested it on a third linux machine I got up and running and it worked. Somehow my windows and my first linux tests both failed for known reasons. Thanks for the help.

This is extremely confusing. The first command in https://blog.infura.io/getting-started-with-infura-28e41844cc89/ says to just do a raw curl GET, which returns a 404. Would be helpful for future newcomers if you updated the tutorial to only include valid code samples.

1 Like

I also see the same commands suggested in the documentation here: https://infura.io/docs/ethereum.
Am I missing something? They all return 404’s for me.

1 Like

Hi @Jared_Nielsen, and welcome to the Infura community! We appreciate your feedback and will definitely update our docs so you don’t get a 404.

Hey @Jared_Nielsen - the reason you’re running into the error is that our API is JSON-RPC, which expects a POST request. The request you’re sending is a GET request, which has no resources available.

Try the same curl but with a valid JSON-RPC API POST request and you should get a response back.

Thanks again for bringing this up to us - we are updating our docs to make this clear so others don’t run into the same confusion!

Thanks! I understand that now. Was just confusing because the intro docs instruct you to make a GET request.

Ahhh, that makes sense! We’re updating them to reflect the need for a POST request :slight_smile:

It looks like docs aren’t updated yet: https://blog.infura.io/getting-started-with-infura-28e41844cc89/

Hey @vyorkin, and welcome to the Infura community! We’ve updated our docs, but we’ll also make sure to update the blog post - thanks!

1 Like

Hello. I am sending ERC721 token via rinkeby.infura. First question.

  1. When I check the “Require project secret for all requests” checkbox, the “getTransactionCount” function stops working and gives the error “Error: Error returned: rejected due to project ID settings”
  2. When the transaction goes through, rinkeby.etherscan.io sees the transaction, in Metamask I get 1 token, but the transaction itself and metadata are not displayed in Metamask …
    What could be the problem?

Hey @Yevhen_Dubovka, and welcome to the Infura community!

  1. If you’re using a WebSocket connection, check this thread out for an example: How to use project secret with wss?
    If not, our API is JSON-RPC, as EG mentioned above on this thread, which expects a POST request. Make sure you’re using a valid JSON-RPC API POST request.
    If neither of these work to fix, can you please send over your code so we can try to debug that way?

  2. What nonce are you using? If you have an incorrect nonce (i.e. a future nonce so the current nonce is 3 and yours is 6), the node won’t receive the next sequential nonce it needs, so your transaction with that future nonce will eventually get dropped. Without having raw transaction information we can’t help you check that, but it’s probably a good place to start! If you need help with getting the nonce, check out our docs!

Hi @starblackDS I had the same issue and it worked with the POST command on my Mac but not Windows (always the outlier :-()))

1 Like

Hey @Solasnarealta, welcome to the Infura community, and thanks for updating this post with your experience! We love to see our users helping each other out :smile:

@Leiya_Kenney ,you are keep saying you will update the documentation and it is just the same after months of complaints of users!
And it is not the blog post, it is documentation that says to try curl https://.infura.io/v3/YOUR-PROJECT-ID
I am sending you the screenshot of the first step of your own documentation guys, where literally everyone goes to start working with you.

Looks like you are really kidding guys

For those using Windows, here’s how I solved the issue of getting the “invalid json request” error: adding escaping backslashes to the "s inside the other quotes. Here’s the example:

What’s on the tutorial:

curl https://mainnet.infura.io/v3/YOUR-PROJECT-ID
-X POST 
-H "Content-Type: application/json" 
-d '{"jsonrpc":"2.0","method":"eth_blockNumber","params": [],"id":1}'

The solution:

curl https://mainnet.infura.io/v3/YOUR-PROJECT-ID 
-X POST 
-H "Content-Type: application/json" 
-d "{\"jsonrpc\":\"2.0\",\"method\":\"eth_blockNumber\",\"params\": [],\"id\":1}"

Result:

    {"jsonrpc":"2.0","id":1,"result":"0xc43001"}

Alternatively if you want to avoid adding \s to every call,
a) Windows 7: install cygwin and run a command line with that (which will have the commands work as if it’s linux)
b) Windows 10: install WSL (Windows Subsystem for Linux) and run a command line with that

2 Likes

Thanks so much. Took me absolutely bloody ages this. Finally solved thanks to your very helpful post!

Please update your docs with this nugget @Infura, there are a lot of folks out there using Windows PowerShell!!