I am going to connect my contract with the website.However,there was something wrong with the web3? I'm not sure.

import Web3 from "web3";
const web3 = new Web3(window.web3.currentProvider);
const address = '0x9e3c32291496E8793xxxxxxxxxxxx'
const abi = [{"constant":true,"inputs":[],"name":"getBalance","outputs":[{"name":"","type":"uint256"}],"payable":.......];
const lottery = new web3.eth.Contract(abi, address);

used the functions of contract.

class App extends Component{
    this.state = {manager:'abc'};
  async componentDidMount(){
      const ManAddress = await lottery.methods.getManager().call();
      console.log('********' + ManAddress);
  render() {

the website consoler returned

TypeError: window.web3 is undefined
  • if you are using web 1.* try const web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); – Badr Bellaj Aug 11 '19 at 11:42

You need to execute ethereum.enable() first, see: https://metamask.github.io/metamask-docs/Advanced_Concepts/Provider_API

Alternatively you could disable the privacy mode of metamask (in settings / Security & Privacy) See https://medium.com/metamask/introducing-privacy-mode-42549d4870fa

| improve this answer | |

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.