@filfox/fnsjs
Version:
Library For FNS
22 lines (21 loc) • 683 B
JavaScript
import { ethers } from 'ethers';
import abi from '../abi';
import { getNetwork } from '../constant';
const contract = {
FixedPriceOracle: null,
FNSRegistry: null,
Multicall: null,
PublicResolver: null,
Registrar: null,
RegistrarController: null,
ReverseRegistrar: null
};
export 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.Contract(getNetwork(network).contractAddress[name], abi[name], signerOrProvider);
}
return contract[name];
}