Just completed level 1 on #cryptozombies

share.cryptozombies.io/en/lesson/1/sh…

Some learnings from a java developer perspective 👇

#Solidity #Ethereum #Web3 #Blockchain #Java #javascript
The naming convention is the same as java.
We have few extra datatypes like
🔲 uint (Unsigned integer)
🔲 struct (Similar to a class in java) - Doesn't have a constructor
uint - Unsigned Integer - int data type that only stores non-negative integers i.e 0 and positive integers.

For e.g, if an int can store 256 numbers, the range of int will be from -128 to 127. But the range of uint will be 0 to 255.
For calculating an exponential, there is an extra operator **

uint x = 5 ** 3;
The value of x will be 125.
In java, let us assume we have a person class and for storing the address we use a separate class that has houseNumber and streetName. We can use struct here

struct Address {
uint houseNumber;
string streetName;
}
There is no new keyword in solidity. If we want to create a new address, the syntax is

Address myAddress = Address(1,"Baker street");
We can push this into an array (similar to javascript)

Address[] addresses;
addresses.push(myAddress);
Functions - all functions are by default public in solidity - Which means anyone (or any other contract) can call your contract's function and execute its code.

The function declaration is slightly different - In my opinion, it is a combination of java and javascript styles
Example:
We need to use the 'function' keyword at start followed by name of function.

The main difference is we shift the public/private keyword & return type to the end of the declaration

function _addNumbers( uint _x, uint _y) private returns (uint) {
return _x + _y;
}
We can add one of the 2 keywords view/pure to function declarations

view - If the function doesn't actually change state e.g. It doesn't change any values or write anything

pure - If the function is not even accessing the data from our contract - e.g. helper functions
TypeCasting is very similar to java

We can declare and fire events as per the requirement. Example

event FindSum(uint x, uint y, uint result);

function _findSum(uint _a, uint _b) private returns (uint) {
uint result = _a + _b;
emit FindSum(_a,_b,result);
return result;
}
Overall, it was a good learning experience. The concepts are explained clearly.
@loomnetwork

#cryptozombies
#java #Solidity #Web3 #Blockchain

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Prasad Kancharla

Prasad Kancharla Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(