Solidity and Blockchain Development
Currently using https://university.alchemy.com/ and https://cryptozombies.io to learn block chain development.
Ethereum Bootcamp
Blockchain and Crypto
The purpose of blockchain is to have a network of computers agree upon a common state of data
A smart contract is code that will always run the way it is programmed.
Crypto Zombies
keccak256
is an Ethereum hash function based off SHA3
Events
- are a way for our contract to communicate that something happened on the blockchain to your app front end. you declare them at the top of the contract method than call them with emit name
Module 1 final code
// Pragma is what we use to tell what version of the compiler to use
pragma solidity >=0.5.0 <0.6.0;
// All code is encapsulated in a contract. Kinda like a library?
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 memory _name, uint _dna) private {
zombies.push(Zombie(_name, _dna));
uint id = zombies.push(Zombie(_name, _dna)) - 1;
emit NewZombie(id, _name, _dna); // Calling the event
}
function _generateRandomDna(string memory _str) private view returns (uint) {
uint rand = uint(keccak256(abi.encodePacked(_str)));
return rand % dnaModulus;
}
function createRandomZombie(string memory _name) public {
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}
}