web Initialization is not working correctly?


I am very new to ethereum stuff. I have built a contract and have deployed to rinkby test network. To get the Web 3 access when metamask is not available I have done something like this but it is not working as I expected.

This is how I did it.

import Web3 from 'web3';

let web3;

if(typeof window.ethereum !== 'undefined' && window.web3 !== 'undefined'){

    //we are in the browser
    web3 = new Web3(window.web3.currentProvider);

    const provider = new Web3.providers.HttpProvider(

    web3= new Web3(provider);

export default web3;

Can someone help me to make this workable?. Thank You.

1 answer

  • answered 2018-11-08 08:22 nikos fotiadis

    Where did you get this snippet from? Because if you read the documentation here, the Web3.providers.HttpProvider takes one parameter which is the network. I think you mixed it up a little with truffle's HDWalletProvider which actually takes a mnemonic as well.