28 lines
892 B
JavaScript
28 lines
892 B
JavaScript
const fs = require('fs');
|
|
/**
|
|
* contract=activity/TokenClaim.sol npx hardhat run scripts/convert-abi.js
|
|
*/
|
|
async function main() {
|
|
|
|
let pathPart = process.env.contract
|
|
if (!pathPart) {
|
|
console.error('\x1b[31m%s\x1b[0m', "contract path is required")
|
|
console.log('\x1b[33m%s\x1b[0m', "use: contract=subfolder/contract_name.sol npx hardhat run scripts/convert-abi.js")
|
|
process.exit(1)
|
|
}
|
|
if (!pathPart.endsWith(".sol")) {
|
|
pathPart = pathPart + ".sol"
|
|
}
|
|
const filename = pathPart.split("/").pop()
|
|
const abiPath = `../artifacts/contracts/${pathPart}/${filename.replace(".sol", ".json")}`
|
|
|
|
const jsonAbi = require(abiPath).abi;
|
|
|
|
const iface = new ethers.Interface(jsonAbi);
|
|
fs.writeFileSync(`./simple_abi/${filename.replace(".sol", ".json")}`, JSON.stringify(iface.format(true)));
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
}); |