getAccounts in web3 js undefined

by urjit on rails   Last Updated August 13, 2019 13:28 PM - source

I am working on dapp with web3js 1.0.0.37-beta with reactjs.
I got blank in web3.eth.getAccounts. Following is my code

App.js

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]);          
}

web3.js

import Web3 from 'web3';
const web3 = new Web3(window.web3.currentProvider);
export default web3;

voting.js

import web3 from './web3';

const address = "0xd278D619eBca4583bc9923F0ac0043525CD08bA8";

const abi = [.......];

export default web3.eth.contract(abi, address);

I got error in console

enter image description here

Please help me.



Related Questions



address.replace is not a function

Updated March 19, 2019 17:28 PM


Web3 not defined

Updated December 20, 2017 21:28 PM