Skip to content

Instantly share code, notes, and snippets.

@adrianmcli
Last active November 22, 2017 10:10
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 adrianmcli/98fc859df70106fa697a305b6295662f to your computer and use it in GitHub Desktop.
Save adrianmcli/98fc859df70106fa697a305b6295662f to your computer and use it in GitHub Desktop.
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