Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to a protected infura project with web3?

Tags:

node.js

web3js

I'm using web3 in node js to create new Web3.providers.HttpProvider with a infura project, which is configure with "Require project secret for all requests"

In infura:

https://infura.io/docs/gettingStarted/authentication

explains calling by curl is:

curl --user :YOUR-PROJECT-SECRET
https://.infura.io/v3/YOUR-PROJECT-ID

I've used:

const client = new Web3(new Web3.providers.HttpProvider('https://YOUR-PROJECT-SECRET@<network>.infura.io/v3/YOUR-PROJECT-ID');

And it doesn't work.

How can I add the --user tag and its value into new Web3.providers.HttpProvider, please?

Thanks in advance!

like image 230
simonced Avatar asked Jan 01 '23 00:01

simonced


1 Answers

I'm awsering my question:

I solved it adding ":" before YOUR-PROJECT-SECRET, like this:

const client = new Web3(new Web3.providers.HttpProvider('https://:YOUR-PROJECT-SECRET@<network>.infura.io/v3/YOUR-PROJECT-ID');

It's working now!

like image 114
simonced Avatar answered Jan 05 '23 16:01

simonced