{"id":37299,"date":"2020-01-24T13:28:11","date_gmt":"2020-01-24T13:28:11","guid":{"rendered":"https:\/\/blockonomi.com\/?p=37299"},"modified":"2020-04-16T13:11:48","modified_gmt":"2020-04-16T13:11:48","slug":"solidity-tutorial","status":"publish","type":"post","link":"https:\/\/blockonomi.com\/solidity-tutorial\/","title":{"rendered":"Solidity Tutorial: An Introduction to Solidity Programming for Beginners"},"content":{"rendered":"<p><a href=\"https:\/\/blockonomi.com\/solidity-guide\/\">Solidity<\/a> is an object-oriented, high-level language for developing dApps (Decentralized applications), on the <a href=\"https:\/\/blockonomi.com\/ethereum-guide\/\">Ethereum blockchain<\/a>.<\/p>\n<p>A blockchain is a peer-to-peer network of computers, called nodes, that share all the data and the code in the network.<\/p>\n<p>So, if you\u2019re a device connected to the blockchain, you are a node in the network, and you talk to all the other computer nodes in the network (we will talk how to setup Ethereum node on your local machine in later tutorials).<\/p>\n<p>You now have a copy of all the data and the code on the blockchain. There are no need for central servers anymore.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"What_is_Ethereum\"><\/span>What is Ethereum?<span class=\"ez-toc-section-end\"><\/span><\/h2><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/#What_is_Ethereum\" >What is Ethereum?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/#Starting_with_the_basics\" >Starting with the basics<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/#Remix_IDE\" >Remix IDE<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/#How_to_type_functions\" >How to type functions?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/#How_to_learn_Solidity\" >How to learn Solidity?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/#Opcodes\" >Opcodes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>At its simplest, Ethereum is an open software platform based on blockchain technology that enables developers to build and deploy decentralized applications.<\/p>\n<p>While the Bitcoin blockchain is used to track ownership of digital currency (bitcoins), the Ethereum blockchain focuses on running the code of decentralized applications.<\/p>\n<p>In the Ethereum blockchain, instead of mining for bitcoin, miners work to earn <a href=\"https:\/\/blockonomi.com\/ethereum-price\/\">Ether<\/a>, a type of crypto token that fuels the network. Beyond a tradeable cryptocurrency, Ether is also used by application developers to pay for transaction fees and services on the Ethereum network.<\/p>\n<p>There is a second type of token that is used to pay miners fees for including transactions in their block, it is called gas, and every smart contract execution requires a certain amount of gas to be sent along with it to entice miners to put it in the blockchain.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Starting_with_the_basics\"><\/span>Starting with the basics<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Solidity&#8217;s code is encapsulated in contracts.<\/p>\n<p>Ethereum blockchain allows us to execute code with the Ethereum Virtual Machine (EVM) on the blockchain with something called a smart contract.<\/p>\n<p>Smart contracts are where all the business logic of our application lives &#8211; all variables and functions belong to a contract, and this will be the starting point of all your projects.<\/p>\n<p>Smart contacts are written in a programming language called Solidity, which looks like a mix of Javascript and C.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Remix_IDE\"><\/span>Remix IDE<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Remix is online tool that allows you to write Solidity smart contracts, then deploy them and run it.<\/p>\n<p>Just go to <a href=\"https:\/\/remix.ethereum.org\">https:\/\/remix.ethereum.org<\/a> from your browser and we can start coding.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-37300\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/1.png\" alt=\"\" width=\"1004\" height=\"627\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/1.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/1-300x187.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/1-768x480.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/1-50x31.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>As you can see, you can choose between Solidity and Vyper. Both are languages for writing smart contracts, Vyper is python-like and Solidity is javascript-like.<\/p>\n<p>Both can compile to the EVM bytecode, kinda like Javascript and Typescript. We are choosing Solidity.<\/p>\n<p>On the left side there\u2019s file explorer. By default, there are two .sol files, just to demo basic syntax (ballot.sol is smart contract, ballot_test.sol is script for testing that smart contract).<\/p>\n<p>You just need to click that plus button and we can start coding our first smart contract.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-37301\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/2.png\" alt=\"\" width=\"1004\" height=\"654\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/2.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/2-300x195.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/2-768x500.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/2-50x33.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>All solidity source code should start with a &#8220;version pragma&#8221; \u2014 a declaration of the version of the Solidity compiler this code should use. This is to prevent issues with future compiler versions potentially introducing changes that would break your code.<\/p>\n<p>It looks like this:<\/p>\n<pre><code>pragma solidity ^0.4.25;\r\n<\/code><\/pre>\n<p>(for the Solidity version above 0.4.25)<\/p>\n<p>or<\/p>\n<pre><code>pragma solidity &gt;= 0.5.0 &lt; 0.6.0;\r\n<\/code><\/pre>\n<p>(for the Solidity version between 0.5.0 and 0.6.0)<\/p>\n<p>Then you create your contract by typing reserved word <strong>contract<\/strong> and the name of your .sol file (It is important to contract name match the name of the file, we will discuss why later). In our case,<\/p>\n<pre><code>contract MyFirstContract {\r\n    \r\n}\r\n<\/code><\/pre>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-37463\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/3-1.png\" alt=\"\" width=\"1004\" height=\"654\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/3-1.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/3-1-300x195.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/3-1-768x500.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/3-1-50x33.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Let\u2019s compile it. You just need to navigate to that compile tab on the left and click the big compile button. If something is wrong with the code you will see errors and warnings here (be compassionate with Solidity, it is still \u201cyoung language\u201d).<\/p>\n<p>With our current contract everything is fine because we really haven\u2019t done anything.<\/p>\n<p>Now I will generate error on purpose just to show you something. You can manually select compiler from that drop down menu.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37464\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture4.png\" alt=\"\" width=\"1004\" height=\"664\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture4.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture4-300x198.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture4-768x508.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture4-50x33.png 50w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture4-270x180.png 270w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture4-370x245.png 370w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Let\u2019s choose for example 0.4.26 version. Now, compile it again. Now you will see a \u2018Compiler not yet loaded\u2019 error.<\/p>\n<p>This is because we specified with pragma to work with compiler versions above 0.5.0. Just change compiler version again, and the error will be gone.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37465\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture5.png\" alt=\"\" width=\"1004\" height=\"652\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture5.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture5-300x195.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture5-768x499.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture5-50x32.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Okay, let\u2019s code now!<\/p>\n<p>We will start with simple \u2018Hello world\u2019 code and <em>get<\/em> and <em>set<\/em> functions, just to get more familiar with the syntax.<\/p>\n<p>A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain.<\/p>\n<p>First, let\u2019s define state variable called <em>message<\/em> for example and its type will be string.<\/p>\n<p>Our <em>get<\/em> function will return the value of our variable <em>message<\/em>, and <em>set<\/em> function will assign a new value to our variable <em>message<\/em>.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_type_functions\"><\/span>How to type functions?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>First, reserved word <strong>function <\/strong>then the name of particular function and parameters and after that &lt;visibility specifiers&gt;.<\/p>\n<pre><code>function myFunction()  returns (bool) {\r\n    return true;\r\n}\r\n<\/code><\/pre>\n<p>Functions can be <strong>public<\/strong> or <strong>private. <\/strong>If a function is public it can be called outside of contract. If a function is private it has a limited scope, and can be called only from its current contract (from some other function for example).<\/p>\n<p>Here is the list of all Function Visibility Specifiers:<\/p>\n<ul>\n<li><strong>public<\/strong>: visible externally and internally (creates a getter function for storage\/state variables)<\/li>\n<li><strong>private<\/strong>: only visible in the current contract<\/li>\n<li><strong>external<\/strong>: only visible externally (only for functions) &#8211; i.e. can only be message-called (via this.func)<\/li>\n<li><strong>internal<\/strong>: only visible internally<\/li>\n<\/ul>\n<p>Functions can be <strong>pure<\/strong>, <strong>view<\/strong>, or <strong>payable<\/strong>. If a function does not write any data on blockchain it is very recommended to be view, because view functions do not cost any gas.<\/p>\n<p>Here is the list of all Function Modifiers (there\u2019s also modifiers for state variables, events and events arguments but it will talk about them later):<\/p>\n<ul>\n<li><strong>pure<\/strong>: Disallows modification or access of state.<\/li>\n<li><strong>view<\/strong>: Disallows modification of state.<\/li>\n<li><strong>payable<\/strong>: Allows them to receive Ether together with a call.<\/li>\n<\/ul>\n<p>If Function returns some value you need to specify that with reserved word <strong>returns<\/strong> and then in regular brackets to specify which type does function returns. In our case it will be string (because we return our variable <em>message<\/em> which is string)<\/p>\n<p>If the Function does not return any value, there\u2019s no need for <strong>returns <\/strong>statement.<\/p>\n<p>To access a state variable, you do not need the prefix <strong>this.<\/strong> as is common in other languages.<\/p>\n<p>Because of that, a common practice is to write function arguments with underscore syntax <strong><em>(_message). <\/em><\/strong>This\u00a0 convention came from Javascript, where private methods and variables starts with _.<\/p>\n<p>To be clear, your code will work fine and without underscores, but it\u2019s cleaner with them.<\/p>\n<p>You will notice reserved word <strong>memory <\/strong>in our code. If you write our code without memory, and set pragma to some version under 0.5.* it will work just fine, but when you change your compiler to above 0.5.* EVM generates compile error.<\/p>\n<p>Why does this happen?<\/p>\n<p>Well, The Ethereum Virtual Machine has three areas where it can store items.<\/p>\n<ul>\n<li>The first is <strong>storage<\/strong>, where all the contract state variables reside. Every contract has its own storage and it is persistent between function calls and quite expensive to use.<\/li>\n<li>The second is <strong>memory<\/strong>, this is used to hold temporary values. It is erased between (external) function calls and is cheaper to use.<\/li>\n<li>The third one is the <strong>stack<\/strong>, which is used to hold small local variables. It is almost free to use, but can only hold a limited amount of values.<\/li>\n<\/ul>\n<p>For almost all types, you cannot specify where they should be stored, because they are copied every time they are used.<\/p>\n<p>But when you work with arrays or structs, and from latest versions with strings also, compiler will force you to specify store area.<\/p>\n<p>So, our code now looks like this:<\/p>\n<pre><code>pragma solidity ^0.5.0;\r\n\r\ncontract MyFirstContract {\r\n    string message;\r\n    \r\n    function get() public view returns(string memory) {\r\n        return message;\r\n    }\r\n    \r\n    function set(string memory _message) public {\r\n        message = _message;\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Please note that some Solidity developers break those visibility specifiers into separate lines in order to make code cleaner. So our <em>get<\/em> function can be written like this:<\/p>\n<pre><code>function get()\r\n\tpublic\r\n\tview\r\n\treturns(string)\r\n{\r\n\treturn message;\r\n}\r\n<\/code><\/pre>\n<p>It\u2019s really up to you how you choose to write your functions.<\/p>\n<p>Let\u2019s compile our contract now and test it.<\/p>\n<p>To compile it just repeat the steps from below (<strong><em>Compile &lt;nameOfContract&gt;.sol<\/em><\/strong> button or <strong><em>cmd\/ctrl + S<\/em><\/strong> from keyboard and it will recompile it automatically)<\/p>\n<p>To actually see how it works (if compiling does not generate errors) you need to Deploy your contract.<\/p>\n<p>To do that, navigate to that Deployment tab from left, for environment select JavaScriptVM and hit Deploy button.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37466\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture6.png\" alt=\"\" width=\"1004\" height=\"656\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture6.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture6-300x196.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture6-768x502.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture6-50x33.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>After deployment, we can now see methods from our contract. Let\u2019s focus just on that part of screen now.<\/p>\n<p>You can see that there\u2019s two buttons (get &amp; set) for our two public functions. If any of those was private we would not see it here.<\/p>\n<p>If we click get button EVM will execute our <em>get<\/em> function.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37467\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture7.png\" alt=\"\" width=\"1004\" height=\"628\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture7.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture7-300x188.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture7-768x480.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture7-50x31.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Let\u2019s see how it worked out.<\/p>\n<p>We\u2019ve got empty string. Not great, not terrible. But, why? Well because we didn\u2019t initialize our <em>message<\/em> variable at first place.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37468\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture8.png\" alt=\"\" width=\"1004\" height=\"653\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture8.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture8-300x195.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture8-768x500.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture8-50x33.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Just one quick pause. I want you to introduce to the Remix Terminal. It\u2019s under code editor and here you can track all your transactions, to see if they are successfully executed or not, to debug them, see details (transaction hash etc.) and more.<\/p>\n<p>For now, we have two successful transactions. One is Contract Deployment and it costs us ether (but don\u2019t worry, we are in editor now everything is virtual) and second is Call of our <strong><em>view<\/em><\/strong> function.<\/p>\n<p>Ok, let\u2019s go back now. What will happen if we call<em> set <\/em>function now?<\/p>\n<p>We need to pass an argument _message (\u201cHello World\u201d for example) and hit transact button to execute function. You can track success of transaction in Terminal.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37469 aligncenter\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture9.png\" alt=\"\" width=\"688\" height=\"641\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture9.png 688w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture9-300x280.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture9-50x47.png 50w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/>Now let\u2019s call <em>get <\/em>function again. Now it returns our <em>message<\/em>.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37470 aligncenter\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture10.png\" alt=\"\" width=\"688\" height=\"520\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture10.png 688w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture10-300x227.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture10-50x38.png 50w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture10-87x67.png 87w\" sizes=\"(max-width: 688px) 100vw, 688px\" \/><\/p>\n<p>Let\u2019s make some improvements to our code. We didn\u2019t initialize our variable <em>message<\/em>. Let\u2019s do this.<\/p>\n<pre><code>contract MyFirstContract {\r\n    string message = \"Hello world!\";\r\n    \r\n    function get() public view returns(string memory) {\r\n        return message;\r\n    }\r\n    \r\n    function set(string memory _message) public {\r\n        message = _message;\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>Notice that message is now \u201cHello world!\u201d, and when we call <em>get <\/em>function for the first time it won\u2019t return empty string.<\/p>\n<p>To test this, we need to compile our contract (cmd\/ctrl + S).<\/p>\n<p>Then to deploy it again. We need to create a new instance of contract (because of the changes we made) and publish that on blockchain.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37472\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture11.png\" alt=\"\" width=\"1004\" height=\"653\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture11.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture11-300x195.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture11-768x500.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture11-50x33.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Just delete previous version from editor (not from our virtual blockchain of course) and hit Deploy button again. Let\u2019s call our <em>get <\/em>function now.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37473 aligncenter\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture12.png\" alt=\"\" width=\"678\" height=\"568\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture12.png 678w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture12-300x251.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture12-50x42.png 50w\" sizes=\"(max-width: 678px) 100vw, 678px\" \/><\/p>\n<p>Nice! Let\u2019s call <em>set <\/em>function now.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37474 aligncenter\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture13.png\" alt=\"\" width=\"738\" height=\"580\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture13.png 738w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture13-300x236.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture13-50x39.png 50w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture13-87x67.png 87w\" sizes=\"(max-width: 738px) 100vw, 738px\" \/><\/p>\n<p>And <em>get<\/em> again.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37475 aligncenter\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture14.png\" alt=\"\" width=\"739\" height=\"574\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture14.png 739w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture14-300x233.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture14-50x39.png 50w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture14-87x67.png 87w\" sizes=\"(max-width: 739px) 100vw, 739px\" \/><\/p>\n<p>Cool.<\/p>\n<p>Let\u2019s now make our <em>message<\/em> a <strong>constant<\/strong>.<\/p>\n<p>Our code now:<\/p>\n<pre><code>pragma solidity ^0.5.0;\r\n\r\ncontract MyFirstContract {\r\n    string constant message = \"Hello world!\";\r\n    \r\n    function get() public view returns(string memory) {\r\n        return message;\r\n    }\r\n    \r\n    function set(string memory _message) public {\r\n        message = _message;\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>When we try to compile it, we get error in our <em>set<\/em> function. That\u2019s because one can not change a value of a constant.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37476\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture15.png\" alt=\"\" width=\"1004\" height=\"652\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture15.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture15-300x195.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture15-768x499.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture15-50x32.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>We will just get rid of that constant now.<\/p>\n<p>To initialize variables like this is not an error, but it is much better if we do that in constructor. You can write constructor in Solidity with:<\/p>\n<pre><code>constructor() public {\r\n \/\/ do something\u2026\r\n}<\/code><\/pre>\n<p>Constructor is just another function which is being called during deployment of smart contract. Our code looks a little bit different, but it works same.<\/p>\n<pre><code>pragma solidity ^0.5.0;\r\n\r\ncontract MyFirstContract {\r\n    string message;\r\n    \r\n    constructor() public {\r\n        message = \"Hello world!\";\r\n    }\r\n    \r\n    function get() public view returns(string memory) {\r\n        return message;\r\n    }\r\n    \r\n    function set(string memory _message) public {\r\n        message = _message;\r\n    }\r\n}<\/code><\/pre>\n<p>You can compile it again and test it if you want.<\/p>\n<p>Finally, one can change visibility of state variables. If you make your state variables <strong>public <\/strong>that means that one can claim their values from outside the contract.<\/p>\n<p>Solidity will make for each public state variable a method with same name which can be called as a regular function (kinda like getter function).<\/p>\n<p>This means, that we can get rid of our <em>get <\/em>function, just declare variable<em> message <\/em>as <strong>public, <\/strong>and our code will work the same, it will be much cleaner and it will costs us less to deploy it one day to Main Network.<\/p>\n<p>The bigger the code, the more gas is needed to execute it and the cost of running our dApp is increases.<\/p>\n<p>When we develop smart contracts we need to be:<\/p>\n<ul>\n<li><strong>efficient <\/strong>&#8211; gas rate consumed needs to be low<\/li>\n<li><strong>precise<\/strong> &#8211; once you deploy smart contract it can not be changed and it is public 24\/7h, every single line of code ( imagine a hacker who finds a bug and can exploit your dApp)<\/li>\n<\/ul>\n<p>Our final code for today looks like this:<\/p>\n<pre><code>pragma solidity ^0.5.0;\r\n\r\ncontract MyFirstContract {\r\n    string public message;\r\n    \r\n    constructor() public {\r\n        message = \"Hello world!\";\r\n    }\r\n    \r\n    function set(string memory _message) public {\r\n        message = _message;\r\n    }\r\n}<\/code><\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37477\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture16.png\" alt=\"\" width=\"1004\" height=\"659\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture16.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture16-300x197.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture16-768x504.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture16-50x33.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Let\u2019s deploy it and test it.<\/p>\n<p>You can see that message button. It is being created because our state variable <em>message<\/em> is public.<\/p>\n<p>If we call that, it should returns us a value that is being initialized through constructor (that\u2019s \u201cHello world!\u201d).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37478 aligncenter\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture17.png\" alt=\"\" width=\"544\" height=\"559\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture17.png 544w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture17-292x300.png 292w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture17-50x50.png 50w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/p>\n<p>Nice. Let\u2019s test <em>set<\/em> function now.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-37479 aligncenter\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture18.png\" alt=\"\" width=\"544\" height=\"604\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture18.png 544w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture18-270x300.png 270w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture18-45x50.png 45w\" sizes=\"(max-width: 544px) 100vw, 544px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_learn_Solidity\"><\/span>How to learn Solidity?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Solidity itself is pretty simple language, but to be a good Solidity developer one needs to understand how everything works on Ethereum.<\/p>\n<ul>\n<li>Solidity is high-level programming language with syntax similar to ECMAScript (javascript).<\/li>\n<li>It compiles to EVM bytecode,\u00a0 something only the EVM can understand.<\/li>\n<li>The Compiler is called Solc.<\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37480\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture19.png\" alt=\"\" width=\"1004\" height=\"462\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture19.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture19-300x138.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture19-768x353.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture19-50x23.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>Let\u2019s take this simple contract as example:<\/p>\n<pre><code>pragma solidity ^0.5.0;\r\n\r\ncontract Example {\r\n    uint a = 10 + 5;\r\n}<\/code><\/pre>\n<p>Simple as that. Now let\u2019s compile it. If we go to Contract Details in Terminal we can see a lot of information.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-37481\" src=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture20.png\" alt=\"\" width=\"1004\" height=\"628\" srcset=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture20.png 1004w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture20-300x188.png 300w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture20-768x480.png 768w, https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/Picture20-50x31.png 50w\" sizes=\"(max-width: 1004px) 100vw, 1004px\" \/><\/p>\n<p>In this case, the compiled code is:<\/p>\n<pre><code>0x6080604052600f600055348015601457600080fd5b5060358060226000396000f3fe6080604052600080fdfea165627a7a72305820bf75c57b7d8745a79baee513ead21a9eb8b075896f8e4c591c8916574d317c750029<\/code><\/pre>\n<p>These long values are hexadecimal representation of the final contract, also known as bytecode. EVM only understands bytecode.<\/p>\n<p>But, if something goes wrong, we get stuck with some error for example, one can not debug bytecode.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Opcodes\"><\/span>Opcodes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Language above bytecode is opcode. Opcode is low-level programming language. Solidity and Opcode are like C and Assembly Language for example.<\/p>\n<p>So when we need to debug some failed transaction, we debug opcode.<\/p>\n<p>One thing you should know about Solidity and debugging &#8211; it\u2019s very hard. But not impossible, so let\u2019s dive into it.<\/p>\n<p>This is opcode of our Example contract:<\/p>\n<pre><code>0 PUSH1 60\r\n02 PUSH1 40\r\n04 MSTORE\r\n05 PUSH1 0f\r\n07 PUSH1 00\r\n09 SSTORE\r\n10 CALLVALUE\r\n11 DUP1\r\n12 ISZERO\r\n13 PUSH1 14\r\n15 JUMPI\r\n16 PUSH1 00\r\n18 DUP1\r\n19 REVERT\r\n20 JUMPDEST\r\n21 POP\r\n22 PUSH1 35\r\n24 DUP1\r\n25 PUSH1 22\r\n27 PUSH1 00\r\n29 CODECOPY\r\n30 PUSH1 00\r\n32 RETURN\r\n33 INVALID\r\n34 PUSH1 80\r\n36 PUSH1 40\r\n38 MSTORE\r\n39 PUSH1 00\r\n41 DUP1\r\n42 REVERT\r\n43 INVALID\r\n44 LOG1\r\n45 PUSH6 627a7a723058\r\n52 SHA3\r\n53 INVALID\r\n54 PUSH22 c57b7d8745a79baee513ead21a9eb8b075896f8e4c59\r\n77 INVALID\r\n78 DUP10\r\n79 AND\r\n80 JUMPI\r\n81 INVALID\r\n82 BALANCE\r\n83 PUSH29 750029<\/code><\/pre>\n<p>Opcodes are the low level human readable instructions of the program. All opcodes have their hexadecimal counterparts, eg <strong>MSTORE<\/strong> is <strong>0x52<\/strong>.<\/p>\n<p>The EVM is Stack Machine. It is based on LIFO structure (Last In First Out). To simplify, imagine stacking up slices of bread in a microwave, the LAST slice you put in is the FIRST one you take out.<\/p>\n<p>In normal arithmetic, we write our equation this way:<\/p>\n<p><strong>10 + 2 * 2<\/strong><\/p>\n<p>and the Answer is 14, because we do multiplication before addition.<\/p>\n<p>In a stack machine, it works in LIFO principle:<\/p>\n<p><strong>2 2 * 10 +<\/strong><\/p>\n<p>It means, put 2 in the stack first, followed by another 2, then followed by multiplication action. The result is 4 sitting on top of the stack. Now add a number 10 on top of 4 and eventually add the 2 numbers together. The final value of the stack becomes 14.<\/p>\n<p>The act of putting data in the stack is called the PUSH instruction and the act of removing data from the stack is called the POP instruction. It&#8217;s obvious that the most common opcode we see in our example above is PUSH1 which means putting 1 byte of data into the stack.<\/p>\n<p>So, this instruction:<\/p>\n<p>PUSH1 0x60<\/p>\n<p>means putting a 1 byte value of \u201c0x60\u201d in the stack. Coincidentally, the hexadecimal value for PUSH1 happens to be \u201c0x60\u201d as well. Removing the non-compulsory \u201c0x\u201d, we could write this logic in bytecode as \u201c6060\u201d.<\/p>\n<p>Let us go a bit further.<\/p>\n<p>PUSH1 0x60 PUSH1 0x40 MSTORE<\/p>\n<p>The MSTORE (0x52) takes in 2 inputs and produces no output. The opcodes above mean:<\/p>\n<p><strong>PUSH1 (0x60)<\/strong>: put 0x60 in the stack.<\/p>\n<p><strong>PUSH1 (0x40)<\/strong>: put 0x40 in the stack.<\/p>\n<p><strong>MSTORE (0x52)<\/strong>: allocate 0x60 of memory space and move to the 0x40 position.<\/p>\n<p>The resulting bytecode is:<\/p>\n<p><strong>6060604052<\/strong><\/p>\n<p>In fact, we always see this magic number \u201c6060604052\u201d in the beginning of any solidity bytecode because its how the smart contract bootstrap.<\/p>\n<p>To further complicate the matter, 0x40 or 0x60 cannot be interpreted as the real number 40 or 60. Since they are hexadecimal, 40 actually equates to 64 (16\u00b9 x 4) and 60 equates to 96 (16\u00b9 x 6) in decimal.<\/p>\n<p>In short, what \u201cPUSH1 0x60 PUSH1 0x40 MSTORE\u201d is doing is allocating 96 bytes of memory and moving the pointer to the beginning of the 64th byte. We now have 64 bytes for scratch space and 32 bytes for temporary memory storage.<\/p>\n<p>In the EVM, there are 3 places to store data. Firstly, in the stack. We\u2019ve just used the PUSH opcode to store data there as per the example above.<\/p>\n<p>Secondly in the memory (RAM) where we use the MSTORE opcode and lastly, in the disk storage where we use SSTORE to store the data. The gas required to store data to storage is the most expensive and storing data to stack is the cheapest.<\/p>\n<p>Now it\u2019s good time to go back to our Solidity code from this tutorial and to recap what we learned about reserved word <strong>memory <\/strong>and how compiler forces us to specify how we store strings, for example.<\/p>\n<p>We have only covered the basics of bytecode and a few opcodes.<\/p>\n<p><strong>We don\u2019t need to know opcodes to start writing smart contract!<\/strong><\/p>\n<p>On the other hand, the EVM error handling is still very primitive and its handy to look at opcodes when things go wrong.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>This first lesson have a bit more theory than actual coding, but it is very important for beginners to know how things work on Ethereum. In the next tutorials, we will write some more interesting code and learn how to deploy our own token on the Ethereum blockchain.<\/p>\n<p>Until then \ud83d\udc4b<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Solidity is an object-oriented, high-level language for developing dApps (Decentralized applications), on the Ethereum blockchain. A blockchain is a peer-to-peer network of computers, called nodes, that share all the data and the code in the network. So, if you\u2019re a device connected to the blockchain, you are a node in the network, and you talk<\/p>\n","protected":false},"author":32,"featured_media":37484,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14],"tags":[6053,5776,5775,5774],"class_list":{"0":"post-37299","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-education","8":"tag-education-featured","9":"tag-solidity-introduction","10":"tag-solidity-programming","11":"tag-solidity-tutorial"},"wppr_data":{"cwp_meta_box_check":"No"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Solidity Tutorial: An Introduction to Solidity Programming for Beginners<\/title>\n<meta name=\"description\" content=\"An introduction to the Solidity programming language for creating smart contracts on Ethereum - Sample code to get you started.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blockonomi.com\/solidity-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Solidity Tutorial: An Introduction to Solidity Programming for Beginners\" \/>\n<meta property=\"og:description\" content=\"An introduction to the Solidity programming language for creating smart contracts on Ethereum - Sample code to get you started.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blockonomi.com\/solidity-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Blockonomi\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/blockonomi\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-24T13:28:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-04-16T13:11:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1400\" \/>\n\t<meta property=\"og:image:height\" content=\"933\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Andrej Rakic\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@blockonomi\" \/>\n<meta name=\"twitter:site\" content=\"@blockonomi\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Andrej Rakic\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/\"},\"author\":{\"name\":\"Andrej Rakic\",\"@id\":\"https:\/\/blockonomi.com\/#\/schema\/person\/6de37845aeb3041e7ee9b2bcd9113873\"},\"headline\":\"Solidity Tutorial: An Introduction to Solidity Programming for Beginners\",\"datePublished\":\"2020-01-24T13:28:11+00:00\",\"dateModified\":\"2020-04-16T13:11:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/\"},\"wordCount\":2838,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/blockonomi.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg\",\"keywords\":[\"education-featured\",\"Solidity Introduction\",\"Solidity Programming\",\"Solidity Tutorial\"],\"articleSection\":[\"Education\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/blockonomi.com\/solidity-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/\",\"url\":\"https:\/\/blockonomi.com\/solidity-tutorial\/\",\"name\":\"Solidity Tutorial: An Introduction to Solidity Programming for Beginners\",\"isPartOf\":{\"@id\":\"https:\/\/blockonomi.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg\",\"datePublished\":\"2020-01-24T13:28:11+00:00\",\"dateModified\":\"2020-04-16T13:11:48+00:00\",\"description\":\"An introduction to the Solidity programming language for creating smart contracts on Ethereum - Sample code to get you started.\",\"breadcrumb\":{\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/blockonomi.com\/solidity-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage\",\"url\":\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg\",\"contentUrl\":\"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg\",\"width\":1400,\"height\":933,\"caption\":\"Solidity Tutorial: An Introduction to Solidity Programming for Beginners\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/blockonomi.com\/solidity-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/blockonomi.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Solidity Tutorial: An Introduction to Solidity Programming for Beginners\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/blockonomi.com\/#website\",\"url\":\"https:\/\/blockonomi.com\/\",\"name\":\"Blockonomi\",\"description\":\"Cryptocurrency News &amp; Your Guide to the Blockchain Economy\",\"publisher\":{\"@id\":\"https:\/\/blockonomi.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/blockonomi.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/blockonomi.com\/#organization\",\"name\":\"Blockonomi\",\"url\":\"https:\/\/blockonomi.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blockonomi.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/blockonomi.com\/wp-content\/uploads\/2018\/07\/blockonomi-logo-1.png\",\"contentUrl\":\"https:\/\/blockonomi.com\/wp-content\/uploads\/2018\/07\/blockonomi-logo-1.png\",\"width\":800,\"height\":127,\"caption\":\"Blockonomi\"},\"image\":{\"@id\":\"https:\/\/blockonomi.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"http:\/\/facebook.com\/blockonomi\",\"https:\/\/x.com\/blockonomi\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/blockonomi.com\/#\/schema\/person\/6de37845aeb3041e7ee9b2bcd9113873\",\"name\":\"Andrej Rakic\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/blockonomi.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/2613389519d5c8f115b49e8f67f0655d0f5bca5a276a401fa3f3d3dc82993bd6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/2613389519d5c8f115b49e8f67f0655d0f5bca5a276a401fa3f3d3dc82993bd6?s=96&d=mm&r=g\",\"caption\":\"Andrej Rakic\"},\"description\":\"Lead Blockchain Developer at Blockchain Systems. Bachelor of Engineering, Computer Science at Faculty of Electrical Engineering in Nis. Graduate of Blockchain Academy (powered by European Blockchain Hub). My hobbies are traveling &amp; vlogging. https:\/\/github.com\/TheRealRichardHendricks\",\"sameAs\":[\"https:\/\/www.medium.com\/@andrej.rakic\"],\"url\":\"https:\/\/blockonomi.com\/author\/andrej-rakic\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Solidity Tutorial: An Introduction to Solidity Programming for Beginners","description":"An introduction to the Solidity programming language for creating smart contracts on Ethereum - Sample code to get you started.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blockonomi.com\/solidity-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Solidity Tutorial: An Introduction to Solidity Programming for Beginners","og_description":"An introduction to the Solidity programming language for creating smart contracts on Ethereum - Sample code to get you started.","og_url":"https:\/\/blockonomi.com\/solidity-tutorial\/","og_site_name":"Blockonomi","article_publisher":"http:\/\/facebook.com\/blockonomi","article_published_time":"2020-01-24T13:28:11+00:00","article_modified_time":"2020-04-16T13:11:48+00:00","og_image":[{"width":1400,"height":933,"url":"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg","type":"image\/jpeg"}],"author":"Andrej Rakic","twitter_card":"summary_large_image","twitter_creator":"@blockonomi","twitter_site":"@blockonomi","twitter_misc":{"Written by":"Andrej Rakic","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blockonomi.com\/solidity-tutorial\/#article","isPartOf":{"@id":"https:\/\/blockonomi.com\/solidity-tutorial\/"},"author":{"name":"Andrej Rakic","@id":"https:\/\/blockonomi.com\/#\/schema\/person\/6de37845aeb3041e7ee9b2bcd9113873"},"headline":"Solidity Tutorial: An Introduction to Solidity Programming for Beginners","datePublished":"2020-01-24T13:28:11+00:00","dateModified":"2020-04-16T13:11:48+00:00","mainEntityOfPage":{"@id":"https:\/\/blockonomi.com\/solidity-tutorial\/"},"wordCount":2838,"commentCount":0,"publisher":{"@id":"https:\/\/blockonomi.com\/#organization"},"image":{"@id":"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg","keywords":["education-featured","Solidity Introduction","Solidity Programming","Solidity Tutorial"],"articleSection":["Education"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blockonomi.com\/solidity-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blockonomi.com\/solidity-tutorial\/","url":"https:\/\/blockonomi.com\/solidity-tutorial\/","name":"Solidity Tutorial: An Introduction to Solidity Programming for Beginners","isPartOf":{"@id":"https:\/\/blockonomi.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg","datePublished":"2020-01-24T13:28:11+00:00","dateModified":"2020-04-16T13:11:48+00:00","description":"An introduction to the Solidity programming language for creating smart contracts on Ethereum - Sample code to get you started.","breadcrumb":{"@id":"https:\/\/blockonomi.com\/solidity-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blockonomi.com\/solidity-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blockonomi.com\/solidity-tutorial\/#primaryimage","url":"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg","contentUrl":"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg","width":1400,"height":933,"caption":"Solidity Tutorial: An Introduction to Solidity Programming for Beginners"},{"@type":"BreadcrumbList","@id":"https:\/\/blockonomi.com\/solidity-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blockonomi.com\/"},{"@type":"ListItem","position":2,"name":"Solidity Tutorial: An Introduction to Solidity Programming for Beginners"}]},{"@type":"WebSite","@id":"https:\/\/blockonomi.com\/#website","url":"https:\/\/blockonomi.com\/","name":"Blockonomi","description":"Cryptocurrency News &amp; Your Guide to the Blockchain Economy","publisher":{"@id":"https:\/\/blockonomi.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blockonomi.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/blockonomi.com\/#organization","name":"Blockonomi","url":"https:\/\/blockonomi.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blockonomi.com\/#\/schema\/logo\/image\/","url":"https:\/\/blockonomi.com\/wp-content\/uploads\/2018\/07\/blockonomi-logo-1.png","contentUrl":"https:\/\/blockonomi.com\/wp-content\/uploads\/2018\/07\/blockonomi-logo-1.png","width":800,"height":127,"caption":"Blockonomi"},"image":{"@id":"https:\/\/blockonomi.com\/#\/schema\/logo\/image\/"},"sameAs":["http:\/\/facebook.com\/blockonomi","https:\/\/x.com\/blockonomi"]},{"@type":"Person","@id":"https:\/\/blockonomi.com\/#\/schema\/person\/6de37845aeb3041e7ee9b2bcd9113873","name":"Andrej Rakic","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/blockonomi.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/2613389519d5c8f115b49e8f67f0655d0f5bca5a276a401fa3f3d3dc82993bd6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2613389519d5c8f115b49e8f67f0655d0f5bca5a276a401fa3f3d3dc82993bd6?s=96&d=mm&r=g","caption":"Andrej Rakic"},"description":"Lead Blockchain Developer at Blockchain Systems. Bachelor of Engineering, Computer Science at Faculty of Electrical Engineering in Nis. Graduate of Blockchain Academy (powered by European Blockchain Hub). My hobbies are traveling &amp; vlogging. https:\/\/github.com\/TheRealRichardHendricks","sameAs":["https:\/\/www.medium.com\/@andrej.rakic"],"url":"https:\/\/blockonomi.com\/author\/andrej-rakic\/"}]}},"jetpack_featured_media_url":"https:\/\/blockonomi.com\/wp-content\/uploads\/2020\/01\/solidity-tutorial.jpg","jetpack_shortlink":"https:\/\/wp.me\/p94Zms-9HB","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/posts\/37299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/users\/32"}],"replies":[{"embeddable":true,"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/comments?post=37299"}],"version-history":[{"count":12,"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/posts\/37299\/revisions"}],"predecessor-version":[{"id":37488,"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/posts\/37299\/revisions\/37488"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/media\/37484"}],"wp:attachment":[{"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/media?parent=37299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/categories?post=37299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blockonomi.com\/wp-json\/wp\/v2\/tags?post=37299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}