Conditional useContract() based on the useNetwork() activeChain #479
-
I'm trying to use the import { useContract, useNetwork } from 'wagmi';
import hardhatContractsJson from '../generated/hardhat_contracts.json';
export const useCustomContract = (): Contract | undefined => {
const { activeChain } = useNetwork();
const contractJson =
activeChain === undefined
? undefined
: (hardhatContractsJson as any)[activeChain.id][activeChain.name]['contracts']['CampaignFactory'];
const abi = contractJson ? contractJson['abi'] : undefined;
return useContract<CampaignFactory>({
addressOrName: contractJson ? contractJson['address'] : undefined,
contractInterface: abi,
});
} However, I guess I'm missing something, if anyone can give me a hand that would ve very much appreciated. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Definitely something that can be improved! In the meantime, you could try falling back to |
Beta Was this translation helpful? Give feedback.
Definitely something that can be improved! In the meantime, you could try falling back to
constants.AddressZero
from ethers foraddressOrName
.