-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestCompile.js
More file actions
64 lines (58 loc) · 1.66 KB
/
testCompile.js
File metadata and controls
64 lines (58 loc) · 1.66 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
57
58
59
60
61
62
63
64
const solc = require('solc');
const { ethers } = require('hardhat');
const { ContractFactory } = ethers;
const fs = require('fs');
/**
* @var content Buffer
* @return [byteCode, ABI]
*/
const compile = (fileBuf, name) => {
// const [Token, SafeMath, Timelock, GovernorAlpha] = files;
const input = {
language: 'Solidity',
sources: {
'contract.sol': {
content: fileBuf
}
},
settings: {
outputSelection: {
'*': {
'*': ['*']
}
}
}
};
const compileResult = solc.compile(JSON.stringify(input), { import: findImports });
const output = JSON.parse(compileResult);
// if (output.errors) {
// console.error(output.errors);
// throw 'compilation error!!';
// }
console.log(output);
// process.exit(0);
// return [
// output.contracts['contract.sol'][name].abi,
// output.contracts['contract.sol'][name].evm.bytecode
// ];
};
const findImports = path => {
if (path === 'Token.sol') {
const fileBuf = fs.readFileSync('contracts/Token.sol');
return {
contents: fileBuf.toString('utf8')
};
}
return { error: 'File not found' };
}
(async() => {
// const { hasQuadraticVoting, name: daoName, owner, tokenCap, tokenName } = req.body;
const fileBuf = fs.readFileSync('contracts/GovernorAlpha.sol');
compile(fileBuf.toString('utf8'), 'Token');
// const [abi, byteCode] = compile(fileBuf.toString('utf8'), 'GovernorAlpha');
// console.log(abi, 'abi');
// console.log(byteCode, 'byteCode');
// const Factory = new ContractFactory(abi, byteCode);
// const contract = await Greeter.deploy('hello');
// console.log(contract, contract.address);
})();