-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
31 lines (27 loc) · 756 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
const path = require('path');
const fs = require('fs');
const solc = require('solc'); // solidity compiler
// get the absolute path of .sol file (contract source code)
const inboxPath = path.resolve(__dirname, 'contracts', 'Inbox.sol');
// read the contract source code
const source = fs.readFileSync(inboxPath, 'utf8');
// compile with solc - JSON-input-output interface (ABI)
const input = {
language: 'Solidity',
sources: {
'Inbox.sol': {
content: source,
},
},
settings: {
outputSelection: {
'*': {
'*': ['*'],
},
},
},
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
// console.log(output);
// export compiled source code
module.exports = output.contracts['Inbox.sol'].Inbox;