-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextract-abi.js
35 lines (29 loc) · 926 Bytes
/
extract-abi.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
32
33
34
35
const fs = require("fs");
const dirName = "./build/contracts/";
const abiDirName = dirName + 'abi/';
const binDirName = dirName + 'bin/';
fs.readdir(dirName, (err, fileNames) => {
if (err) throw err;
try {
fs.mkdirSync(abiDirName);
} catch (e) {
}
try {
fs.mkdirSync(binDirName);
} catch (e) {
}
for (const fileName of fileNames) {
if (fileName.split('.')[1] === "json") {
fs.readFile(dirName + fileName, 'utf-8', (err, content) => {
if (err) throw err;
// parse contract
const contract = JSON.parse(content);
const abiFileName = fileName.split(".")[0] + "." + "abi";
const binFileName = fileName.split(".")[0] + "." + "bin";
// stringify abi and write to file
fs.writeFileSync(abiDirName + abiFileName, JSON.stringify(contract.abi));
fs.writeFileSync(binDirName + binFileName, contract.bytecode);
});
}
}
});