Learn What Are Cryptokitties? The Most Comprehensive Guide Written
What Are Cryptokitties? Crash Course.Over the last year or so DAPPs aka Decentralised Applications have slowly gained a lot of steam.
As you are probably aware of, a DAPP is not owned by any central organization and it represents a much-needed paradigm shift in an increasingly centralized world.
However, for DAPPs to get the proper mainstream exposure they deserve, one of them had to break through and make it big. (Yes technically speaking Bitcoin is a DAPP as well, but we are not talking about store-of-value here). Sure, there have been several DAPPs before which got some exposure but something had to make it big and capture the public’s imagination.
Image Credit: Cryptokitties
What are Cryptokitties?
Cryptokitties is a blockchain-based virtual game that allows players to adopt, raise, and trade virtual cats. The game was made by Vancouver based blockchain company Axiom Zen. However, what is truly important to remember is that this is the first known application of DAPP for leisure and recreation.
Sales of Cryptokitties have been through the roof. People have spent more than twelve million dollars buying these cryptokitties. There are even reports of people who have made more money trading cyptokitties than investing in their IRA!
Let’s look at how many sales have been made per day:
Image Credit: KittyExplorer
Several articles have been written about the “kitty phenomena” and they have received significant mainstream exposure as well. In fact, even Vitalik has gotten in on the act!
Image Credit: Vitalik Buterin Twitter
Each kitty has its own unique 256-bit unique genome code. Which is carried down to all its descendent kitties via the use of Genetic Algorithm.
What is Genetic Algorithm?
The genetic algorithm is an optimization technique used to solve nonlinear optimization problems. It works pretty much the way biological genetics works. It starts with an initial generation of candidate solutions that have been tested against the objective function. The algorithm then generates subsequent solutions from these parent solutions using bio-inspired operators like selection, crossover, and mutation.
While the genes inside our body consist of proteins and various other elements, in GA they are represented via numbers. So let’s take a look at how evolution works using genetic algorithm. We will only be using binary cases i.e. cases where the genes can be represented as 1’s and 0’s.
- Selection: Selection basically means retaining the best-performing parents from one generation to the next. These well-performing parents are the ones that are preferred for reproduction. So eg. the two parents chosen via selection are:Parent 1: 1010011000Parent 2: 1001001010.
- Crossover: Next we have a crossover. What happens here is that we choose the common variables of the two parents and retain those in the child solution. So using our example:Parent 1: 1010011000Parent 2: 1001001010Child: 1000011010This pretty much works the same in real life as well. This is how a child retains certain features of the father and the mother.
- Mutation: Mutation is when we take a parent and randomly mutate some of their variables to create a child. This is done to make sure that the system can explore other possibilities for optimal solutions.Parent: 1010011000Child: 0101010001
Cryptokitties uses the Genetic Algorithm to create a new kitty. It uses the crossover mechanism to “sire” a child genome using two parent kitties. This child genome is used to generate a new kitty.
So, now that we have looked at how the genetic algorithm works, let’s go even deeper and take a look at their smart contract.
The CryptoKitty Smart Contract.
You can read the main source code here.
Before we begin, a huge shoutout to James Martin Duffy’s article for the explanation.
The entire code is broken into several smaller contracts. This is done because otherwise, the humongous code body would make code management impossible.
The inheritance tree of the contracts look like this:
contract KittyBase is KittyAccessControl
contract KittyOwnership is KittyBase, ERC721
contract KittyBreeding is KittyOwnership
contract KittyAuction is KittyBreeding
contract KittyMinting is KittyAuction
contract KittyCore is KittyMinting
As the solidity guide states: “When a contract inherits from multiple contracts, only a single contract is created on the blockchain, and the code from all the base contracts is copied into the created contract.”
So, in this case, KittyCore is the contract that is inheriting all the codes from the base contracts. Let’s define what each of these contracts do.
#1 Cryptokitty Access Control
You can check out the KittyAccessControl contract here.
The contract assigns special roles to the devs.
This contract sets the management system of the entire contract and has nothing to do with the way the game works. The special roles assigned by this contract are:
- CEO: The CEO can reassign other roles and change the addresses of the dependent smart contracts. They can also unpause the contract (more on this in a bit).
- CFO: Can withdraw funds from KittyCore and the auction contracts.
- COO: Can release gen0 kitties for auction and mint promo cats. (we will explore this later in KittyAuction)
This contract also has a “pause” function:
This gives the devs an opportunity to pause the entire contract if in case they have deal with a bug or a hack or if they are upgrading the whole system.
KittyBase is the most important contract as far as “kitty definition” is concerned. This is where we set ground rules for kitty creation.
So these kitties are actually a struct with lots of variables.
Let’s see what each of those variables are.
This part of the contract also keeps track of the kitty’s owner. This is done by the following line of code:
mapping (uint256 => address) public kittyIndexToOwner;
#3 Cryptokitty OwnerShip
This is how they define KittyOwnerShip in their contract:
“This provides the methods required for basic non-fungible token transactions, following the draft ERC-721 spec (https://github.com/ethereum/EIPs/issues/721).”
What is fungibility? Investopedia defines fungibility as follows:
“Fungibility is a good or asset’s interchangeability with other individual goods or assets of the same type.”
So, what is fungible and what is non-fungible.
Suppose you borrowed $20 from a friend. If you return the money to him with ANOTHER $20 bill, then it is perfectly fine. In fact, you can even return the money to them in the form of 1 $10 bill and 2 $5 bills. It is still fine. The dollar has fungible properties (not all the time though).
However, if you were to borrow someone’s car for the weekend and come back and give them some other car in return, then that person will probably punch on the face. In fact, if you went away with a red Impala and came back with another red Impala then even that is not a done deal. Cars, in this example, are a non fungible asset.
The kitties in CryptoKitties are non-fungible because each kitty is not created equally. You can’t simply exchange one kitty with another. The CryptoKitties tokens follows the ERC721 formula which you can check here.
#4 CryptoKitty Breeding
This is the contract where we set the functions required for two kitties to breed and produce a new kitty.
There is a breeding process and then there is a birthing process.
Let’s see how both of them work.
Ok, so what is happening in this piece of code?
Firstly, the Ids of both the mother and father kitties are taken for the matronId and sireId and the mother’s “siring withId” is changed to the father’s id. (Remember: a non-pregnant mother’s siringwithId is 0 while that of the pregnant mother, the siringwithId is the Id of the sire.)
Along with that, the number pregnant kitties in the system is increased 1.
Now, let’s see how the birthing process works.
Firstly, the function checks whether the mother is ready to give birth. If the mother is ready to give birth then the parentGen aka the generation of the parent is set to mother’s generation or the father’s generation, depending on who is younger.
After that, the child’s genes are created by calling the geneScience.mixGenes() function. The breeding algorithm is “sooper-sekret” and is handled by a contract that implements GeneScienceInterface. The algorithm is closed-source and not open to the public.
Once the mother gives birth three things happen:
- The number of pregnant kitties goes down by 1 (pregnantKitties — ).
- The ownership of the new child kitty goes to the owner of the mother kitty.
- The function then calls the “createKitty()” function that was elaborated in KittyBase.
#5 CryptoKitty Auctions
Here we have the public methods for auctioning or bidding on cats or siring services. The actual auction functionality is handled in two sibling contracts (one for sales and one for siring), while auction creation and bidding are mostly mediated through this facet of the core contract.
In this contract, the devs have set various public methods for auctioning on cats or for siring services. The main auction functionality has been split into two sibling contracts:
These functions can only be called by the CEO.
The reason why the devs set up two siblings contracts is that according to them:
“Their logic is somewhat complex and there’s always a risk of subtle bugs. By keeping them in their own contracts, we can upgrade them without disrupting the main contract that tracks kitty ownership.”
#6 CryptoKitty Minting
Remember how we said earlier that the COO has the power to create promo cats and gen 0 cats?
This is the contract which enables them to do so.
There is a limit to the number of promo and Gen 0 cats that can be created. It has already been present in the code itself:
- uint256 public constant PROMO_CREATION_LIMIT = 5000;
- uint256 public constant GEN0_CREATION_LIMIT = 45000;
Let’s take a look into this contract:
Let’s examine the createPromoKitty() function.
So, on closer inspection certain things are obvious:
- The COO can create whatever Promo kitty they want with whatever genes they want.
- The COO can send the promo kitty to anyone that they want.
On checking the createGen0Auction() function, the following is apparent:
- The COO has full power over what gen 0 kitty they want to create.
- However, once the kitty is created, it goes straight to auction.
#7 CryptoKitty Core
This is the main contract that runs on the Ethereum Blockchain.
This contract inherits all the functions from the previous contracts AND it also defines a method of its own:
This function basically returns all the for a specific kitty from the blockchain.
So, now that we know what goes on behind the scenes, let’s see how the interface works in real life.
How to Buy CryptoKitties?
Before you get started with anything there are three things that you need:
- Chrome or Firefox Browser.
- The Metamask wallet.
- Ether in your Metamask wallet.
That’s really all that you need to get started.
Once you have these things sorted out, buying the kitties is very straightforward.
- Go to the Cryptokitties Marketplace.
- Once you are in, this is what you will see:
Image Credit: CryptokittiesWhen you see a kitty that you like, simply click on it.
- After that, it is a simple matter of buying the kitty.
Suppose you don’t like any of the kitties that you see, then you can simply search for a Gen 0 kitty. These kitties are under the “Gen 0” tab.
Ok, so now that you know how to buy kitties, let’s look at how you can sire your kitties.
- Firstly, go to the “siring” tab of the marketplace.
- After that, you will see all the kitties that have been put up for siring.Image Credit: Cryptokitties
- After that is a simple matter of choosing the kitty that you want to mater with your kitty.
Gas Consumption Of CryptoKitties.
Now we will look at one of the raging points of discussion that has been brought up because of cryptokitties. The amount of gas that it has consumed and the way it has clogged up the Ethereum blockchain.
As of writing, it is the third most gas-hungry smart contract in Ethereum.
Image Credit: ETH Gas Station
The sheer popularity of the kitties has asked the Ethereum blockchain some serious questions. Because of the increasing demand for the kitties, the number of unconfirmed transaction on the blockchain increased exponentially.
Image Credit: Quartz
Because of this, Axiom aka the company behind cryptokitties was forced to increase their birthing fees. This is what they said in their medium article:
“The excitement and adoption we’ve seen this week has been overwhelming and we couldn’t be happier! However, the Ethereum network is completely full. The only way to keep CryptoKitties from lagging is to increase the gas prices so that all transactions can complete quickly. We know that increased prices will mean that some of you will need to slow down your breeding regimen, and we are incredibly disappointed by that. But who knows? Maybe this slowdown will just mean that you’ll love the Kitties you already have that much more”
We all learned a very valuable lesson from this whole episode.
While, Ethereum will definitely have a role to play in a decentralized future, right now, it simply doesn’t have the means to cope with increased mainstream demands. They definitely need to work more on their scalability in order to move forward.
The Economic Cycle Of Cryptokitties
We came across this fascinating article by Jaz Liu on medium. It documents the entire Economic Cycle of Cryptokitties. We are going to take data from her articles for this particular section.
How does any game that is based on “collecting rare things” work? It works on the simple concept of “scarcity”.
The users are interested in collecting as rare collectibles as possible. But then, this begs the question, who actually decides which traits are rare and desirable?
This is what Arthur Camara, a software engineer on the CryptoKitty team in Vancouver, had to say about that:
“Look, we haven’t said kitties 1–100 are rare. That’s people’s perspective of scarcity. People just think they’re more important for some reason, maybe it’s how they look. The way the game works is that the kitties that breed the most will make those traits more popular. So if you breed a lot of kitties with green eyes, that’s going to be less scarce. People control that scarcity in a way, and create that value themselves. It’s the users creating that idea of scarcity with the genes and with their kitties.”
So, keeping that in mind, let’s see how the CryptoKitty economics will play out in a typical business cycle.
Image Credit: Medium
Stage #1: Growth
This represents the first stage of the cryptokitty economy. The average cost of a starter kitty was $4 however, within a week it went up to $8.
Stage #2: Peak
This is the second stage of the economy when the demand exceeds all expectations and the DAPP becomes mainstream. The demand was so much that it clogged up the Ethereum Blockchain.
Stage #3 Recession
Image Credit: Kitty Explorer
And, after the growth comes to the inevitable recession.
As you can see from the graph, the number of kitties purchased has definitely dropped off over the last few days.
Stage #4 Depression
Will the kitties hit an absolute rock bottom before they recover?
That’s not clear. However, one thing is definitely apparent. With their popularity, it is a difficult thing to envisage.
It is not an exaggeration to say that cryptokitties have taken the world by storm. What we have seen here is the first popular application of the blockchain in a purely recreational form. More than making utility applications, this is the kind that may actually become super mainstream.
However, that is not the only lesson that they have taught us. We all know now that scalability definitely needs to be worked on. If Ethereum can address these issues in the future (with the use sharding, plasma etc.) then DAPPs can truly breakthrough and become an essential part of the zeitgeist.
Get started today and earn 4 bonus blocks
Already have an account? Sign In