Eth getBalance "basic auth failure\n"

Hello, I am using web3js for requesting

var mainNetHttpHost = ‘’;
var mainNetHttpProvider = new web3js.providers.HttpProvider(this.mainNetHttpHost);
mainNetHttp = new web3js(mainNetHttpProvider);

But I get the error.
Error: Invalid JSON RPC response: “basic auth failure\n”

I tested using postman is success.
What’ wrong?? ㅠ.ㅜ
please help me…

Hi @joo welcome to our community!

Are you able to issue the same command for getBalance directly using a curl to verify that your Project ID is functioning properly?

From our documentation:

curl \
    -X POST \
    -H "Content-Type: application/json" \
    -d '{"jsonrpc":"2.0","method":"eth_getBalance","params": ["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":1}'

Hi @joo,
Check your env variable. Please set it if you haven’t yet.

Thank you

1 Like

Hey @joo , for MY-PROJECT-ID , sign up on and insert your own project’s API key. That should fix it.

@Sean_Infura @wuehler I’m getting the same issue with just using the curl command… I tried generating a new project key but same error not sure what im missing? Am I suppose to give it the secret key too?

curl \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_getBalance","params": ["0x..........", "latest"],"id":1}'

basic auth failure`

Nevermind… looks like I was using a v2 project (even though the project page said to use v3 it didnt work). I tried with a new project and it finally worked.

1 Like

Glad to hear you got it working @alkaidiver! Any other questions at all we’re here to help.