0

i'm trying to connect my webiste to testnet using web3 but when i unlock metamask and connect metamask to testnet. web3 cannot connect to metamask.

please help me to solve this problem.

this is my code web3.

    web3 = require('web3');

    if (typeof web3 !== 'undefined') {

     web3 = new Web3(web3.currentProvider);
     console.log("existing web3: provider " + typeof web3);
  }
  else {
        web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/access_token"));
        console.log("new provider " + web3);
    }

Error : Provider not set or invalid

0

I think you have wrong one line

Web3 = require('web3'); // <----  Here you need 'Web3' with 'W'

if (typeof web3 !== 'undefined') {
    web3 = new Web3(web3.currentProvider);
    console.log("existing web3: provider " + typeof web3);
} else {
    web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/access_token"));
    console.log("new provider " + web3);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.