Skip to content

Instantly share code, notes, and snippets.

View AdamJLemmon's full-sized avatar

Adam J Lemmon AdamJLemmon

View GitHub Profile
@AdamJLemmon
AdamJLemmon / Exchange error catching
Last active July 28, 2017 17:02
Solidity error handling
contract Exchange {
event LogError(string errorMessage);
function executeOrder(
address _buyerEOA,
address _sellerEOA,
address _tokenAddress,
uint _etherAmount,
uint _tokenAmount,
uint _expirationBlock
@AdamJLemmon
AdamJLemmon / deploy.js
Created October 10, 2017 19:02
Example js contract deploy
const STK = artifacts.require('./STK.sol')
// To access the deployed contract, truffle migrate
const stk = await STK.deployed()
// To deploy a new STK contract
const newStk = await STK.new(<constructor params>)
// These 2 addresses are NOT the same
assert(newStk.address != stk.address)
<h3>Active Account</h3>
<DropDownMenu maxHeight={300} width={500} value={this.state.defaultAccount} onChange={this.handleDropDownChange}>
{this.state.availableAccounts}
</DropDownMenu>
<h3>Account Balances</h3>
<p className="App-intro">{this.state.ethBalance / 1e18} ETH</p>
<p className="App-intro"> {this.state.tokenBalance} {this.state.tokenSymbol}</p>
<br/>
<h3>Submit an Order!</h3>
<p>The default exchange supports only the pairing of {this.state.tokenSymbol} / ETH</p>
<TextField floatingLabelText="Bid" style={{width: 75}} value={this.state.tokenSymbol} />
<TextField floatingLabelText="Amount" style={{width: 75}} value={this.state.bidAmount}
onChange={(e, bidAmount) => this.setState({ bidAmount })}
/>
<TextField floatingLabelText="Ask" style={{width: 75}} value="ETH" />
<TextField floatingLabelText="Amount" style={{width: 75}} value={this.state.askAmount}
onChange={(e, askAmount) => this.setState({ askAmount })}
/>
// Submit a new order to the order book.
submitOrder() {
const { askAmount, bidAmount, defaultAccount, exchange, token } = this.state
const from = this.web3.eth.accounts[defaultAccount]
const gas = 1e6
// First give the exchange the appropriate allowance
token.approve(exchange.address, bidAmount, { from, gas },
(err, res) => {
if (err) {
<h3>Order Book</h3>
<p>Select an order to execute!</p>
<RaisedButton label="Execute Order" labelPosition="after" style={{width: 300}} secondary={true}
onClick={() => this.executeOrder(this.selectedOrder)}
/>
<Table style={{ maxHeight: 500, overflow: "auto" }} fixedHeader={true} multiSelectable={false}
onRowSelection={r => { if (this.state.orderBook[r[0]]) this.selectedOrder = this.state.orderBook[r[0]].key}}>
<TableHeader>
<TableRow>
<TableHeaderColumn>Maker</TableHeaderColumn>
pragma solidity 0.4.24;
contract TicTacToe {
address public player1_;
address public player2_;
/** The game board itself
* 0, 1, 2
import React, { Component } from 'react';
import logo from './blg.jpg';
import './App.css';
// Import the web3 library
import Web3 from 'web3'
import ipfsAPI from 'ipfs-api'
// Material UI
import MenuItem from 'material-ui/MenuItem';
const { sendRequest } = require('../controller/src/utils/requests');
const { API_PATH, SERVER_PORT } = require('../controller/src/constants');
// const apiUrl = `${API_PATH}:${SERVER_PORT}`;
const apiUrl = 'http://23.96.29.24:3000'
// Pass in number of assets to add as command line arg
const assetsToAdd = process.argv[2] || 2;
const type = 'goat';
const inputs = [ 'test' ];
const { sendRequest } = require('../controller/src/utils/requests');
const { API_PATH, SERVER_PORT } = require('../controller/src/constants');
// const apiUrl = `${API_PATH}:${SERVER_PORT}`;
const apiUrl = 'http://23.96.29.24:3000'
// Pass in number of assets to add as command line arg
const assetsToAdd = process.argv[2] || 2;
const type = 'goat';
const inputs = [ 'test' ];