I'm trying to get the network ID from the Web3 object on the client side (i.e. - while running Javascript code in the browser). I have code that confirms that the object exists and it does. I have the Metamask extension installed and configured in Chrome. I have clicked on the extension and I am definitely connected to the Ganache network client (Localhost 8545). However, every time I call **web3.version.getNetwork()**
the result is **undefined**
. Does anyone know why this is happening and how I can fix it?
UPDATE: I tried the same test with web3.eth.getAccounts() and that too is coming back undefined. I'm guessing I'll get the same result with any of the Web3 methods/properties I try.
// Make sure the Web3.js object has been defined.
web3_helpers.web3AndMetamaskCheck();
if (typeof gameDetailsObj == 'undefined' || gameDetailsObj == null)
throw new Error(errPrefix + 'The game details object is unassigned.');
if (typeof currentUserObj == 'undefined' || currentUserObj == null)
throw new Error(errPrefix + 'The current user object is unassigned.');
// >>>>> getNetworkCall is ALWAYS 'undefined'.
var getNetworkCall = web3.version.getNetwork();