-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractABI.ts
36 lines (31 loc) · 1 KB
/
extractABI.ts
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
import fs from 'fs'
const extractAbi = async () => {
const mainFolder = "artifacts/contracts/";
fs.readdirSync(mainFolder).forEach((folder) => {
if (folder.includes(".sol")) {
const absolutePath = mainFolder + folder + "/";
fs.readdirSync(absolutePath).forEach((file: any) => {
if (!file.includes(".dbg.json")) {
const finalPath = absolutePath + file;
const parentDirectory = __dirname.substr(
0,
__dirname.lastIndexOf("/")
);
const abiFolder = parentDirectory + "/abis";
try {
if (!fs.existsSync(abiFolder)) {
fs.mkdirSync(abiFolder);
}
} catch (err) {
console.error(err);
}
let data: any = fs.readFileSync(finalPath);
fs.writeFileSync(
`abis/${file}`,
JSON.stringify(JSON.parse(data).abi)
);
}
});
}
});
};