我的 Ganche-GUI 和 metamask 正在运行。但我在控制台中收到以下错误
TypeError:无法读取 App.componentDidMount 处未定义的属性“getId”(App.js:17)
以下是我在 App.js 代码中的代码
import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import getWeb3 from './utils/getweb3';
import CrowdFundingContract from './contracts/CrowdFunding.json';
class App extends Component {
state = {web3: null, accounts: null, contracts: null};
componentDidMount = async () => {
try{
const web3 = await getWeb3();
const accounts = await web3.eth.getAccounts();
const networkId = await web3.eth.net.getId();
const deployedNetwork = CrowdFundingContract.networks[networkId];
const instance = new web3.eth.Contract(CrowdFundingContract.abi, deployedNetwork && deployedNetwork.address);
this.setState({web3, accounts, contract: instance}, this.runExample);
}
catch(error){
alert('Failed to load web3, accounts and contract, check the console');
console.error(error);
}
};
}
我没有把 render() 和函数 returnExample 放在这里。
请帮我