Skip to content

Instantly share code, notes, and snippets.

@sponnet
Created July 12, 2016 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sponnet/5919544b7253517aa9cf1919531807b8 to your computer and use it in GitHub Desktop.
Save sponnet/5919544b7253517aa9cf1919531807b8 to your computer and use it in GitHub Desktop.
compile solidity files gulp task
gulp.task('solc', function() {
glob([
'app/contracts/*.sol',
], {
cwd: '.'
}, function(error, files) {
var allfiles = '';
var destpath = '';
files.forEach(function(file) {
console.log('compiling sol file', file);
var fileContent = fs.readFileSync(file, "utf8");
allfiles += fileContent;
destpath = require('path').dirname(file);
});
// save combined SOL file for later reference
var combinedFileName = destpath + '/tmp_combined.txt';
fs.writeFile(combinedFileName, allfiles, 'utf8');
var solc = require('solc');
var input = allfiles;
var output = solc.compile(input, 1); // 1 activates the optimiser
//console.log(output);
for (var contractName in output.contracts) {
var data = {
bytecode: output.contracts[contractName].bytecode,
abi: JSON.parse(output.contracts[contractName].interface)
}
var outputFileName = destpath + '/' + contractName + ".json";
console.log('saving to', outputFileName);
fs.writeFile(outputFileName, JSON.stringify(data), 'utf8');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment