Enabling automated NFT lotteries with Chainlink Keepers and VRF

What is CZodiac?

We are known as the Global DeFi Bank on Binance Smart Chain. CZodiac issues lifetime passive rewards to NFT holders, a farming/staking platform, and a high-interest stabletoken all wrapped into one ecosystem.

How CZodiac uses Chainlink Keepers

We are using the term ‘VRF sandwich’ because the Lucky Rabbit contract uses TWO Chainlink Keepers Upkeeps with Chainlink VRF in between! ‘Keepers 1’ will watch and track the amount of CZUSD locked in liquidity via LRT burns, raising the price floor. When a certain amount is locked, it will initiate VRF and send a random number to ‘Keepers 2’ which will perform the minting/buying of a Rabbit NFT and then airdrop it to the random winner.

What is the VRF Sandwich feature?

The VRF sandwich separates the keeper into two parts around a central call to Chainlink VRF. The first keeper triggers the VRF function. Then to save gas and stay under the gas limit, the second keeper fires a second performUpkeep to distribute the NFT via lottery. This method reduces the gas cost while ensuring a safe and fun lottery game.

How CZodiac DeFi Bank integrated Chainlink Keepers

We used the documentation on Chainlink’s website which included great details on the specific process for implementation. All our contracts are developed and tested using hardhat, so adding the Keepers interface and VRF mock was as simple as adding Chainlink’s package to our repository using Yarn. Then we wrote the contracts in solidity inheriting from Chainlink’s interfaces. Testing was done in hardhat using mocks provided by the package.

Creating our Keepers-compatible contract

checkUpkeep Function: Runs off-chain at every block to determine if the performUpkeep function should be called on-chain.

After writing our Keepers-compatible contract, we simply registered on the Chainlink Keepers app by following the tutorial here.

Advice for other developers integrating Chainlink Keepers

An important item to consider is whether your call to checkUpkeep is under the gas limit set by Chainlink. There’s a limit to the amount of computation checkUpkeep can do, so make sure your design is under that limit.

Results from the integration

The LRT performed quite well and had a positive reception from our community. Without the Chainlink integration, the dev team would need to constantly monitor the contract to call the performUpkeep manually. The Chainlink integration reduced a major headache for our dev team saving an estimated 150 to 180 hours a year. It also meant that our community would get their Rabbit NFT airdrops immediately instead of waiting for the dev to wake up.

Why CZodiac chose Chainlink Keepers

There are many things worth noting that the automation of Keepers can benefit. Our ecosystem is becoming deeper and more enriched every day, and that calls for more transparent and trustless systems. Chainlink Keepers fills that need for Web3 developers.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CZodiac DeFi Bank

CZodiac DeFi Bank

CZodiac uses POL game theory to develop novel Defi 2.0 technologies that protect farmers and stakers.