Skip to content

Instantly share code, notes, and snippets.

@sujithsomraaj
Created November 4, 2021 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sujithsomraaj/662c4ef6a33acf4ba33f9bf50105b60a to your computer and use it in GitHub Desktop.
Save sujithsomraaj/662c4ef6a33acf4ba33f9bf50105b60a to your computer and use it in GitHub Desktop.
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