Source code of the NFT online game "CryptoKitties"

 CryptoKitties are NFT online game DApps that can be played on the Ethereum blockchain. (* Reference: Another article “ DApps and Ethereum ”)

Since I am interested in blockchain, I would like to actually use DApps, so I will actually register.

And here, I will try to read the source code of CryptoKitties, as I have never studied Solidity, a development language on the blockchain. (Because I am a beginner, if there is a misunderstanding, I would appreciate it if you could point it out in the comments. It's not bad

What is CryptoKitties

Crypto Kitties

CryptoKitties is a game released in 2017 that has become popular around the world, including Japan and is recognized as a pioneer of blockchain games.

As the name suggests, in a cat game, the cats raised and bred by players are NFTs with unique values ​​that are traded in the Ethereum cryptocurrency ETH.

Also, breeding a cat with a high rarity will increase the price of that cat, so for the purpose of playing, you will try to breed a cat with a high value in order to acquire more ETH.

The registration itself was mostly in English, but it was easy, and I think anyone can do it while translating.

After you start playing, you will be using ETH to play, so let's leave it until you understand the outline and proceed to the next step.

How to write Solidity

Now that you have registered with CryptoKitties, you have an overview of the game.

In fact, the source of the contract of CryptoKitties is open to the public. You can check it here on Etherscan. (I will investigate how to use Etherscan separately, but it seems that various things can be done)

I have never seen the DApps source code before, but I decided to fumble through the source code to get a feel for Solidity.

take a look

Selecting Contracts brought up the source.

First of all, at the beginning, if you write like this, it will be a declaration that you will write the code in solidity.

pragma solidity ^0.4.11;

line 5

Next, from the following way of writing, it seems that the contract is defined as follows when using the elements of another contract. In this case, the contract KittyOwnership seems to be defined as consisting of the elements of the contract KittyBase and ERC721.

contract KittyOwnership is KittyBase, ERC721 {

line 472

Also, function() is created inside or outside the contract, and the function created by the contract described later is called first.

From this, it seems that you don't have to worry about the order in which function() is defined, regardless of whether the contract is used or not.


If you follow the whole with only this writing style, you can see that the configuration is as follows.

I haven't followed the contents of variables and processing, but as far as I can see the comments, it seems to do something like this. Pretty much what the title says.

Since the comments are written in detail, it seemed that I could grasp the contents to some extent even if I could not understand the code.

Kitty Base

Where to define variable constants that will be shared later

Kitty Access Control

A place to control access, divided into roles called CEO, CFO, and COO


Where to add the methods required for NFT transactions based on ERC721

Kitty Breeding

A place to give the methods necessary for breeding

Kitty Auctions

A place to grant cat auctions and bidding methods and mediate transactions

Kitty Minting

A place to wrap up the functionality of the generated cats. (There are a maximum of 50,000 cats that can be generated, including promo cats, which are given to new communities (up to 5000), and auction cats that are automatically priced by an algorithm.)


From the point of view of a non-learner, I briefly wrote down the records of seeing the source of CryptoKitties.

I would like to start learning about Solidity from now on, but once again I realized how useful it is to be an open source of free teaching material.

I also purchased the following books, which are well-received in the engineering community, so I would like to subscribe to them.