Today, I randomly came across a website called crypto zombies.
crypto zombies
It's a nice platform to learn solidity and smart contract dev. I completed a starting course (pretty easy if we know programming basics) which consists 15 chapters. Here r few learnings of today:
In every solidity program, we need to specify the version of language we are using in it using "pragma solidity ".
A smart contract or simply contract is a building block of an Ethereum app. It contains the variables, functions etc. just like a class in java/c++.
This contract is deployed on blockchain which acts as the backend of our decentralized app (dapp).
A contract once deployed on blockchain can't be modified. So, we need to be very careful when writing them.
There are many data types in solidity just like other programming languages.
Integers are broadly 2 types, signed (int) and unsigned (uint), there are different sizes as well (8, 16, .., 256 bits).
Strings are used to store from letters to sentences.
Arrays are also 2 types. Static and Dynamic. When we know we make changes to an array in runtime, we should use dynamic arrays as they provide push and pop functionality.
"function () returns (){}".
Above is the syntax to write a function.Public functions can be called from external contracts also and Private functions are restricted from doing it.
A pure type function can only access data which is passed to it as parameters.
A view type function can access data which is not passed to but present in that contract.
Struct is another data type which is user-defined which contains other variables in it.
Parameters can be passed in 2 ways to a function. Pass by value and Pass by reference.
To pass a parameter with reference, we need to give keyword "memory" before the name of argument.
We can create events, so that when that event occurs, we can perform certain things in our frontend.
"event (arguments)". We can catch these events using web3JS.
To fire that event in a function, we use "emit ".
Push method of dynamic array returns the size of array after pushing.
20.All this info in 20 mins read. Try it if u want to get started.
My twitter: twitter
My LinkedIn: linkedin
My showwcase: showwcase
Top comments (2)
Awesome find. Need clarification on few points:
point 15
. The site saysDon't forget to pass the first argument by value by using the memory keyword
(Course 1, Chapter 7).Thanks
There is no such thing called references in solidity. But if we just pass the value of it, we can only use it, but can't change the actual value of the variable. So, we need to pass the address along with it's value, if we want to change it. This can be understood as pass by reference where we are actually passing value but along with it's address. I mentioned passing value with address as pass by reference as it is close to it which might be easy to understand.