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 / ContractDetails.js
Last active November 20, 2017 18:34
This feature shows the contract details.
function renderContractDetails(name, contract) {
const modalEl = document.createElement('div')
modalEl.style.width = '700px';
modalEl.style.margin = '100px auto';
modalEl.style.padding = '50px';
modalEl.style.backgroundColor = '#fff';
modalEl.appendChild(renderContractInfo(name, contract))
mui.overlay('on', modalEl);
}
@devonwesley
devonwesley / Web3JS.js
Created November 15, 2017 00:01
Using this to show how to instantiate the web3 object.
if (typeof web3 !== 'undefined') {
web3 = new Web3(web3.currentProvider)
} else {
// set the provider you want from Web3.providers
web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
}
@devonwesley
devonwesley / Account.js
Last active December 20, 2017 02:22
This snippet of code is for the blog series that i am writing.
function getAccounts() {
const ethAccount = web3.eth.accounts[0]
return document
.getElementById('account-addresses')
.innerHTML = `<div>
Account: ${ethAccount}
<br />
Balance: ${balanceInEth(ethAccount)}
</div>
<div class="mui-col-md-6">
<div class="mui-panel">
<div id="account-addresses"></div>
</div>
</div>
function renderContractList() {
const contractListContainer = document.getElementById('contract-list')
const { contracts } = compiledContract
Object.keys(contracts).forEach((contract, index) => {
const label = `contract-id-${contract}-${Math.random()}`
const gas = contracts[contract].gasEstimates.creation
createContractInfo(gas, contract, label, function (el) {
contractListContainer.appendChild(el)
@devonwesley
devonwesley / DeployContractEvent.js
Last active December 20, 2017 02:23
Function for blog series
function deployContractEvent(name, contract) {
const comfirmMsg = `
Contract: ${name.substring(1)}
Network: ${currentNetwork()}
Confirm to deploy with these settings.
`
if (!confirm(comfirmMsg)) return
const { bytecode, interface } = contract
function renderContract(contract, contractName) {
status(`Contract Deployed...`)
const { transactionHash, address } = contract
web3.eth.getTransaction(transactionHash, (err, transaction) => {
if (!err) {
const props = { ...transaction, ...contract, }
const details = {
blockNumber: transaction.blockNumber,
contractName,
@devonwesley
devonwesley / newContractCallback.js
Last active December 20, 2017 02:25
Code snippet of a callback for a contract being deployed.
function newContractCallback(name) {
return (err, contract) => {
getAccounts()
if (!err) {
!contract.address
? status(`Deploying contract..`)
: renderContract(contract, name)
}
}
}
@devonwesley
devonwesley / currentNetwork.js
Last active December 20, 2017 02:24
A code snippet that checks which ethereum network your on.
function currentNetwork() {
const network = web3.eth.getBlock(0).hash
const main = '0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3'
const test = '0x41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d'
switch (network) {
case main:
return 'Main Net'
case test:
return 'Ropsten Network'
@devonwesley
devonwesley / CreateContractPanel.js
Last active December 20, 2017 02:26
Creates a Container for smart contract info inside of the UI.
function createContractPanel(contract, callback) {
const div = document.createElement('DIV')
div.className = 'mui-panel'
div.innerHTML = `
<h3>
<strong>Contract: </strong>
${contract.contractName}
</h3>
<p>
<strong>Block Number: </strong>