If any body passed the chapter 13 on cryptozombie, can he please elaborate regarding how we will write our final contract in cryptozombies chapter 13?
https://cryptozombies.io/en/lesson/1/chapter/13It says that
We want an event to let our front-end know every time a new zombie was created, so the app can display it.
Declare an event called NewZombie. It should pass zombieId (a uint), name (a string), and dna (a uint).
Modify the _createZombie function to fire the NewZombie event after adding the new Zombie to our zombies array.
You're going to need the zombie's id. array.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 uint called id, so you can use this in the NewZombie event in the next line.
Contract.sol
pragma solidity ^0.4.25;
contract ZombieFactory {
// declare our event here
uint dnaDigits = 16;
uint dnaModulus = 10 ** dnaDigits;
struct Zombie {
string name;
uint dna;
}
Zombie[] public zombies;
function _createZombie(string _name, uint _dna) private {
zombies.push(Zombie(_name, _dna));
// and fire it here
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
function createRandomZombie(string _name) public {
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}
}
I am unable to pass this chapter as I write on line 5 (// declare our event here
event NewZombie(_zombieId, _dna, _name);
function add(_zombieId, _dna) public {
uint _name = _zombieId+_dna;
and on line 15, I modify the array like this
Zombie[] public Newzombie;
I then edit and modify function on line 17-18
function _createZombie(string _name, uint _dna) private {
Newzombie.push(Zombie(_name, _dna));
and on line 19 (// and fire it here
emit _zombieId.Newzombie.push(_name, _dna) -1;
return _name;
but getting the error, can anyone please correct all my mistakes and provide the complete source?
It'll be appreciated if anyone may help
Regards