-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgulpfile.js
More file actions
25 lines (23 loc) · 856 Bytes
/
Copy pathgulpfile.js
File metadata and controls
25 lines (23 loc) · 856 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const gulp = require('gulp');
const solc = require('solc');
const fs = require('fs');
const contractName = 'ChuckETHCheese';
const contractFileName = `${contractName}.sol`;
gulp.task('compile', function(done) {
const input = fs.readFileSync(`./${contractFileName}`).toString();
const output = solc.compile({ sources: { [contractFileName]: input} }, 1);
if(output.errors) {
console.log(output.errors);
done();
}
else {
const myContract = output.contracts[`${contractFileName}:${contractName}`];
const abi = JSON.parse(myContract.interface);
const bytecode = myContract.bytecode;
const fileOutput = { abi, bytecode };
fs.writeFile(`./${contractName}.json`, JSON.stringify(fileOutput, null, 4), done);
}
})
gulp.task('watch', function() {
return gulp.watch(`./${contractFileName}`, () => gulp.start('compile'));
})