import EmbarkJS from 'Embark/EmbarkJS'; import SimpleStorage from '../../embarkArtifacts/contracts/SimpleStorage'; import React from 'react'; import { Form, FormGroup, FormControl, HelpBlock, Button } from 'react-bootstrap'; class Blockchain extends React.Component { constructor(props) { super(props); this.state = { valueSet: 10, valueGet: "", logs: [] }; } handleChange(e) { this.setState({ valueSet: e.target.value }); } checkEnter(e, func) { if (e.key !== 'Enter') { return; } e.preventDefault(); func.apply(this, [e]); } async setValue(e) { e.preventDefault(); await EmbarkJS.enableEthereum(); var value = parseInt(this.state.valueSet, 10); SimpleStorage.methods.set(value).send(); this._addToLog("SimpleStorage.methods.set(value).send()"); } getValue(e) { e.preventDefault(); SimpleStorage.methods.get().call().then(_value => this.setState({ valueGet: _value })); this._addToLog("SimpleStorage.methods.get(console.log)"); } _addToLog(txt) { this.state.logs.push(txt); this.setState({ logs: this.state.logs }); } render() { return (

1. Set the value in the blockchain

this.checkEnter(e, this.setValue)}> this.handleChange(e)}/> Once you set the value, the transaction will need to be mined and then the value will be updated on the blockchain.

2. Get the current value

current value is {this.state.valueGet} Click the button to get the current value. The initial value is 100.

3. Contract Calls

Javascript calls being made:

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

{item}

) }
); } } export default Blockchain;