@filfox/fnsjs
Version:
Library For FNS
29 lines (28 loc) • 1.02 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useContract = void 0;
const ethers_1 = require("ethers");
const abi_1 = __importDefault(require("../abi"));
const constant_1 = require("../constant");
const contract = {
FixedPriceOracle: null,
FNSRegistry: null,
Multicall: null,
PublicResolver: null,
Registrar: null,
RegistrarController: null,
ReverseRegistrar: null
};
function useContract(name, signerOrProvider, network) {
if (!(name in contract))
throw new TypeError('Non-existent contract name');
const c = contract[name];
if (!c || c.provider !== signerOrProvider) {
contract[name] = new ethers_1.ethers.Contract((0, constant_1.getNetwork)(network).contractAddress[name], abi_1.default[name], signerOrProvider);
}
return contract[name];
}
exports.useContract = useContract;