-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
47 lines (39 loc) · 1.1 KB
/
compile.js
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
const path = require('path');
const solc = require('solc');
const fs = require('fs-extra');
const buildPath = path.resolve(__dirname, 'build');
fs.removeSync(buildPath);
const campaignPath = path.resolve(__dirname, 'contracts', 'Campaign.sol');
const source = fs.readFileSync(campaignPath, 'utf8');
var input = {
language: 'Solidity',
sources: {
'Campaign.sol': {
content: source
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
const contractMap = output.contracts['Campaign.sol'];
fs.ensureDirSync(buildPath);
for (let contractName in contractMap) {
console.log(`Building contract ${contractName}...`);
const contract = contractMap[contractName];
const abi = contract.abi;
const bytecode = contract.evm.bytecode.object;
fs.outputJSONSync(
path.resolve(buildPath, `${contractName}.json`),
{
abi,
bytecode,
}
);
console.log(`Built contract ${contractName}!`);
}