How to use Infura API Project ID with Keeper Autotask?

Hi @spalladino

Thanks for your input and I think I know what you mean. So I’m trying to get the code to use my own API and while the code runs, I suspect it is still using the shared keys because I still get the same occasional errors as before. I commented out the original and replaced the provider definition to what I have below. Do you mind taking a look to see if there is anything wrong? network has been defined as “homestead”. Thanks

  const provider = ethers.getDefaultProvider(network, {
    infura: {
  		projectId:'xxxxMYPROJECTIDxxxx',
        projectSecret:'XXXXXXXXXXXXXX',
    	} 

[EDIT @abcoathup] Moved from: Keep3r Autotask errored with "INVALID_ARGUMENT","reason":"invalid ENS name"

3 Likes

getDefaultProvider use FallBackProvider which requires quorum of all providers (INFURA, Etherscan amd Nodesmith). Since you are providing keys only for Infura, it fails to call other providers because they are also rate limited. To avoid this issue use InfuraProvider directly or supply keys for other providers as well.

From FallbackProvider docs:

A result is not returned until at least quorum (by weight) providers have agreed on the same value.
By default the weight for each provider is 1 (any must be a positive integer) and the length of array of weights (if specified) must match the length of the arrray of providers.

An example of using only Infura:

 // Connect to mainnet with a Project ID and Project Secret
  provider = new InfuraProvider('homestead', {
    projectId: yourProjectId,
    projectSecret: yourProjectSecret,
  });
2 Likes

something like that @ylv-io?

exports.handler = async function(credentials) {
  const provider = ethers.getDefaultProvider("mainnet", { 
  etherscan: ETHERSCAN,
  alchemy: ALCHEMY,
  infura: {
    projectId: INFURA_PROJECT_ID,
    projectSecret: INFURA_PROJECT_SECRET,
    },
  });
  const signer = new DefenderRelaySigner(credentials, provider, { speed: 'fastest' });
  return await main(signer, Jobs, RegistryAddress);
}
2 Likes

Yes, if you want to use all the providers. If you want to use only Infura, checkout the example below.

Here is the code of the handler function:

// Entrypoint for the Autotask
exports.handler = async function (credentials) {
  // Connect to mainnet with a Project ID and Project Secret
  provider = new ethers.providers.InfuraProvider('homestead', {
    projectId: yourProjectId,
    projectSecret: yourProjectSecret,
  });
  const signer = new DefenderRelaySigner(credentials, provider, { speed: 'fastest' });
  return await main(signer, Jobs, RegistryAddress);
};

I hope it helps. Let me know if there are any other questions left.

2 Likes

oh got it now.

instead of getDefaultProvider . I should use InfuraProvider if I want to user Infura

2 Likes

instead of getDefaultProvider . I should use InfuraProvider if I want to user Infura

If you want to use only Infura.

1 Like

ok but should we use 3 provides or one? Do we need to use all providers?

2 Likes

Multiple providers are used to prevent a malicious node from fooling your code. Ethers.js would compare results from different providers and only if they match it will send a tx.
Considering above, Keepers run jobs for other projects which are secure to run by anyone, meaning they don’t trust Keeper in anyway or take any input from them, based on that I would say it is fine to run with only one provider in that case.

2 Likes

@ylv-io ty for the clarification

1 Like