Answered step by step
Verified Expert Solution
Question
1 Approved Answer
We want an event to let our front - end know every time a new zombie was created, so the app can display it .
We want an event to let our frontend 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 array.push will be the index of the zombie we just added. Store the result of zombies.push in a uint called id so you can use this in the NewZombie event in the next line. pragma solidity ; contract ZombieFactory declare our event here uint dnaDigits ; uint dnaModulus dnaDigits; struct Zombie string name; uint dna; Zombie public zombies; function createZombiestring memory name, uint dna private zombies.pushZombiename, dna; and fire it here function generateRandomDnastring memory str private view returns uint uint rand uintkeccakabiencodePackedstr; return rand dnaModulus; function createRandomZombiestring memory name public uint randDna generateRandomDnaname; createZombiename, randDna;
We want an event to let our frontend 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 array.push will be the index of the zombie we just added. Store the result of zombies.push in a uint called id so you can use this in the NewZombie event in the next line.
pragma solidity ;
contract ZombieFactory
declare our event here
uint dnaDigits ;
uint dnaModulus dnaDigits;
struct Zombie
string name;
uint dna;
Zombie public zombies;
function createZombiestring memory name, uint dna private
zombies.pushZombiename, dna;
and fire it here
function generateRandomDnastring memory str private view returns uint
uint rand uintkeccakabiencodePackedstr;
return rand dnaModulus;
function createRandomZombiestring memory name public
uint randDna generateRandomDnaname;
createZombiename, randDna;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started