How does work?

Image for post
Image for post
These cute little buggers are taking over Ethereum with 15% of all transactions on the blockchain buying, selling and breeding kitties.

Let’s look under the hood of the Ethereum based cryptocurrency cat craze and see how it works!

FYI: This post is aimed at those without much knowledge of Ethereum or Genetic Algorithms. I will be looking into the actual smart contract code in a later blog post though, so stick around! Here’s my website.

Cryptokitties is a blockchain game. Players collect and breed CryptoKitties, which are all unique, thanks to a digital genome that defines how they look.

The whole thing is powered by the Ethereum blockchain, a cryptocurrency kind of like Bitcoin, except transactions may contain executable code. This means that you can create a Distributed Application (DApp) that makes use of the decentralised structure of a cryptocurrency, and the usefulness of a computer application. You can use complex logic within a transaction.

So what? Well, if you don’t quite see the potential of this combination straight off the bat, this post wont convince you. Think: completely transparent and autonomous transactions with possibilities far beyond simply sending money from one person to another. I’ll leave it to the commenters to provide further insightful examples.

Basic explanation: Genetic Algorithm

In your body, these genes consist of proteins that are all connected in a specific way. In a GA, we just use numbers to represent them.

In biology, animals can reproduce by mating. For those of you not familiar with the process, it involves taking genes from two parents and mixing them together. The sperm and the egg each contribute half the total amount of DNA which makes a child that has some traits belonging to the father, and some traits belonging to the mother, but never being exactly the same as either.

Image for post
Image for post
Crossover in a GA via wikimedia

In a GA, we call this crossover. It works exactly the same too. You copy one half of the father’s genome, and the other half of the mother’s genome into a new, and unique child genome. How exactly you split up the genes can differ each time you crossover, meaning that even two siblings will have unique genomes. Just like in real life.

CryptoKitties works just like this. After mating (or “Siring” as they call it in-game) the new child genome is used to generate a new kitty.

Running a GA on Ethereum

The key here is understanding that representing a genome is as simple as storing a few numbers. Doing crossover then, is really a simple piece of code that takes two numbers (parent genomes) as input and produces a single number as output (child genome).

On the Etherum blockchain, we can store data (like a genome), and perform calculations with that data using Smart Contracts.

WTF is a Smart Contract?

In Ethereum, there are two types of accounts: External Accounts and Contract Accounts.

Image for post
Image for post
The Blockchain: Like The Cloud except it’s not just “someone else’s computer” it’s “lots of people’s computers, all at once, all the time, forever”

A Contract Account is a special account. Like an External Account, it has an address, so you can make transactions with it. Unlike External Accounts, it isn’t necessarily owned by anybody, and it contains some code. Every time a transaction is made with it, the code is run (like running a program on your computer).

I’m purposefully leaving out how mining works. For now, don’t worry about it. Briefly, a miner runs the code as part of verifying the transaction.

Contract Accounts are also referred to as a Smart Contracts. There are lots of smart contracts being calculated all the time as transactions are verified on the blockchain.

CryptoKitties Smart Contracts

There’s a lot to digest there…but thankfully it’s all very well commented. The main contract “KittyCore” explains the various aspects:

- KittyBase: This is where we define the most fundamental code shared throughout the core functionality. This includes our main data storage, constants and data types, plus internal functions for managing these items.

The “data storage” referenced here means how the Genome of a kitty can be stored in the contract.

— KittyOwnership: This provides the methods required for basic non-fungible token transactions, following the draft ERC-721 spec (


Funigible [Adjective]: Able to be substituted for something of equal value or utility; interchangeable, exchangeable, replaceable.

So non-fungible means non-interchangeable(?). This refers to the parts of an asset, rather than the asset itself. Example, rice is fungible, because you can substitute one grain of rice in a sack for any other grain in the world, and the value of the sack as a whole will remain the same. This doesn’t hold true for real estate or land for example. Any acre of land in a property cannot be swapped for any other acre in the world without changing the price of the property as a whole.

In this application, imaging owning a bunch of kitties worth $100 as a whole. They are all unique and therefore cannot be swapped for other kitties without changing the value of the group of kitties.

(I welcome feedback on this…I’m not entirely sure of my analogy)

— KittyBreeding: This file contains the methods necessary to breed cats together, including keeping track of siring offers, and relies on an external genetic combination contract.

This refers to the smart contracts that do the crossover as we discussed earlier.

— KittyAuctions: 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 is mostly mediated through this facet of the core contract.

This let’s you sell kitties and… basically pimp them out to breed with other kitties. A core feature, clearly.

— KittyMinting: This final facet contains the functionality we use for creating new gen0 cats. We can make up to 5000 “promo” cats that can be given away (especially important when the community is new), and all others can only be created and then immediately put up for auction via an algorithmically determined starting price. Regardless of how they are created, there is a hard limit of 50k gen0 cats. After that, it’s all up to the community to breed, breed, breed!

This part is actually quite interesting. The functionality here is very similar to how many ICOs (initial coin offerings) work. Often, the creator of the coin will create a bunch of these coins (or in this case, kitties) to be given away for free. This way, you can kickstart the community by giving people something that will have value (however intangible) and scarcity at a later date.


I welcome any feedback on the content, or suggestions for future posts!

Lastly..there have been way too many kitties mentioned throughout this post (and on the internet in general as of late…). I hope this serves to bring balance to the force.

Image for post
Image for post
That’s better. via pexels

Written by

I own , a software development consultancy. I’m also a PhD student, musician and youtube creator.

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