我正在使用web3js 1.0.0.37-beta和reactjs开发dapp。
我在web3.eth.getAccounts考试中空白。以下是我的代码
import React, {Component} from 'react';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import web3 from './web3.js';
import voting from './voting.js';
import './App.css';
class App extends Component {
constructor(){
super();
this.state = {
account: '',
}
}
componentDidMount = async () => {
const accounts = await web3.eth.getAccounts();
console.log(accounts[0]);
}import Web3 from 'web3';
const web3 = new Web3(window.web3.currentProvider);
export default web3;import web3 from './web3';
const address = "0xd278D619eBca4583bc9923F0ac0043525CD08bA8";
const abi = [.......];
export default web3.eth.contract(abi, address);控制台出错了

请帮帮我。
发布于 2019-08-13 15:19:00
首先需要执行ethereum.enable(),请参阅:https://metamask.github.io/metamask-docs/Advanced_概念/提供者_API接口
或者,您也可以禁用元See的隐私模式(在设置/安全和隐私中),请参见https://medium.com/metamask/introducing-privacy-mode-42549d4870fa
顺便说一句,web3.js1.2.1现在可以使用了。
https://ethereum.stackexchange.com/questions/73880
复制相似问题