46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
import solc from 'solc';
|
|
import fs from 'fs';
|
|
|
|
const source = fs.readFileSync('DurianUSDT.sol', 'utf8');
|
|
|
|
const input = {
|
|
language: 'Solidity',
|
|
sources: {
|
|
'DurianUSDT.sol': {
|
|
content: source
|
|
}
|
|
},
|
|
settings: {
|
|
optimizer: {
|
|
enabled: true,
|
|
runs: 200
|
|
},
|
|
evmVersion: 'paris', // Use paris to avoid PUSH0
|
|
outputSelection: {
|
|
'*': {
|
|
'*': ['abi', 'evm.bytecode']
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
const output = JSON.parse(solc.compile(JSON.stringify(input)));
|
|
|
|
if (output.errors) {
|
|
output.errors.forEach(err => {
|
|
console.log(err.formattedMessage);
|
|
});
|
|
}
|
|
|
|
const contract = output.contracts['DurianUSDT.sol']['DurianUSDT'];
|
|
const bytecode = contract.evm.bytecode.object;
|
|
const abi = contract.abi;
|
|
|
|
fs.mkdirSync('build', { recursive: true });
|
|
fs.writeFileSync('build/DurianUSDT.bin', bytecode);
|
|
fs.writeFileSync('build/DurianUSDT.abi', JSON.stringify(abi, null, 2));
|
|
|
|
console.log('Compiled successfully!');
|
|
console.log('Bytecode length:', bytecode.length);
|
|
console.log('ABI functions:', abi.filter(x => x.type === 'function').map(x => x.name).join(', '));
|