forked from Motus-DAO/RootAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompile.cjs
More file actions
38 lines (31 loc) · 1.22 KB
/
compile.cjs
File metadata and controls
38 lines (31 loc) · 1.22 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
const solc = require('solc');
const fs = require('fs');
const path = require('path');
const source = fs.readFileSync(path.join(__dirname, 'contracts/PsyEscrow.sol'), 'utf8');
const input = {
language: 'Solidity',
sources: { 'PsyEscrow.sol': { content: source } },
settings: {
optimizer: { enabled: true, runs: 200 },
outputSelection: { '*': { '*': ['abi', 'evm.bytecode.object'] } },
},
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));
if (output.errors) {
const errors = output.errors.filter(e => e.severity === 'error');
if (errors.length) {
console.error('Compilation errors:');
errors.forEach(e => console.error(e.formattedMessage));
process.exit(1);
}
output.errors.forEach(e => console.warn(e.formattedMessage));
}
const contract = output.contracts['PsyEscrow.sol']['PsyEscrow'];
const abi = contract.abi;
const bytecode = '0x' + contract.evm.bytecode.object;
// Write artifacts
fs.mkdirSync('artifacts', { recursive: true });
fs.writeFileSync('artifacts/PsyEscrow.json', JSON.stringify({ abi, bytecode }, null, 2));
console.log('ABI entries:', abi.length);
console.log('Bytecode size:', (bytecode.length / 2 - 1), 'bytes');
console.log('Artifact written to artifacts/PsyEscrow.json');