I am creating my first Dapp by using web3 1.0.0-beta.37 and trufflfe
While getting the accounts in app.js by using ganache-CLI and Metamask, I am getting following error.
Uncaught TypeError: e is not a function in the console
Following is my code of App.js
import React, { Component } from 'react';
import './App.css';
import FormSubmitContract from './contracts/FormSubmit.json';
import getWeb3 from './utils/getWeb3.js';
class App extends Component {
state = {
web3:null,
address:null,
};
componentDidMount = async () =>{
try{
const web3 = await getWeb3();
console.log(web3);
const accounts = await web3.eth.getAccounts();
console.log(accounts);
const networkId = await web3.eth.net.getId();
const deployedNetwork = FormSubmitContract.networks[networkId];
const instance = new web3.eth.contract(FormSubmitContract.abi,
deployedNetwork, deployedNetwork.address);
}catch(error){
console.log(error);
}
}
I am able to print the web3 in console log
Proxy {_requestManager: s, currentProvider: MetamaskInpageProvider, eth: r, db: e.exports, shh: a, …}
But got undefined in
const accounts = await web3.eth.getAccounts();
console.log(accounts); ==> undefined
I think there has been change in web3 1+ versions for getting the accounts.
Help me.
Thanks in advance
Best Answer
In Metamask, go to Setting -> Privacy & Security -> deactive the "Privacy Mode" option.
If you want to use the Privacy Mode then you have to modify your code
https://medium.com/metamask/eip-1102-preparing-your-dapp-5027b2c9ed76