My friend Anshul recently told me about . I had heard about it clogging up the ETH pipes and causing the price to drop but had not realized what an amazing design the CryptoKitties team had realized. CryptoKitties are basically breed-able beanie babies built on top of the ethereum . And yet, they are also so much more than that: CryptoKitties are a digital playground where programmers, geneticists, and experts in economics, bioinformatics, machine learning and game theory can come together to learn and play. CryptoKitties blockchain Studying cryptokitties For those of you new to CryptoKitties, have a look at the ; this will teach you the basics of the CryptoKitties game system. To get a better view of exactly just what a kitty is you can go through the . You’ll find that a CryptoKitty is basically a struct on the EVM that looks like this. Mashable guide CryptokittiesCore contract struct Kitty {uint256 genes;uint64 birthTime;uint64 cooldownEndBlock;uint32 matronId;uint32 sireId;uint32 siringWithId;uint16 cooldownIndex;uint16 generation;} We see some other interesting things too… modifier onlyCEO() {require(msg.sender == ceoAddress);_;} and… /// SEKRETOOOOcontract GeneScienceInterface {function isGeneScience() public pure returns (bool); @title /// given genes of kitten 1 & 2, return a genetic combination - may have a random factor/// genes1 genes of mom/// genes2 genes of sire/// the genes that are supposed to be passed down the childfunction mixGenes(uint256 genes1, uint256 genes2, uint256 targetBlock) public returns (uint256);} @dev @param @param @return Wow a secret. This is THE secret. If you’ve been playing cryptokitties you know this is how kitties are produced. You’ll notice that siring kitties produces offspring in a manner that feels intuitive: features get passed on from parents to offspring sometimes but not always, sometimes skipping generations. This is the code that runs at the conception of cryptokitties with non-zero generations. A brief genetics remedial from your 10th grade biology class A (from , meaning ‘to show ‘, and , meaning ‘type’) is the composite of an ’s observable characteristics or , such as its , , biochemical or physiological properties, , and products of behavior (such as a bird’s nest). A phenotype results from the of an organism’s genetic code, its , as well as the influence of environmental factors and the interactions between the two. When two or more clearly different phenotypes exist in the same population of a species, the species is called . A well-documented polymorphism is ; while the coat color depends on many genes, it is clearly seen in the environment as yellow, black and brown. phenotype Greek phainein typos organism traits morphology development behavior expression genotype polymorphic Labrador Retriever coloring Managing all the features in my head was difficult. I needed somewhere to organize my thoughts so I created a do do some of the math. From the currently features that are being served up by the crypokitties.co API we know that a CryptoKitty has up to 1.15792×10⁷⁷ phenotypes. Given that the ‘genotype’ for a CryptoKitty is a 256-bit integer there are 2²⁵⁶ possible genotypes for a CryptoKitty. Going to cryptokittydex I was able to see the genotypes for each kitty and block addresses! What fun! spreadsheet totesbasic The API at CryptoKitties.co serves the public data needed to create the game around this blockchain. It creates the images, names the “features” serves then via the API and facilitates the ethereum transactions required to play the game using MetaMask. Inspecting the browser while playing cryptokitties, you’ll find that the requests to cryptokitties.co are serving results related to the features expressed in the phenotype and familial relationships. Running curl ' https://api.cryptokitties.co/kitties/123606' gives {"id": 123606,"name": null,"generation": 4,"created_at": "2017-12-07T06:54:46.000Z","image_url": " ","color": "topaz","bio": "What's up! I'm Kitty #123606. I've never told anyone this, but I once pawed at a dog. I once got in a fight with a moose, and won. We can be friends, but keep the ultra purrsonal stuff to yourself, please.","is_fancy": false,"is_exclusive": false,"fancy_type": null,"status": {"is_ready": true,"is_gestating": false,"cooldown": 1512636431155,"cooldown_index": 3},"auction": {},"owner": {"address": "0xb464f93be01bde143c92176d921c1d0d533bc3ca","image": "17","nickname": "KittyHodlr"},"matron": {"id": 123288,"name": null,"generation": 3,"owner_wallet_address": "0x8081ecb6f3350fe5ed46f1bd74d5ada62c62e740","created_at": "2017-12-07T06:30:08.000Z","image_url": " ","color": "topaz","is_fancy": false,"is_exclusive": false,"fancy_type": null,"status": {"is_ready": true,"is_gestating": false,"cooldown": 1512635143445}},"sire": {"id": 96883,"name": "Gen 3 Purple Sizzurp","generation": 3,"owner_wallet_address": "0x8081ecb6f3350fe5ed46f1bd74d5ada62c62e740","created_at": "2017-12-05T23:09:11.000Z","image_url": " ","color": "sizzurp","is_fancy": false,"is_exclusive": false,"fancy_type": null,"status": {"is_ready": false,"is_gestating": false,"cooldown": 1512641108913}},"children": [],"cattributes": [{"description": "orangesoda","type": null}, {"description": "simple","type": null}, {"description": "granitegrey","type": null}, {"description": "coffee","type": null}, {"description": "pouty","type": null}, {"description": "totesbasic","type": null}, {"description": "topaz","type": null}, {"description": "cymric","type": null}]} https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/123606.svg https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/123288.svg https://storage.googleapis.com/ck-kitty-image/0x06012c8cf97bead5deae237070f9587f8e7a266d/96883.svg This is what a CryptoKitty looks like according to the API. We can see the owners address, and the features of Kitty # . Most importantly we get an image of an amazing, fluffly cat. 123606 So cute and fluffly! Each cat has cattributes, based on its genes. Remember that 256 bit uint ? That determines what your kitty looks like. Ignoring the auction system, we can think about the genetic aspect of the system as having two parts genes X **— (cryptokitties.co)→ (**phenotype X, image X) genes matron+ genes sire genes offspring —( mixGenes )→ where is our secret sauce function. Could we study the reproductive patterns of cryptokitties to be able to predict breeding outcomes better than chance? mixGenes We want to be able to get data about the genomes of these mystical creatures by inspecting the ethereum blockchain. We could write code to download and parse all cryptokitties transactions so far but that would be slow and ain’t nobody got time for cat. I decided to quickly write a scraper to collect the current set of cats available on cryptokitties.co and cryptokittydex.com. I wrote this to use a headless Chrome instance to ‘visit’ and put the genomes of all the cats, their owners and their images in an S3 bucket (or on disk). I let it run till it downloaded about 100k cats and their images. code cryptokittydex.com The next day I decided to study the sample of cryptokitties I had scraped. I quickly noticed that fancy kittys had extensions while normal kitties were saved as I began to notice patterns and learnt the basics of each cryptokitty attribute by trial and error and referring to reddit guides. It became obvious which features were exclusive and I slowly felt I was becoming better at categorizing cryptokitties. By the end of the night I felt I could soon be the Gregor Mendel of cryptokitties. .png .svg. Cryptokitty basics There are 3 basic feature types. Excluding ‘fancy’, there are 7 or 8 visible features for each cat. There are 2 reproductive features for each cat that are not visual. : BodyType, PatternType, MouthType, EyeType, Body Features (4) : Primary, Secondary, Tertiary, Eye Colors Features (4) : CoolDown, Generation Reproductive Some patterns I noticed while going through the cats. Totesbasic cats do not express their tertiary color but do have the gene The beard is the only mouth feature that contains color. It uses the primary color. The eye color is also the color of the background The primary color is the main color of the cats fur The secondary color is the color of the cats fur patch(s) / stripes if their pattern type has 2 colors Tertiary colors are expressed in the cats fur for some pattern types with 3 colors Now the question was — which kitties had not been discovered yet? And could we somehow do a to see what these kitties would look like before they are born? Opening up the SVGs it was easy to see the different parts of the kitty. cryptokitty genetic test Grepping around I looked for the color in this kitty and searched for it in another. It was the same across all the files! However continuing through the dataset I found not all fur patterns used all 3 colors and some were pretty convoluted making it difficult to manipulate the svgs directly with JSDom. I decided to just treat the svgs as strings and create three sets of images. The first would be a set of 48 images that would have cats of every possible BodyType and PatternType combination. The second was a set of 8 cats with all Mouth combinations. The third — you guessed it — the set of all possible eyes. Isolating the svg elements for each of these ‘genes’ allowed me build a quick React.js prototype that was able to render a kitty of any possible phenotype. aquamarine ={body} ={mouth} ={eye} ={pattern} ={[c.Primary[primary],c.Secondary[secondary],c.Tertiary[tertiary],c.EyeColor[eyeColor]]}/> <Cryptokitty body mouth eye pattern colors Adding some simple controls, I had a very early prototype for my cryptokitty genetic testing company. Meow all I have to do is find a cool person with some good venchair carpetal. Tell me what you think! PRs are highly encouraged. CryptoKitty Designer: https://bytesforbites.github.io/cryptokitty-designer/#/ Source: . https://github.com/BytesForBites/cryptokitty-designer Send kittehs and tips to 0x02Ee97a13e434717e3FFa12758a235D1a1680775 Please sir, I’m just a dev cat that needs to pay for my new mouse