Blockchain CryptoZombies - Lesson 1: Making the Zombie Factory


This is where the magic begins, remember to sign in with an account to save your progress :)

CryptoZombies - Learn to code games on Ethereum.

CryptoZombies is an interactive code school that teaches you to write smart contracts in Solidity through building your own crypto-collectables game.


In Lesson 1, you're going to build a "Zombie Factory" to build an army of zombies.
  • Our factory will maintain a database of all zombies in our army
  • Our factory will have a function for creating new zombies
  • Each zombie will have a random and unique appearance
In later lessons, we'll add more functionality, like giving zombies the ability to attack humans or other zombies! But before we get there, we have to add the basic functionality of creating new zombies.

Make sure to walk through the interactive lessons all by yourself first. This is just a rewind of important knowledge :)

Let 's take a look at our code at the end of lesson 1, which we will explain briefly about:

etBLUzHTAm

1 Solidity code sharing site. Share Solidity code snippets with friends, or check out cool code snippets from around the web.

As you can see, we have some variables, a Zombie struct, a public array of Zombies and some functions varied in different security types.

There are 3 things you need to remember from this lesson:

You're going to need the zombie's idarray.push() returns a uint of the new length of the array - and since the first item in an array has index 0, array.push() - 1 will be the index of the zombie we just added. Store the result of zombies.push() - 1 in a uintcalled id, so you can use this in the NewZombie event in the next line.

Events are a way for your contract to communicate that something happened on the blockchain to your app front-end, which can be 'listening' for certain events and take action when they happen.

We need an event to let our front-end know every time a new zombie was created, so the app can display it.


That 's the end of lesson 1, here 's what you 've learned so far: 

  • How to write Ethereum smart contracts
  • Programming in Solidity, Ethereum's smart contract programming language
  • Building games on Ethereum

See you in the next lesson :)

No comments

Hey, buddy. What's on your mind :)

Powered by Blogger.