Padmini On-Chain

Share this post
Solidity & Cryptozombies
padminionchain.substack.com

Solidity & Cryptozombies

Finally, some code

Padmini Pyapali
Nov 16, 2021
Comment
Share

This week, I stumbled upon cryptozombies,an interactive virtual school for programmers who want to learn how to develop on the blockchain. It expects a basic level of programming competency; I’ve found my javascript experience helpful in going through the tutorials.

The tutorial takes you through building a blockchain game featuring zombies, each with a set of unique characteristics determined by its name. The first two lessons focus primarily on learning the basics of Solidity and the blockchain. If you’re motivated, you could probably complete several lessons in a day.

I won’t walk you through any more details of the tutorial because you should just do it (you can finish lesson 1 in under 30 minutes), but I want to point out a few things I found interesting.

#1 Function execution always starts with an external caller.

...this means every function has access to a variable (msg.sender) that stores the eth address that called the function. An eth address is also a separate datatype in Solidity called ‘address’. msg.sender can come in handy in your smart contract if, for example, you wanted to limit the number of actions a user can take.

Ex:

mapping(address => uint) numActions;
function performAction() public {
    require ( numActions[msg.sender] == 0 );
    // action code here
}

#2 Solidity doesn’t have native string comparison functionality

...so you have to memorize this:

keccak256(abi.encodePacked(<string 1>)) == keccak256(abi.encodePacked(<string 2>));

keccak256 generates a hash from bytes. First, you convert the string to bytes using abi.encodePacked(), then you pass that to keccak256().

#3 All data from other smart contracts are stored and accessible on the block-chain

...so you can interact with other blockchain entities or NFTs. But it isn’t that straightforward.

All the data is available on the blockchain, but if you want to interact with that data through code, you need access to the variables and functions that return the data you need. This means you need access to the contract code.

Lesson 2 of the tutorial will walk you through declaring interfaces to interact with the source code of other contracts, but it didn’t cover where to find the source code. Thankfully, my partner is a crypto nerd and pointed me in the right direction: etherscan. You’ve probably stumbled across etherscan before if you’ve tried to view transaction history for an NFT. You can also lookup your own ethereum address and view your current wallet balance (a bit awkward). I have to say, it’s kind of nice having an all-inclusive blockchain explorer.

Share

Here’s how I found the CryptoKitties contract code on Etherscan:

Search for CryptoKitties

Click on the link next to ‘Contract’

Click on the ‘Contract’ tab

Viola! The CryptoKitty contract code:


I have a strong statement. Understanding blockchain technologies, especially Ethereum, is the best use of your time (unless you’re facing an existential threat). Not because of all the hype around NFTs selling for $67 million and Bored Ape Yacht Club yacht parties, but because you’ll start to understand the opportunity that lies behind these seemingly (but definitely not) small paradigm shifts. If you’re getting into the code, you’ll be able to see the opportunities more clearly. The idea of a shared database between every contract ever built on Ethereum is ground-breaking, mind-boggling, absolutely, completely exciting. The ideas we’re seeing so far are interesting, but it’s still early. If you don’t have the bandwidth to start learning or building, pay attention. It’s going to get wild.

Thanks for reading my metaverse rambles. Feel free to reach out to me on Twitter.

Share

CommentComment
ShareShare

Create your profile

0 subscriptions will be displayed on your profile (edit)

Skip for now

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.

TopNewCommunity

No posts

Ready for more?

© 2022 Padmini Pyapali
Privacy ∙ Terms ∙ Collection notice
Publish on Substack Get the app
Substack is the home for great writing