{"id":2833,"date":"2020-12-22T20:20:48","date_gmt":"2020-12-22T07:20:48","guid":{"rendered":"http:\/\/www.talkcrypto.org\/blog\/?p=2833"},"modified":"2021-02-07T23:21:45","modified_gmt":"2021-02-07T10:21:45","slug":"solidity-helloworld-updated-for-2021-with-remix","status":"publish","type":"post","link":"https:\/\/www.talkcrypto.org\/blog\/2020\/12\/22\/solidity-helloworld-updated-for-2021-with-remix\/","title":{"rendered":"Solidity HelloWorld (updated for 2021) with Remix"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">It is really easy to get up and running with Solidity smart contracts using Remix which is an online IDE for developing smart contracts in Solidity. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you visit <a href=\"https:\/\/remix.ethereum.org\/\">https:\/\/remix.ethereum.org\/<\/a>, you&#8217;ll see some sample code <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"686\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/image-1024x686.png\" alt=\"\" class=\"wp-image-2834\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/image-1024x686.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/image-300x201.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/image-768x515.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/image.png 1347w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Removing all the comments to make it less scary, you can see that the name of the contract is &#8220;Storage&#8221;, there is one variable called number of type uint256 which stands for an unsigned integer that is 256 bits long and then two functions. One to store the number and one to retrieve the number. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ SPDX-License-Identifier: GPL-3.0\n\npragma solidity &gt;=0.7.0 &lt;0.8.0;\ncontract Storage {\n    uint256 number;\n    function store(uint256 num) public {\n        number = num;\n    }\n    function retrieve() public view returns (uint256){\n        return number;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">And that is it really. Read <a rel=\"noreferrer noopener\" href=\"https:\/\/www.talkcrypto.org\/blog\/2018\/12\/22\/understanding-basic-functions-in-solidity\/\" target=\"_blank\">this<\/a> explanation of functions to demystify the key words such as public, view and returns and this smart contract should be easy to understand. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Below I&#8217;ve changed the code to store a string instead and changed the contract name to &#8220;helloWorld&#8221;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ SPDX-License-Identifier: GPL-3.0\npragma solidity &gt;=0.7.0 &lt;0.8.0;\ncontract helloWorld {\n    string myString;\n    function store(string memory str) public {\n        myString = str;\n    }\n    function retrieve() public view returns (string memory){\n        return myString;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To run this, you will have to compile the contract first.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"897\" height=\"601\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.11.25-pm.png\" alt=\"\" class=\"wp-image-2835\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.11.25-pm.png 897w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.11.25-pm-300x201.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.11.25-pm-768x515.png 768w\" sizes=\"(max-width: 897px) 100vw, 897px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Then deploy the contract.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"790\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.15.32-pm-1024x790.png\" alt=\"\" class=\"wp-image-2836\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.15.32-pm-1024x790.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.15.32-pm-300x231.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.15.32-pm-768x593.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/Screen-Shot-2021-01-22-at-6.15.32-pm.png 1055w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Now you can store a string and retrieve the string. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is really easy to get up and running with<\/p>\n","protected":false},"author":1,"featured_media":2838,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,2],"tags":[],"class_list":["post-2833","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ethereum","category-smart-contracts"],"featured_image_urls":{"full":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"thumbnail":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld-150x131.jpg",150,131,true],"medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"medium_large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"1536x1536":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"2048x2048":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"chromenews-featured":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"chromenews-large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false],"chromenews-medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2021\/01\/helloWorld.jpg",194,131,false]},"author_info":{"info":["seandotau"]},"category_info":"<a href=\"https:\/\/www.talkcrypto.org\/blog\/category\/ethereum\/\" rel=\"category tag\">Ethereum<\/a> <a href=\"https:\/\/www.talkcrypto.org\/blog\/category\/smart-contracts\/\" rel=\"category tag\">Smart Contracts<\/a>","tag_info":"Smart Contracts","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/2833","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/comments?post=2833"}],"version-history":[{"count":2,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/2833\/revisions"}],"predecessor-version":[{"id":2853,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/2833\/revisions\/2853"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media\/2838"}],"wp:attachment":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media?parent=2833"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/categories?post=2833"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/tags?post=2833"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}