Skip to content

Instantly share code, notes, and snippets.

View devonwesley's full-sized avatar
Probably at coffee shop in Oakland, CA.

Devon Wesley devonwesley

Probably at coffee shop in Oakland, CA.
  • Oakland, CA
View GitHub Profile
@devonwesley
devonwesley / CreateContract.js
Last active December 20, 2017 02:27
This is how we create contracts, and display them in the view.
function createContract(contract, panel) {
const propHandler = lists => props => {
if(!filterProps(props[0])) {
const container = categorizeContractProps({
key: props[0],
value: props[1],
...lists
})
container.append(createContractElement(props, container))
@devonwesley
devonwesley / CreatePropsContainers.js
Last active December 20, 2017 02:28
These our the 3 panel containers for our contract props.
function createPropsContainers(panel, callback) {
document.getElementById('contractFunction').appendChild(panel)
const propsList = createPanelContainer('props')
const hashList = createPanelContainer('hashes')
const functionList = createPanelContainer()
const banner = '<H3><strong>Contract Functions: </strong></H3>'
functionList.innerHTML = banner
panel.append(propsList)
panel.append(hashList)
@devonwesley
devonwesley / CategorizeContractProps.js
Last active December 20, 2017 02:30
This function helps us pick which containers a prop is for.
function categorizeContractProps(params) {
const hashNames = {
'hash': 'hash',
'blockHash': 'blockHash',
'input': 'input',
'from': 'from',
}
if (hashNames[params.key]) {
return params.hashList
@devonwesley
devonwesley / FilterProps.js
Last active December 20, 2017 02:29
This is the information about the contract and transaction that we don't want.
function filterProps(prop) {
const excludes = {
'_eth': '_eth',
'abi': 'abi',
'allEvents': 'allEvents',
'to': 'to',
'value': 'value',
'blockNumber': 'blockNumber',
'address': 'address',
'transactionHash': 'transactionHash',
@devonwesley
devonwesley / CreateContractElement.js
Last active December 20, 2017 02:32
This function is going to create elements for our contract props.
function createContractElement(contractProp, container) {
return typeof contractProp[1] === 'function'
? createContractFunction(contractProp, container)
: createContractProp(contractProp, 'P')
}
function createContractFunction(contractFunc, container) {
const name = contractFunc[0]
const func = contractFunc[1]
const btn = document.createElement('BUTTON')
@devonwesley
devonwesley / CreateContractHash.js
Last active December 20, 2017 18:07
This creates an element from the contract props pass to it.
function createContractHash(name, hash, tag, className) {
const el = document.createElement(tag)
const value = name === 'input'
? `<br/><textarea style="width: 100%;">${hash}</textarea>`
: hash
el.className = className
el.innerHTML = `<br/><strong>${name}</strong>: ${value}`
return el
@devonwesley
devonwesley / compile.md
Last active January 12, 2018 00:27
Compiling contracts in the browser.
  1. Clone the repo:
$ git clone [email protected]:Jusdev89/Remix-Mini-Starter.git
  1. Inside of the mini_remix_stater
$ open index.html
@devonwesley
devonwesley / deploy.md
Created January 12, 2018 02:17
The deployment section of the app.
  1. Install the Ganache Blockchain:
$ npm install --global ganache-cli
  1. Get a Web3 instance:
if (typeof web3 !== 'undefined') {
@devonwesley
devonwesley / truffle.js
Created March 14, 2018 00:26
A config file for TruffleJS, this file will tell the TruffleJS tools what blockchain to work with in development.
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 8545,
network_id: "*",
}
}
}
@devonwesley
devonwesley / WalletLibrary.sol
Last active March 14, 2018 17:51
A mock WalletLibrary that has flaws DO NOT use for you real contract flow.
pragma solidity ^0.4.6;
contract WalletLibrary {
address owner;
function initWallet(address _owner) {
owner = _owner;
}
function changeOwner(address _newOwner) external {