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 / 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 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)
<div class="mui-col-md-6">
<div class="mui-panel">
<div id="account-addresses"></div>
</div>
</div>
@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>
@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 / 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 / RenderContract.js
Last active November 21, 2017 07:34
Code that is being used for a blog
function renderContractList() {
const contractListContainer = document.getElementById('contract-list')
const { contracts } = compiledContract
Object.keys(contracts).forEach((contract, index) => {
const label = `contract-id-${index}`
const gas = contracts[contract].gasEstimates.creation
createContractInfo(gas, contract, label, function(el){
contractListContainer.appendChild(el)
@devonwesley
devonwesley / ContractCompile.js
Last active November 21, 2017 07:58
Code snippet for Medium blog.
function addCompileEvent() {
const compileBtn = document.getElementById('contract-compile')
compileBtn.addEventListener('click', solcCompile)
}
function solcCompile() {
if (!compiler) return alert('Please select a compiler version.')
setCompileButtonState(true)
status("Compiling contract...")
@devonwesley
devonwesley / ContractInput.html
Last active November 21, 2017 08:02
Code snipper for blog
<div class="mui-row">
<div class="mui-col-md-6">
<div class="mui-panel">
<p style="font-size:25px; font-weight:bold">
Compile Contract
</p>
<textarea id="source" onclick="this.select()" style="height: 360px; width: 530px; display: block; margin-left: 20px;"></textarea>
<button id="contract-compile" class="mui-btn mui-btn--primary">
Compile
</button>
@devonwesley
devonwesley / DisplayCompilerVersions.js
Last active November 19, 2017 21:51
Code snippet for Solcjs and Web3JS blog
let compiler
window.onload = function () {
document.getElementById('versions').onchange = loadSolcVersion
if (!BrowserSolc) {
console.log('You have to load browser-solc.js in the page. We recommend using a <script> tag.')
throw new Error()
}