lynnux

Logo

☁️ customer engineer at google
🏂 snowboarder
🍞 carb addict
🏘 real estate investor
💃🏻 dancer
✈️ traveler
📖 learner
👾 ex-gamer with semi-annual relapses
☕️ fueled by caffeine


linkedin github

Journal

21 Nov 2021


Cryptozombies Lesson 2

I love the meme references in cryptozombies’ example code 😂 :

contract Doge {
  function catchphrase() public returns (string memory) {
    return "So Wow CryptoDoge";
  }
}

contract BabyDoge is Doge {
  function anotherCatchphrase() public returns (string memory) {
    return "Such Moon BabyDoge";
  }
}
cryptozombie that has eaten a cryptokitty!


My smart contract for lesson 2:

pragma solidity >=0.5.0 <0.6.0;

import "./zombiefactory.sol";

contract KittyInterface {
  function getKitty(uint256 _id) external view returns (
    bool isGestating,
    bool isReady,
    uint256 cooldownIndex,
    uint256 nextActionAt,
    uint256 siringWithId,
    uint256 birthTime,
    uint256 matronId,
    uint256 sireId,
    uint256 generation,
    uint256 genes
  );
}

contract ZombieFeeding is ZombieFactory {

  address ckAddress = 0x06012c8cf97BEaD5deAe237070F9587f8E7A266d;
  KittyInterface kittyContract = KittyInterface(ckAddress);

  function feedAndMultiply(uint _zombieId, uint _targetDna, string memory _species) public {
    require(msg.sender == zombieToOwner[_zombieId]);
    Zombie storage myZombie = zombies[_zombieId];
    _targetDna = _targetDna % dnaModulus;
    uint newDna = (myZombie.dna + _targetDna) / 2;
    if (keccak256(abi.encodePacked(_species)) == keccak256(abi.encodePacked("kitty"))) {
      newDna = newDna - newDna % 100 + 99;
    }
    _createZombie("NoName", newDna);
  }

  function feedOnKitty(uint _zombieId, uint _kittyId) public {
    uint kittyDna;
    (,,,,,,,,,kittyDna) = kittyContract.getKitty(_kittyId);
    feedAndMultiply(_zombieId, kittyDna, "kitty");
  }

}

General

I have a love / hate relationship with coding. I think everyone who does some form of engineering knows the feeling. That feeling when nothing is going right, none of it makes sense, every little thing is a struggle… but then, one day or moment; it suddenly all clicks into place, everything is right again in the world, and all the pain and strife that was endured to get there becomes worth it. Rinse and repeat.

I’m not necessarily going through such a dramatic roller coaster ride like that right now, but it’s only a matter of time!