Last active
November 19, 2017 21:51
-
-
Save devonwesley/415edc93d7911e5c9caabb06936cc1e2 to your computer and use it in GitHub Desktop.
Code snippet for Solcjs and Web3JS blog
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
} | |
status('Loading Compiler Versions...') | |
BrowserSolc.getVersions(function (soljsonSources, soljsonReleases) { | |
populateVersions(soljsonSources) | |
setVersion(soljsonReleases['0.4.18']) | |
loadSolcVersion() | |
}) | |
} | |
function loadSolcVersion() { | |
status(`Loading Solc: ${getVersion()}`) | |
BrowserSolc.loadVersion(getVersion(), function (c) { | |
status('Solc loaded.') | |
compiler = c | |
}) | |
} | |
function getVersion() { | |
return document.getElementById('versions').value | |
} | |
function setVersion(version) { | |
document.getElementById('versions').value = version | |
} | |
function populateVersions(versions) { | |
sel = document.getElementById('versions') | |
sel.innerHTML = '' | |
for (let i = 0; i < versions.length; i++) { | |
let opt = document.createElement('option') | |
opt.appendChild(document.createTextNode(versions[i])) | |
opt.value = versions[i] | |
sel.appendChild(opt) | |
} | |
} | |
function status(txt) { | |
document.getElementById('status').innerHTML = txt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment