-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
48 lines (39 loc) · 1.25 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
48
// To work with files and folders
const path = require("path");
// File system methods
const fs = require("fs-extra");
// Solidity compiler
const solc = require("solc");
// Clean up the build folder
const buildPath = path.resolve(__dirname, "build");
fs.removeSync(buildPath);
// Get the path where is located the contract
const contractPath = path.resolve(__dirname, "contracts", "Greetings.sol");
// Read the abi and the bytecode from the contract
const params = {
language: "Solidity",
sources: {
"contract": {
content: fs.readFileSync(contractPath, 'utf-8')
}
},
settings: {
outputSelection: {
"*": {
"*": ["abi", "evm.bytecode"]
}
}
}
};
// Compile the contract and returns its object
const output = JSON.parse(solc.compile(JSON.stringify(params)));
// Use or create the build folder
fs.ensureDirSync(buildPath);
// Create the JSON file and store the contract's object
fs.outputJsonSync(
path.resolve(buildPath, "Greetings.json"),
output.contracts.contract.Greetings
);
// Export greetings contract
module.exports.interface = output.contracts.contract.Greetings.abi;
module.exports.bytecode = output.contracts.contract.Greetings.evm.bytecode.object;