import EmbarkJS from 'Embark/EmbarkJS'; import TestToken from 'Embark/contracts/TestToken'; import React from 'react'; import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; class TestTokenUI extends React.Component { constructor(props) { super(props); this.state = { amountToMint: 100, accountBalance: 0, accountB: web3.eth.defaultAccount, balanceOf: 0, logs: [] } } handleMintAmountChange(e){ this.setState({amountToMint: e.target.value}); } mint(e){ e.preventDefault(); var value = parseInt(this.state.amountToMint, 10); // If web3.js 1.0 is being used if (EmbarkJS.isNewWeb3()) { TestToken.methods.mint(value).send({from: web3.eth.defaultAccount}); this._addToLog("TestToken.methods.mint("+value+").send({from: " + web3.eth.defaultAccount + "})"); } else { TestToken.mint(value); this._addToLog("#blockchain", "TestToken.mint(" + value + ")"); } } getBalance(e){ e.preventDefault(); if (EmbarkJS.isNewWeb3()) { TestToken.methods.balanceOf(web3.eth.defaultAccount).call() .then(_value => this.setState({accountBalance: _value})) } else { TestToken.balanceOf(web3.eth.defaultAccount) .then(_value => this.x({valueGet: _value})) } this._addToLog(TestToken.options.address + ".balanceOf(" + web3.eth.defaultAccount + ")"); } _addToLog(txt){ this.state.logs.push(txt); this.setState({logs: this.state.logs}); } render(){ return (

1. Mint Test Token

this.handleMintAmountChange(e)} />

2. Read your account token balance

Your test token balance is {this.state.accountBalance}

3. Contract Calls

Javascript calls being made:

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

{item}

) }
); } } export default TestTokenUI;