I'm playing around with Chainlink's "Register an Upkeep using your own deployed contract" example: https://docs.chain.link/docs/chainlink-keepers/register-upkeep/#register-an-upkeep-using-your-own-deployed-contract

However, once the UpkeepIDConsumerExample is deployed with the Link Token Contact, Registry and Registrar parameters for the respective chain, I am unable to use the UpkeepIDConsumerExample.registerAndPredictID function as it fails.

(Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Internal JSON-RPC error. { "code": -32000, "message": "execution reverted" })

I've tried on Rinkeby, Mumbai and Polygon Mainnet, incase testnets weren't live yet. And I've used the parameters suggested by the docs for calling the function. And I have sufficient Link in my metamask.

Is it correct to use these: https://docs.chain.link/docs/link-token-contracts/ as the Link Token Interfrace parameter?

Thanks!

1

There are 1 best solutions below

3
On BEST ANSWER

I was able to make this work (though I tried only on Goerli)using the code from the offical docs that you linked to.

For the benefit of others that read this post, I will break it down into detailed steps - perhaps more than you needed for an answer!

Prerequisites

  1. Get some LINK tokens in your browser wallet
  2. Deploy a Chainlink Keepers-compatible contract -- this is your Upkeep contract; the one that will be automated. Here is the example Upkeep smart contract that you can copy and deploy right away. You can use 10 as the interval -- that's 10 seconds. This way you can see the upkeep happen fast. Note this Upkeep's address
  3. Next, deploy the UpkeepIDConsumerExample from the example in the docs, which is the smart contract that programmatically registers your Upkeep Contract. This contract handles registering the Upkeep Contract you deployed in Step #2 with Chainlink's Keepers network, so that the Keepers Network can automate the running of functions in your Upkeep contract. Note this Contracts Address

Making it work

  1. From your wallet, which should now have LINK in it, send 5 LINK to the deployed UpkeepIDConsumerExample address. This is funding it will need to send onwards to your Upkeep (Upkeeps need funding so they can pay the Keepers Network for the compute work they do in performing the automations).

  2. Using Remix, connect to the right network and then connect to your deployed UpkeepIDConsumerExample contract by using its address.

  3. When Remix shows your contract and its interactions in the DEPLOYED CONTRACTS section of the UI, fill in the parameters for the registerAndPredictID() function using this table in the docs.

    While following the table referred to above, please note:

    • upkeepContract is the Upkeep Contracts address - the one you deployed in Step 2 in Prerequisites
    • gasLimit - I used 3000000
    • adminAddress - this can just be your wallet address. The one that you're deployed from, sending LINK from etc.
    • Amount - 5 LINK expressed in Juels (LINK's equivalent of Wei), so 5000000000000000000
    • Sender - this is the UpkeepIDConsumerExample's address. In this example it's the calling contract itself.
  4. run registerAndPredictID() with the params as per the previous step. It should run successfully.

  5. Verify by going to the Keepers App and checking under "My Upkeeps" for a new Upkeep that you just programmatically created.

Cleanup

  1. In the Keepers App note the LINK balance of the Upkeep you just created and funded with the 5 LINK -- it may be a bit less than the 5 LINK you sent it because the keepers network may have already run your Upkeep - we had set the interval for 10 seconds in Step 2 of Prerequisites.
  2. And on Etherscan check whether UpkeepIDConsumerExample has any LINK in it (it shouldn't because the 5 LINK you sent from your wallet to this contract, was transferred when you ran registerAndPredictID() and sent an amount of 5 LINK

Hope this helps!