import EmbarkJS from 'Embark/EmbarkJS'; import ERC20Token from 'Embark/contracts/ERC20Token'; import React from 'react'; import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; class ERC20TokenUI extends React.Component { constructor(props) { super(props); this.state = { balanceOf: 0, transferTo: "", transferAmount: 0, logs: [] } } contractAddress(e){ e.preventDefault(); var tokenAddress = e.target.value; ERC20Token.options.address = tokenAddress; } update_transferTo(e){ this.setState({transferTo: e.target.value}); } update_transferAmount(e){ this.setState({transferAmount: e.target.value}); } transfer(e){ var to = this.state.transferTo; var amount = this.state.transferAmount; var tx = ERC20Token.methods.transfer(to, amount).send({from: web3.eth.defaultAccount}); this._addToLog(ERC20Token.options.address+".transfer(" + to + ", "+amount+")"); } approve(e){ var to = this.state.transferTo; var amount = this.state.transferAmount; var tx = ERC20Token.methods.approve(to, amount).send({from: web3.eth.defaultAccount}); this._addToLog(ERC20Token.options.address+".approve(" + to + ", "+amount+")"); } balanceOf(e){ e.preventDefault(); var who = e.target.value; if (EmbarkJS.isNewWeb3()) { ERC20Token.methods.balanceOf(who).call() .then(_value => this.setState({balanceOf: _value})) } else { ERC20Token.balanceOf(who) .then(_value => this.x({balanceOf: _value})); } this._addToLog(ERC20Token.options.address+".balanceOf(" + who + ")"); } _addToLog(txt){ this.state.logs.push(txt); this.setState({logs: this.state.logs}); } render(){ return (

Set token contract address

this.contractAddress(e)} />

Read account token balance

Transfer/Approve token balance

Contract Calls

Javascript calls being made:

{ this.state.logs.map((item, i) =>

{item}

) }
); } } export default ERC20TokenUI;