-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.js
More file actions
56 lines (49 loc) · 1.5 KB
/
Copy pathcompile.js
File metadata and controls
56 lines (49 loc) · 1.5 KB
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
49
50
51
52
53
54
55
56
const solc = require('solc');
const fs = require('fs');
const path = require('path');
const contractPath = path.join(__dirname, 'contracts', 'ArcEscrow.sol');
const source = fs.readFileSync(contractPath, 'utf8');
const input = {
language: 'Solidity',
sources: {
'ArcEscrow.sol': { content: source }
},
settings: {
outputSelection: {
'*': {
'*': ['abi', 'evm.bytecode.object', 'evm.deployedBytecode.object']
}
},
optimizer: { enabled: true, runs: 200 }
}
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
let hasError = false;
if (output.errors) {
for (const err of output.errors) {
if (err.severity === 'error') {
hasError = true;
console.error('ERROR:', err.formattedMessage);
} else {
console.warn('WARNING:', err.formattedMessage);
}
}
}
if (hasError) {
console.error('\nCompilation FAILED.');
process.exit(1);
}
const contract = output.contracts['ArcEscrow.sol']['ArcEscrow'];
console.log('\nCompilation SUCCEEDED.');
console.log('Bytecode size (deployed):', contract.evm.deployedBytecode.object.length / 2, 'bytes');
console.log('Number of ABI entries:', contract.abi.length);
// Write artifacts for later use (deploy script, frontend ABI)
fs.writeFileSync(
path.join(__dirname, 'ArcEscrow.abi.json'),
JSON.stringify(contract.abi, null, 2)
);
fs.writeFileSync(
path.join(__dirname, 'ArcEscrow.bytecode.txt'),
'0x' + contract.evm.bytecode.object
);
console.log('\nWrote ArcEscrow.abi.json and ArcEscrow.bytecode.txt');