1

I've got a getContract function that looks something like this.

const getContract = async () => {
    const provider = new ethers.providers.InfuraProvider(process.env.NETWORKS, process.env.ENDPOINT_KEY);
    let wallet = ethers.Wallet.fromMnemonic(process.env.MNEMONIC);

    const isReady = await provider.ready;
    

    if(isReady){
      wallet = wallet.connect(provider);
    
      const contractAddress = WakandaVotingPlatform.networks["4"].address;

      return new ethers.Contract(contractAddress, WakandaVotingPlatform.abi, wallet);   
    }

    console.log(isReady);
    
}

My goal is to check if provider is ready to do it's job, and if for some reason it's not (the internet is down) I want to return something else instead of the contract, but this just doesn't seem to work. What would be the proper way to handle such error.

1 Answer 1

0

maybe call a cheaper ethereum method.

provider.getNetwork();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.