Created
November 4, 2021 18:05
-
-
Save sujithsomraaj/662c4ef6a33acf4ba33f9bf50105b60a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import './index.css'; | |
import Web3 from 'web3'; | |
class Wallet extends Component { | |
render() { | |
return ( | |
<div className="container1"> | |
<h1> Wallet Data </h1> | |
<p>{this.props.account} </p> | |
</div> | |
); | |
} | |
} | |
class App extends Component { | |
async createAccount() { | |
var account = await this.state.web3.eth.getAccounts(); | |
this.setState({account: account[0]}); | |
} | |
constructor(props) { | |
super(props); | |
this.createAccount = this.createAccount.bind(this) | |
this.state = { | |
web3: new Web3(new Web3.providers.HttpProvider("http://127.0.0.1:7545")), | |
account: '', | |
}; | |
} | |
render() { | |
return ( | |
<div className="container"> | |
<h1>Hello, World!</h1> | |
<Wallet account={this.state.account}/> | |
<button type="button" onClick={this.createAccount}>Create account | |
</button> | |
</div> | |
); | |
} | |
} | |
export default App; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment