adrianmcli/truffle-next

Show usage of web3

adrianmcli opened this issue · 1 comments

The dapp page currently does not demonstrate use of web3. Perhaps we can add a getEthBalance() method in the component class to get the amount of ETH stored in the first account. It might look something like this:

getEthBalance = async () => {
  const { web3, accounts } = this.props
  const balanceInWei = await web3.eth.getBalance(accounts[0])
  this.setState({ ethBalance: balanceInWei / 1e18 })
}

Of course, we must remember to pass in web3:

<Web3Container
  renderLoading={() => <div>Loading Dapp Page...</div>}
  render={({ accounts, contract, web3 }) => (
    <Dapp accounts={accounts} contract={contract} web3={web3} />
  )}
/>

Sent a PR