diff --git a/README.md b/README.md index 921f73d5bc..7f45f27c02 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,12 @@ Starting from version 0.1.6, multiple files are supported with automatic import console.log(contractName + ': ' + output.contracts[contractName].bytecode); Note that all input files that are imported have to be supplied, the compiler will not load any additional files on its own. + +###Using a legacy version + +In order to allow compiling contracts using a specific version of solidity, the `solc.setVersion` method is available. + + var solc = require('solc'); + solc.setVersion( 'latest' ); // this is used by default + solc.setVersion( 'v0.1.1-2015-08-04-6ff4cd6' ); + var output = solc.compile( "contract t { function g() {} }", 1 ); diff --git a/index.js b/index.js index 2e3e2552c7..7e2988bb75 100644 --- a/index.js +++ b/index.js @@ -1,23 +1,30 @@ -var soljson = require('./bin/soljson-latest.js'); +function setupMethods (soljson){ -var compileJSON = soljson.cwrap("compileJSON", "string", ["string", "number"]); -var compileJSONMulti = - '_compileJSONMulti' in soljson ? - soljson.cwrap("compileJSONMulti", "string", ["string", "number"]) : - null; + var compileJSON = soljson.cwrap("compileJSON", "string", ["string", "number"]); + var compileJSONMulti = + '_compileJSONMulti' in soljson ? + soljson.cwrap("compileJSONMulti", "string", ["string", "number"]) : + null; -var compile = function(input, optimise) { - var result = ''; - if (typeof(input) != typeof('') && compileJSONMulti !== null) - result = compileJSONMulti(JSON.stringify(input), optimise); - else - result = compileJSON(input, optimise); - return JSON.parse(result); -} + var compile = function(input, optimise) { + var result = ''; + if (typeof(input) != typeof('') && compileJSONMulti !== null) + result = compileJSONMulti(JSON.stringify(input), optimise); + else + result = compileJSON(input, optimise); + return JSON.parse(result); + } + var version = soljson.cwrap("version", "string", []); -module.exports = { - compile: compile, - version: soljson.cwrap("version", "string", []) + return { + version: version, + compile: compile, + useVersion: function( versionString ){ + return setupMethods( require('./bin/soljson-' + versionString + '.js' ) ); + } + } } + +module.exports = setupMethods( require('./bin/soljson-latest.js') );