0% found this document useful (0 votes)
6 views2 pages

ZombieFactory Smart Contract Code

The document outlines a Solidity smart contract named ZombieFactory, which allows users to create zombies with unique DNA based on a random generation method. It includes functions for creating zombies and emitting events upon their creation. The contract is deployed at a specified address.

Uploaded by

lavanyachawla04
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

ZombieFactory Smart Contract Code

The document outlines a Solidity smart contract named ZombieFactory, which allows users to create zombies with unique DNA based on a random generation method. It includes functions for creating zombies and emitting events upon their creation. The contract is deployed at a specified address.

Uploaded by

lavanyachawla04
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Blockchain Practical

Name:Lavanya Chawla

CSE A1_09

Code:

pragma solidity ^0.4.25;

contract ZombieFactory {

event NewZombie(uint zombieId, string name, uint dna);

uint dnaDigits = 16;

uint dnaModulus = 10 ** dnaDigits;

struct Zombie {

string name;

uint dna;

Zombie[] public zombies;

function _createZombie(string _name, uint _dna) private {

uint id = [Link](Zombie(_name, _dna)) - 1;

emit NewZombie(id, _name, _dna);

function _generateRandomDna(string _str) private view returns (uint) {

uint rand = uint(keccak256([Link](_str)));

return rand % dnaModulus;

function createRandomZombie(string _name) public {

uint randDna = _generateRandomDna(_name);

_createZombie(_name, randDna);
}

Output:

Contract Address: 0x765ed99f07f422d3930a1e648ee684e6b81db50f

Confirmation:

You might also like