How to use infura API with web3 js? Where should I put secret key?
Asked
Active
Viewed 8,025 times
4
-
See https://medium.com/coinmonks/deploy-your-smart-contract-directly-from-truffle-with-infura-ba1e1f1d40c2 – GrandFleet Oct 31 '18 at 19:37
1 Answers
8
First, import web3 as such:
const Web3 = require('web3')
Then instantiate a variable (in my case web3) and set a provider:
const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/INFURA_ACCESS_TOKEN:8545'))
Then you can use all the available web3 methods.
Hope it helped you!
-
1This metod stopped working in browser right? It is telling about CORS headers – gkucmierz Nov 05 '18 at 15:41
-
@gkucmierz I think you have to use NodeJS. Browsers won't allow CORS unless it's HTTP(S) apparently. – Philip Rego Sep 16 '20 at 01:51