Last active
November 22, 2017 10:10
-
-
Save adrianmcli/98fc859df70106fa697a305b6295662f 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 from 'react' | |
import withWeb3 from '../lib/withWeb3' | |
// Demonstration of a basic dapp with the withWeb3 higher-order component | |
class Dapp extends React.Component { | |
state = { balance: null } | |
storeValue = async () => { | |
const { accounts, contract } = this.props | |
const response = await contract.set(5, { from: accounts[0] }) | |
alert("Stored 5 into account") | |
} | |
getValue = async () => { | |
const { accounts, contract } = this.props | |
const response = await contract.get.call({ from: accounts[0] }) | |
this.setState({ balance: response.toNumber() }) | |
} | |
render() { | |
const { web3, accounts, contract } = this.props | |
const { balance } = this.state | |
return ( | |
<div> | |
<h1>My Dapp</h1> | |
<button onClick={this.storeValue}>Store 5 into account balance</button> | |
<button onClick={this.getValue}>Get account balance</button> | |
<div>Balance: {balance ? balance : 'N/A'}</div> | |
</div> | |
) | |
} | |
} | |
export default withWeb3(Dapp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment