It's really weird that I got empty array after I tried to web3.eth.getAccounts().then(console.log);
and I also got a warning which is ./node_modules/web3-eth-accounts/src/scrypt.js Critical dependency: the request of a dependency is an expression
.
In this project I first cmd create-react-app lottery_react
and then all I changed in my lottery_react
folder are modifying App.js and creating web3.js file. I can't find what's wrong in these file. Please help!
I've seen this but I didn't get the error that he/she gets. I only get a warning.
This is my App.js
import React, {Component} from 'react';
import logo from './logo.svg';
import './App.css';
import web3 from './web3';
class App extends Component {
render(){
web3.eth.getAccounts().then(console.log);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}
}
export default App;
This is my web3.js file
import Web3 from 'web3';
const web3 = new Web3(window.web3.currentProvider);
export default web3;
web3.eth.getAccounts()
gives you a list of unlocked accounts on your node. It works well with Ganache (which by default sets up a node with 10 unlocked accounts). But why should it work on a public network like Rinkeby?