-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.js
44 lines (40 loc) · 912 Bytes
/
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
const path = require("path");
const fs = require("fs");
const solc = require("solc");
const lotteryPath = path.join(__dirname, "contracts", "MyContract.sol");
const source = fs.readFileSync(lotteryPath, "utf8");
var input = {
language: "Solidity",
sources: {
"MyContract.sol": {
content: `${source}`,
},
},
settings: {
optimizer: {
enabled: true,
},
evmVersion: "byzantium",
outputSelection: {
"*": {
"*": ["abi", "evm.bytecode.object"],
},
},
},
};
function findImports(_path) {
if (_path[0] === ".") {
return {
contents: fs.readFileSync(path.join(__dirname, _path)).toString(),
};
} else {
return {
contents: fs
.readFileSync(path.join(__dirname, "node_modules", _path))
.toString(),
};
}
}
module.exports = JSON.parse(
solc.compile(JSON.stringify(input), { import: findImports })
);