diff --git a/lib/compiler.js b/lib/compiler.js index fddcd6b7..60acd74b 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -13,25 +13,25 @@ Compiler.prototype.init = function(env) { }; Compiler.prototype.compile_solidity = function(contractFile) { - var source = fs.readFileSync(contractFile).toString(); - var output = solc.compile(source, 1); + var cmd, result, output, version, json, compiled_object; - if(output.errors && output.errors.length>0){ - throw new Error(output.errors[0]); - } + cmd = "solc --input-file " + contractFile + " --combined-json bin,abi"; - var json = output.contracts; + result = exec(cmd, {silent: true}); + output = result.output; - compiled_object = {} + json = JSON.parse(output).contracts; - for (var className in json) { - var contract = json[className]; - - compiled_object[className] = {}; - compiled_object[className].code = contract.bytecode; - compiled_object[className].info = {}; - compiled_object[className].info.abiDefinition = JSON.parse(contract.interface); - } + compiled_object = {} + + for (var className in json) { + var contract = json[className]; + + compiled_object[className] = {}; + compiled_object[className].code = contract.binary || contract.bin; + compiled_object[className].info = {}; + compiled_object[className].info.abiDefinition = JSON.parse(contract["abi"] || contract["json-abi"]); + } return compiled_object; };