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