Foraying into Blockchain

Blockchain is a zany cool idea, especially for crypto-anarchists like me. I’ve been wading deeper into crypto this weekend; got myself setup with Metamask, started hunting Bounties, opened my Gitcoin tip jar, joined some slack & telegram communities and became a Level 1 Crypto-Zombie.

Remember one of my recent posts about giving up coding? yeah, forget that. I’m full of sh*t. Here I go again, this time raking at the blockchain soil.

So, here is my crypto-zombie Ethereum Solidity Contract (s’no’biggie — just a Zombie generating blockchain hook).

pragma solidity ^0.4.19;
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 = zombies.push(Zombie(_name, _dna)) — 1;
NewZombie(id, _name, _dna);
}
function _generateRandomDna(string _str) private view returns (uint) {
uint rand = uint(keccak256(_str));
return rand % dnaModulus;
}
function createRandomZombie(string _name) public {
uint randDna = _generateRandomDna(_name);
_createZombie(_name, randDna);
}
}

It really is no biggie because I took the tutorial here ( you do need some basic JS fu to get through it without cheating ).

The awesome thing about being a level 1 crypto-zombie is a better understanding of how blockchain works. Even though the above is a tutorial, I was still stoked to learn how to write some data to a blockchain! You can also share functions and events with the entire eco-system, which is a pretty mind-blowing concept if you pause to think (*checks phone).

Onwards to Buidling Blockstack dApps!