UNPKG

@ajna-finance/sdk

Version:

A typescript SDK that can be used to create Dapps in Ajna ecosystem.

39 lines 1.76 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.decodeErrors = void 0; exports.getCustomErrorsFromContract = getCustomErrorsFromContract; const tslib_1 = require("tslib"); const dotenv_1 = tslib_1.__importDefault(require("dotenv")); const constants_1 = require("../constants"); const ethers_1 = require("ethers"); const grant_fund_1 = require("../contracts/grant-fund"); /** * Iterate through each contract, decoding error hashes. * Ensure environment is configured (to any chain) before running. */ const decodeErrors = function () { dotenv_1.default.config(); const provider = new ethers_1.providers.JsonRpcProvider(process.env.ETH_RPC_URL); // TODO: load interface directly from ABI so we don't need a provider constants_1.Config.fromEnvironment(); // TODO: decode errors from other contracts, label them in stdout getCustomErrorsFromContract((0, grant_fund_1.getGrantsFundContract)(provider)); }; exports.decodeErrors = decodeErrors; /** * print error hashes for a single contract * @param contract identifies the contract for which error hashes are desired */ function getCustomErrorsFromContract(contract) { // retrieve the list of custom errors available to the contract const customErrorNames = Object.keys(contract.interface.errors); // index the contract's errors by the first 8 bytes of their hash const errorsByHash = customErrorNames.reduce((acc, name) => { return Object.assign(Object.assign({}, acc), { [contract.interface.getSighash(name)]: name }); }, {}); for (const errorHash in errorsByHash) { // TODO: format into table or CSV console.log(errorsByHash[errorHash], errorHash); } } //# sourceMappingURL=decode-errors.js.map