Cross-Chain Breeding — The Crazy Crows Chess Club
Hello, everyone! I am kingmaker.eth and I am the founder and co-creator of The Crazy Crows Chess Club. Throughout these Medium posts, I will attempt to share all of the functionality that this project has brought and will bring to the NFT industry. This particular post may get a little technical as we discuss some of the more complicated elements of our Smart Contracts. It’s part of my job to break things down so hopefully I can do that in a way that allows everyone to understand. With that, let’s begin!
The Crazy Crows Chess Club is an NFT project built on the Ethereum block-chain. We launched the project on August 15th, 2021. It sold out of it’s initial supply of 8,181 crows three days later. These crows are considered Generation 0 crows and they carry with them a number of utilities:
- Free Gold membership to chess.com
- Monthly profit-sharing via the Founder’s Token *
- Mad House breeding (Our burn mechanism) *
- Egg Breeding (Our DeFi component) *
- Access to secret channels for tournaments, treasure hunts, and airdrops *
* The main functionality of these all take place on the Polygon blockchain; This brings with it a number a benefits including being able to circumvent the high gas fees of the Ethereum blockchain.
I will write other posts on the first and second utility points. This post is dedicated to the cross-chain breeding.
First, let’s touch on the Mad House breeding.
Mad House Breeding
The Mad House is our burning mechanism. This means 2 crows go in, only 1 comes out. Each crow has eight traits:
When two crows are sent to the MadHouse.sol (a separate contract on Ethereum mainnet with no withdrawal function. See Fig 1), the mom’s most rare trait may be her eyes and the dad’s most rare may be his body, the new crow would have the eyes and body of the mom and dad respectively.
Our amazing smart contract developer has provided screenshots of some our smart contract logic to give an idea of what each function is doing. Here is an excerpt from our Breeder.sol contract:
This function sends the crows to the Mad House who becomes the new owner of the crows and they are there forever. There is no way to get them back once they are sent. Hence the title, “our burning mechanism”. WARNING: If you plan to use the Mad House to create a more rare crow, be careful because if it is a Gen 0 crow, which has all the aforementioned utility, you lose that utility because the new Gen 1 crow, will not have the same utility.
It then mints a new crow with no metadata (just think of a blank crow) and sends it to the caller of the function.
This is where the cross-chain action happens. The Ethereum mainnet Breeder.sol contract then sends a message to Polygon which tells EggCarton.sol (a separate contract on the Polygon mainnet) to find the traits of the new crow by using the parent’s rarest traits, and then uses Chainlink VRF to decide the other 6 traits, provably randomly. This is a big deal. Chainlink is amazing and allows us to bring trustless randomization to the creation of these new crows.
Let’s move over to Polygon and the EggCarton.sol contract. (Fig 3)
This function, _findTraits(), decodes the message from Ethereum mainnet that the Breeder.sol contract sent over, and stores it.
It then, using getRandomNumber(), calls Chainlink VRF to get a new random number that will be used to determine the random traits for the new crow.
Further down in EggCarton.sol we have findTraits() which will find the rarest traits of the parents and make sure they are carried over to the new crow.
Then, using the Chainlink Random Number, randomly find the other 6 traits of the new crow. This will then emit an event that announces the token id that has just had it’s metadata set.
The frontend (Fig 5) then makes a call to the Egg contract (another contract we’ll touch on further down) and pass the tokenID to getCrowMetaData() that will return an 8 number array where each number represents a trait.
At this point, we add the new metadata to our JSON array, stack all the image assets, pin that image to IPFS, and the new Gen 1 crow is ready to go! You’ll now be able to see your new, more rare Crazy Crow in your wallet.
Pretty neat right? The cross-chain functionality here is a first in the NFT space while making use of Chainlink VRF for true randomness.
This is our second breeding mechanic. That’s right, we have two cross-chain breeding mechanics. They’ll never say Crazy Crows didn’t push the limits!
This breeding mechanic combines NFT with the world of DeFi. With Egg Breeding, two crows produce an egg NFT on Polygon which can be staked in a DeFi yield farm and earn you passive income. While your egg is staked with one of our partners on Polygon, (along with as much or as little collateral as you want)* , it matures and after a minimum period of time (you can keep the egg there as long as you like) it will be ready to hatch. The longer you keep the egg staked, the higher chances that a more rare crow will hatch from it. Oh we use Chainlink VRF for that too. We know, it’s awesome.
Our first official partner is Gravity Finance. We can’t say enough nice things about these guys. They know their stuff and have been audited twice to ensure safety of funds and security of their smart contracts. We’re very happy to partner with them for our Egg Breeding.
* Note that the collateral will be dependent on what DeFi protocol the Nest is interacting with. For example, GFI/USDC. You would be able to get your funds and egg out at any time.
Here’s a helpful infographic that outlines the process:
Let’s jump into the technical stuff for Egg Breeding.
We’re now back to the Breeder.sol contract on Ethereum mainnet.
The first thing we check is if the mom and dad crows can breed. We have put in a number of preventative measures so people cannot go on a breeding spree and flood the market with new crows. One of the counter-measures is a cool down period.
We then check if Mating Season is active. This is a special time where the breeding cooldown is significantly shorter.
Once we go through all the checks, we then mint the new blank crow and we keep it in the Breeder.sol contract.
This contract then sends a message to Polygon telling it that a new egg has been made, and where to send it. This is denoted by the receiver variable input.
Take note that the receiver is an input so that in future, a Breeding Marketplace contract can match people willing to have their rare crows for breeding with people who want to pay to breed with rare crows. This is desirable because the resulting egg will mature faster in Nests.
Another point is Generation 0 crow owners can be financially rewarded for breeding even if they do not want to take part in the DeFi process. They can just put their crows up in the Breeding Market place.
** Yes we will be setting up a Breeding Marketplace where you can list your crows so that others can find special crows they want to breed with. **
Now over to Polygon again with our EggCarton.sol contract.
The contract decodes the message from Ethereum mainnet Breeder.sol contract. The Egg Carton will then mint an egg, record where the egg needs to be sent, and set the parents of the egg. We need to set the parents because they are used to calculate the egg bonus.
sendEggtoCaller() calculates the egg bonus for the egg based off the eggs parent’s rarity. The egg bonus will make the egg mature faster in nests so you can have the chance to get a more rare crazy crow by reaching double the maturity.
Then, it sends the egg to the rightful owner so they can deposit their egg into a Nest.
DeFi Nests — SUPER SECRET
Eventually, eggs fully mature and will become hatchable. Still in the EggCarton.sol contract we have the hatchEgg() function.
The caller can now hatch their egg, which asks Chainlink VRF (told ya you’d see Chainlink’s magic again!) for another random number which will be used to randomly assign all the new crow’s traits.
We then call the sendHatchedEggToMainnet() function. The random number supplied by Chainlink is used to determine the traits of the new crow.
This function also checks to see if the egg participated in a Special Event. If it did, it will assign special event traits, IF the RNG lines up.
What’s a Special Event?
A special event is an event put on by Crazy Crows Chess Club or any of it’s partners where a crow has the ability to receive a trait that is exclusive to that event. For example, if the Egg Participates in the IDO or launch of a new project or a special event from an existing project, (an example, Gravity Finance launching an IDO from their launchpad or a Kongz event where you need to stake to earn rewards), it can gain a special trait like a Gravity Hat or a Kongz tshirt. This would make the crow that hatches very rare as not all eggs will gain these special event traits.
sendHatchedEggToMainnet() then burns the egg and sends a message back to Ethereum mainnet saying who burned the egg and the tokenID of said burned egg.
Back to Ethereum mainnet and Breeder.sol.
_processMessageFromChild() — kind of sounds like a dystopian future where an AI is getting a message from it’s child — will then decode the message from the Egg Carton on Polygon and send the caller address the brand new Crazy Crow with the same token ID as the one that was just hatched on Polygon.
Then BOOM, the new crow with randomly assigned traits via Chainlink VRF is sent to the user’s wallet.
This has been a basic overview of the Crazy Crows Chess Club’s two cross-chain breeding mechanics. Pretty exciting stuff right? I hope I was able to appeal to the non-tech and tech crowd alike with this breakdown.
Stay tuned for more. All we’re waiting on to launch this is the Polygon mapping requests and once they have been granted, we will conduct our final tests and bring these online. Mad House will be brought online first, followed shortly by Egg Breeding.
Any questions or comments, feel free to reach out to me on Discord anytime. kingmaker#7777