(Part 1) Ethereum Solidity Development - Getting Started + Lower Level Explanation (PT 1) by igormuba

View this thread on steempeak.com
· @igormuba ·
$25.80
(Part 1) Ethereum Solidity Development - Getting Started + Lower Level Explanation (PT 1)
#### Repository
https://github.com/igormuba/EthereumSolidityClass/tree/master

#### What Will I Learn?

- Ethereum variables and functions
- Lower level memory vs storage vs stack
- Deploy on a test environment (free)

#### Requirements

- Browser
- Visual Studio Code

#### Difficulty

- Basic

#### Tutorial Contents

# Setting up the environment for the whole series
First, you need to setup your development environment.

Think about long term, where I want to get with this course, I recommend you to use the metamask browser add-on.
You can get it here
https://metamask.io/

Also, I use Visual Studio code because it has many handy plugins, but you can also use Ethereum's browser IDE.

To get Visual Studio Code go here
https://code.visualstudio.com/
And add to it an addon called Solidity. To do so, after you install and open the Visual Studio Code go to the tab extensions (CTRL+SHIFT+X), find the extension called solidity which is the most widely used and install it
![](https://cdn.steemitimages.com/DQmRMcGN8XUGVjyP8Sr25eGXqP7uLCug2mPKB61GdDB5uDq/image.png)

To use the browser IDE, that should also work fine, just go to
http://remix.ethereum.org/

# Solidity version

It is highly recommended that when you are developing for the Ethereum virtual machine you set the solidity version you want to use.
If you are not sure what is the most recent version, when you open the online IDE (Remix) you will see on the sample code what is the most recent version

![](https://cdn.steemitimages.com/DQmNW1bsm1D7SReuM9MRqNTewiBqsu1MsW8LvcAuQXNMzwx/image.png)

# Basic sintax

Solidity is very similar to Javascript, with a few tweaks.

To declare variables you must cast the type of the variable and it's scope followed by the variable name.
For example

```
string private stringVarible = "Variable name";
```

For setting integer variables you must explicitly tell the virtual machine if the variable is signed or unsigned, unsigned means it can only be positive (can't have negative sign).
For example
```
uint private unsignedInteger = 10;
```

# Setters and Getters

I am using specifically Solidity 5 in this tutorial to highlight a few substantial changes. Most tutorials you will find on the internet might cover an earlier version of the language, if you try to code like they teach, you will probably face a few errors and you will be stuck on an earlier syntax that, though easier to write and read, gives you less power.

The importance of using the most up to date syntax is that you can **LITERALLY SAVE MONEY** as the developers are always working on making the language less resource intensive, because computer resources from the EVM (Ethereum Virtual Machine) literally cost money (Ethereum) to execute.

Don't worry though, we will be using a development environment that is free and even shows you an estimative of costs so when you develop your contracts you can try and see what data structures are the cheapest.


Starting from Solidity 5 onwards you must make the location of the variables explicit, refer to the change doc at
https://solidity.readthedocs.io/en/v0.5.0/050-breaking-changes.html

There is a very in depth guide of how and when to use it here
https://medium.com/coinmonks/ethereum-solidity-memory-vs-storage-which-to-use-in-local-functions-72b593c3703a

But to sum it up: storage variables are permanent and **CAN NOT BE CRATED INSIDE FUNCTIONS**, so in functions when we create a variable we are using memory variables.

So a simple setter for the string variable would be

```
function setStringVariable(string memory newVariable) public {
        stringVariable = newVariable;
    }
```
The first keyword is the same as JavaScript and then we give the name of the function, then as an argument for the setter we give the type `string` and we must make it explicit that it is a memory variable and is called newVariable, and then we say it is public.

A getter would look like

```
function getStringVariable() public view returns (string memory){
        return stringVariable;
    }
```
Again, we declare the first two words as if JavaScript but we must explicitly tell later that it is a public function that creates a view that is returned from the Ethereum Virtual Machine, and that it returns especifically a string that is in memory

# Where this stuff goes

Before we continue, you must be aware that all variables and functions must be inside a contract. Ethereum Viirtual Machine deal with everything as contracts, so let us wrap our varaibles and functions inside a contract and name it

```
pragma solidity ^0.5.0;


contract firstClassContract{
    string private stringVariable = "Variable name";
    int private unsignedInteger = 10;

    function setStringVariable(string memory newVariable) public {
        stringVariable = newVariable;
    }

    function getStringVariable() public view returns (string memory){
        return stringVariable;
    }

}
```

# Why do I need to tell it explicitly that it is a memory variable if I know that a function can't create a storage variable?

Because there is a third place in the Ethereum Virtual Machine where variables can be stored, it is the stack, it is the cheapest storage but is the smallest of the 3. You want to use it when you know for sure the size of your variable.

You can read a more in depth look at data sizes in
https://blog.zeppelin.solutions/ethereum-in-depth-part-2-6339cf6bddb9

But in short, stack items have a size of 256bits

This is more lower level stuff but I highly recommend you to read about lower level Ethereum development. In my tutorials I will cover lower level stuff the most I can but I might miss something (I was never good at computer architecture and operating systems at college)

# How to deploy and test (FOR FREE)

I have been writing so far with the Visual Studio code for systax highlight (makes development much easier), the code looks like
![](https://cdn.steemitimages.com/DQmRztivsdKhtggu4G898etH8w5fY6Evo3jCJ47E7cPAPNo/image.png)

Here is how to test it on Remix

Paste the code inside the browser IDE

![](https://cdn.steemitimages.com/DQmQq2hnrrvMeyGiPpmF42Pakeum4RqZDToQaZFi7pmJScz/image.png)

On the right side of the screen click on Start to compile
![](https://cdn.steemitimages.com/DQmTe2zPD4vzwyrEjDKhmTBhPsck94meNtm9DPTcX18muKG/image.png)

Set the environment to JavaScript VM and click on the pink button that says deploy

![](https://cdn.steemitimages.com/DQmPtAP5wnwTUJofzj6i5EyG2e8zXpC6GCGh6rScBAcToX1/image.png)

If you don't do the above you will automatically use the Ethereum blockchain and will have to spend Ether to pay for real transactions.

Then below we can see and interact with the deployed contracts

![](https://cdn.steemitimages.com/DQmTrzrNR9NnajEgaKdGNTco1FhUAkNos78fS1cBTA3XEcC/image.png)
πŸ‘  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
post_id68,135,959
authorigormuba
permlinkpart-1-ethereum-solidity-development-getting-started-lower-level-explanation-pt-1
categoryutopian-io
json_metadata{"links":["https:\/\/github.com\/igormuba\/EthereumSolidityClass\/tree\/master","https:\/\/metamask.io\/","https:\/\/code.visualstudio.com\/","http:\/\/remix.ethereum.org\/","https:\/\/solidity.readthedocs.io\/en\/v0.5.0\/050-breaking-changes.html","https:\/\/medium.com\/coinmonks\/ethereum-solidity-memory-vs-storage-which-to-use-in-local-functions-72b593c3703a","https:\/\/blog.zeppelin.solutions\/ethereum-in-depth-part-2-6339cf6bddb9"],"format":"markdown","image":["https:\/\/cdn.steemitimages.com\/DQmRMcGN8XUGVjyP8Sr25eGXqP7uLCug2mPKB61GdDB5uDq\/image.png"],"app":"steemit\/0.1","tags":["utopian-io","tutorials","ethereum","solidity","remix"]}
created2018-12-30 22:49:27
last_update2018-12-30 22:49:27
depth0
children4
net_rshares45,990,848,081,182
last_payout2019-01-06 22:49:27
cashout_time1969-12-31 23:59:59
total_payout_value19.493 SBD
curator_payout_value6.305 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length6,783
author_reputation79,636,306,810,404
root_title"(Part 1) Ethereum Solidity Development - Getting Started + Lower Level Explanation (PT 1)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (47)
@portugalcoin ·
$12.82
Thank you for your contribution @igormuba.
We have been analyzing your tutorial and we suggest the following points:

- We suggest that you use comments in the sections of your code. Comments are very important for readers to understand well what you are developing.

This tutorial is very interesting thanks for your work in constructing this tutorial.

Happy New Year :)

Your contribution has been evaluated according to [Utopian policies and guidelines](https://join.utopian.io/guidelines), as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, [click here](https://review.utopian.io/result/8/2-1-1-1-1-3-1-3-).

---- 
Need help? Write a ticket on https://support.utopian.io/. 
Chat with us on [Discord](https://discord.gg/uTyJkNm). 
[[utopian-moderator]](https://join.utopian.io/)
πŸ‘  , , , , , , , , , , , , ,
properties (23)
post_id68,207,897
authorportugalcoin
permlinkre-igormuba-part-1-ethereum-solidity-development-getting-started-lower-level-explanation-pt-1-20190101t121556669z
categoryutopian-io
json_metadata{"app":"steemit\/0.1","users":["igormuba"],"tags":["utopian-io"],"links":["https:\/\/join.utopian.io\/guidelines","https:\/\/review.utopian.io\/result\/8\/2-1-1-1-1-3-1-3-","https:\/\/support.utopian.io\/","https:\/\/discord.gg\/uTyJkNm","https:\/\/join.utopian.io\/"]}
created2019-01-01 12:15:57
last_update2019-01-01 12:15:57
depth1
children1
net_rshares22,768,202,579,271
last_payout2019-01-08 12:15:57
cashout_time1969-12-31 23:59:59
total_payout_value9.700 SBD
curator_payout_value3.116 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length872
author_reputation214,343,891,436,406
root_title"(Part 1) Ethereum Solidity Development - Getting Started + Lower Level Explanation (PT 1)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (14)
@utopian-io ·
Thank you for your review, @portugalcoin! Keep up the good work!
properties (22)
post_id68,303,018
authorutopian-io
permlinkre-re-igormuba-part-1-ethereum-solidity-development-getting-started-lower-level-explanation-pt-1-20190101t121556669z-20190103t135107z
categoryutopian-io
json_metadata{"app":"beem\/0.20.9"}
created2019-01-03 13:51:09
last_update2019-01-03 13:51:09
depth2
children0
net_rshares0
last_payout2019-01-10 13:51:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length64
author_reputation152,913,012,544,965
root_title"(Part 1) Ethereum Solidity Development - Getting Started + Lower Level Explanation (PT 1)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@steem-ua ·
#### Hi @igormuba!

Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!
Your post is eligible for our upvote, thanks to our collaboration with @utopian-io!
**Feel free to join our [@steem-ua Discord server](https://discord.gg/KpBNYGz)**
properties (22)
post_id68,212,537
authorsteem-ua
permlinkre-part-1-ethereum-solidity-development-getting-started-lower-level-explanation-pt-1-20190101t141632z
categoryutopian-io
json_metadata{"app":"beem\/0.20.14"}
created2019-01-01 14:16:33
last_update2019-01-01 14:16:33
depth1
children0
net_rshares0
last_payout2019-01-08 14:16:33
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length287
author_reputation23,203,609,903,979
root_title"(Part 1) Ethereum Solidity Development - Getting Started + Lower Level Explanation (PT 1)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
@utopian-io ·
Hey, @igormuba!

**Thanks for contributing on Utopian**.
We’re already looking forward to your next contribution!

**Get higher incentives and support Utopian.io!**
 Simply set @utopian.pay as a 5% (or higher) payout beneficiary on your contribution post (via [SteemPlus](https://chrome.google.com/webstore/detail/steemplus/mjbkjgcplmaneajhcbegoffkedeankaj?hl=en) or [Steeditor](https://steeditor.app)).

**Want to chat? Join us on Discord https://discord.gg/h52nFrV.**

<a href='https://steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1'>Vote for Utopian Witness!</a>
properties (22)
post_id68,222,137
authorutopian-io
permlinkre-part-1-ethereum-solidity-development-getting-started-lower-level-explanation-pt-1-20190101t185307z
categoryutopian-io
json_metadata{"app":"beem\/0.20.9"}
created2019-01-01 18:53:09
last_update2019-01-01 18:53:09
depth1
children0
net_rshares0
last_payout2019-01-08 18:53:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 SBD
curator_payout_value0.000 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length590
author_reputation152,913,012,544,965
root_title"(Part 1) Ethereum Solidity Development - Getting Started + Lower Level Explanation (PT 1)"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000