{"id":2371,"date":"2020-01-09T11:28:25","date_gmt":"2020-01-09T10:28:25","guid":{"rendered":"https:\/\/www.codemotion.com\/magazine\/uncategorized\/simple-contract-solidity-blockchain\/"},"modified":"2021-12-23T14:15:37","modified_gmt":"2021-12-23T13:15:37","slug":"simple-contract-solidity-blockchain","status":"publish","type":"post","link":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/","title":{"rendered":"A simple contract in Solidity"},"content":{"rendered":"<p>After choosing the best <span id=\"urn:enhancement-946d19a9\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/integrated_development_environment\">IDE<\/span> to develop our first smart contract, we will now write some actual code.<\/p>\n<p>This is part three of a series on how to create an ERC-20 token. If you want to begin from scratch, please read <u><a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/what-is-an-erc-20-token-an-overview\/\">part one<\/a><\/u> and <u><a href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/solidity-hello-world-blockchain\/\">part two<\/a><\/u> of this series (<a class=\"ek-link\" href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/smart-contract-create-interface-token-blockchain\/\">part four<\/a> and <a href=\"_wp_link_placeholder\" data-wplink-edit=\"true\">part five<\/a> are right here<a class=\"ek-link\" href=\"https:\/\/www.codemotion.com\/magazine\/dev-hub\/blockchain-dev\/smart-contract-create-interface-token-blockchain\/\">)<\/a>.<\/p>\n<p>Using <strong>Ethereum Studio<\/strong>, we began using the \u2018<span id=\"urn:enhancement-b9d80e8\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/dbpedia.org\/resource\/\" hello=\"\" _world=\"\" _program=\"\">Hello World<\/span>\u2019 template to understand the basics of Solidity. This is the \u2018<span id=\"urn:enhancement-ee54b575\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/dbpedia.org\/resource\/\" hello=\"\" _world=\"\" _program=\"\">Hello World<\/span>\u2019 template:<\/p>\n<pre>pragma solidity ^0.5.10;<br \/>contract <span id=\"urn:enhancement-2a1d6ba7\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/dbpedia.org\/resource\/\" hello=\"\" _world=\"\" _program=\"\">HelloWorld<\/span> {<br \/><br \/>   string public message;<br \/><br \/>\u00a0\u00a0\u00a0constructor(string memory initMessage) public {<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0message = initMessage;<br \/>   }<br \/><br \/>   function update(string memory newMessage) public {<br \/>      message = newMessage;<br \/>      }<br \/>}<\/pre>\n<p>This says that the smart contract <span id=\"urn:enhancement-907277dd\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/dbpedia.org\/resource\/\" hello=\"\" _world=\"\" _program=\"\">HelloWorld<\/span> initializes a message that is passed as a parameter and which can be updated using the <em>update<\/em> function. Please remember that the <em>newMessage<\/em> <span id=\"urn:enhancement-99428fef\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">variable<\/span> will be the <em>message <span id=\"urn:enhancement-cdd02328\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\"><\/span><\/em>variable for the most updated block, but one can view all <em>message <span id=\"urn:enhancement-8791913d\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\"><\/span><\/em>variables in previous blocks: this is known as a <strong>State <span id=\"urn:enhancement-35d93a2e\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">Variable<\/span><\/strong>. Every <span id=\"urn:enhancement-20f55637\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">variable<\/span> in a smart contract is a <span id=\"urn:enhancement-7fe928b7\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">variable<\/span> in the block it gets executed into. All <span id=\"urn:enhancement-11599b53\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">variables<\/span> in a given block compose the <strong>State <\/strong>of the blockchain, along with all the \u2018normal\u2019 transactions.<\/p>\n<p><strong>Functions<\/strong> are the same as in every other <span id=\"urn:enhancement-d232fc2a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/programming_languages\">programming language<\/span>, and can accept parameters and return <span id=\"urn:enhancement-d66f9689\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">variables<\/span>.<\/p>\n<p>We will now explore the development of a simple contract for implementing the simplest form of cryptocurrency. It allows the creation of new coins (<strong>minting<\/strong>), and sending them to addresses belonging to the same blockchain (transactions between assets in two different blockchain are possible, but require an <strong>extra layer<\/strong> that will not be discussed in this series).<\/p>\n<p>In order to do implement this form, we can edit the current situation by pasting this code and renaming the file to ExampleCoin.sol:<\/p>\n<pre><strong>pragma solidity<\/strong> &gt;=0.5.0 &lt;0.7.0;<br \/><strong>contract<\/strong> ExampleCoin {<br \/>   address public minter;<br \/><br \/>   mapping (address =&gt; uint) public balances;<br \/>   <br \/>   event Sent(address from, address to, uint amount);<br \/><br \/>   constructor() public {<br \/>      minter = msg.sender;<br \/>      }<br \/>   function mint(address receiver, uint amount) public {<br \/>      require(msg.sender == minter);<br \/>      require(amount &lt; 1e60);<br \/>      balances[receiver] += amount;<br \/>   }<br \/><br \/>   function send(address received, uint amount) public {<br \/>      require(amount &lt;= balances[msg.sender], \"Insufficient balance.\");<br \/>      balances[msg.sender] -= amount;<br \/>      balances[receiver] += amount;<br \/>      emit Sent(msg.sender, receiver, amount);<br \/>   }<br \/>}<\/pre>\n<p>The contract above is very simple: it creates an <em>ExampleCoin <\/em>token (also referred to as <em>subcurrency <\/em>in Ethereum Studio) by initializing a coin minter (with the <em>public constructor), <\/em>i.e., an address that can create new coins. This is also the address of the contract creator, so only the creator can mint new coins (see the <em>require(msg.sender == minter) <\/em>instruction). This contract also models the <em>mapping<\/em> of every address with its balance, and the function <em>send<\/em> that simply checks the feasibility of the transaction. If the sender has less balance that they want to send, the contract will return an <em>Insufficient balance<\/em> <span id=\"urn:enhancement-f98f979d\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/statement_computer_science\">statement<\/span> and the transaction will not be completed. If the transaction is feasible, the function will <em>emit <\/em>a <em>send <\/em>event &#8211; a declaration for the broadcast of the transactions. Ethereum <span id=\"urn:enhancement-ffbe5a55\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/client_computing\">clients<\/span> (wallets or decentralized apps on the web) can listen to these events emitted on the blockchain without much cost. As soon as the event is emitted, the listener receives the arguments <em>from<\/em>, <em>to<\/em>, and <em>amount<\/em>, which makes it possible to track transactions.<\/p>\n<p>Keep in mind: to approve any transaction, the <span id=\"urn:enhancement-f8f349d9\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/client_computing\">client<\/span> (wallet or decentralized app on the web) must be synced with the <strong>State of the blockchain<\/strong>, i.e., it must know what the most recent state of all the <span id=\"urn:enhancement-531bdecd\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">variables<\/span> in the blockchain is. A smart contract executed offline will not verify the requirements of the transactions until it\u2019s back online and fully synced with the blockchain.<\/p>\n<p>The <em>minter <\/em>and every <em>address<\/em> mapped are State <span id=\"urn:enhancement-aa533eb7\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/variable_computer_science\">Variables<\/span>. Specifically, this mapping can be thought of as hash tables, virtually initialized such that every possible key exists from the start and is mapped to a value whose <span id=\"urn:enhancement-832793a5\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/byte\">byte<\/span>-representation is all zeros.<\/p>\n<p>It\u2019s impossible to get a list of all of a mapping&#8217;s keys, or a list of all values, so it\u2019s <span id=\"urn:enhancement-d6d98b7a\" class=\"textannotation disambiguated wl-other\" itemid=\"http:\/\/data.wordlift.io\/wl01770\/entity\/best_practice\">good practice<\/span> to either record what you added to the mapping (if it\u2019s useful for other functions), or to keep a list of all the changes recorded by the contract.<\/p>\n<p>To get the balance of an address, the <em>balances <\/em>function can be used at any time:<\/p>\n<pre>function balances(address _account) external view returns (uint) {<br \/>   return balances[_account];<br \/>}<\/pre>\n<p>The main ExampleCoin.sol file is now complete (for the moment), but to make this contract usable, we need to give it the capacity for interaction. The .sol file is intended to be the backend logic of the contract, but there\u2019s also a frontend logic that needs to be implemented. This logic can be developed with the <strong>Web3<\/strong> technology stack, and that will be the main focus of the next chapter in this series.<\/p>\n<p><!-- strchf script --><script>        if(window.strchfSettings === undefined) window.strchfSettings = {};    window.strchfSettings.stats = {url: \"https:\/\/codemotion.storychief.io\/simple-contract-solidity-blockchain?id=460832171&type=2\",title: \"A simple contract in Solidity\",id: \"66543c6c-96d5-4792-a44b-49339654b7a1\"};            (function(d, s, id) {      var js, sjs = d.getElementsByTagName(s)[0];      if (d.getElementById(id)) {window.strchf.update(); return;}      js = d.createElement(s); js.id = id;      js.src = \"https:\/\/d37oebn0w9ir6a.cloudfront.net\/scripts\/v0\/strchf.js\";      js.async = true;      sjs.parentNode.insertBefore(js, sjs);    }(document, 'script', 'storychief-jssdk'))    <\/script><!-- End strchf script --><\/p>\n\n\n\n\n<p class=\"eplus-U0J7qS\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>After choosing the best IDE to develop our first smart contract, we will now write some actual code.<\/p>\n","protected":false},"author":86,"featured_media":2372,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_uag_custom_page_level_css":"","_genesis_hide_title":false,"_genesis_hide_breadcrumbs":false,"_genesis_hide_singular_image":false,"_genesis_hide_footer_widgets":false,"_genesis_custom_body_class":"","_genesis_custom_post_class":"","_genesis_layout":"","footnotes":""},"categories":[13],"tags":[4240,4244],"collections":[],"class_list":{"0":"post-2371","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-blockchain","8":"tag-ethereum","9":"tag-smart-contract","10":"entry"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.9 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Solidity: how to create a simple smart contract for Blockchain - Codemotion<\/title>\n<meta name=\"description\" content=\"After choosing the best IDE to develop our first smart contract, we will now write some actual code.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"A simple contract in Solidity\" \/>\n<meta property=\"og:description\" content=\"After choosing the best IDE to develop our first smart contract, we will now write some actual code.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/\" \/>\n<meta property=\"og:site_name\" content=\"Codemotion Magazine\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Codemotion.Italy\/\" \/>\n<meta property=\"article:author\" content=\"https:\/\/facebook.com\/ijaack94\" \/>\n<meta property=\"article:published_time\" content=\"2020-01-09T10:28:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-12-23T13:15:37+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1104\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Giacomo Barbieri\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ijaack94\" \/>\n<meta name=\"twitter:site\" content=\"@CodemotionIT\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Giacomo Barbieri\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/\"},\"author\":{\"name\":\"Giacomo Barbieri\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf\"},\"headline\":\"A simple contract in Solidity\",\"datePublished\":\"2020-01-09T10:28:25+00:00\",\"dateModified\":\"2021-12-23T13:15:37+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/\"},\"wordCount\":702,\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg\",\"keywords\":[\"Ethereum\",\"Smart Contracts\"],\"articleSection\":[\"Blockchain\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/\",\"name\":\"Solidity: how to create a simple smart contract for Blockchain - Codemotion\",\"isPartOf\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg\",\"datePublished\":\"2020-01-09T10:28:25+00:00\",\"dateModified\":\"2021-12-23T13:15:37+00:00\",\"description\":\"After choosing the best IDE to develop our first smart contract, we will now write some actual code.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg\",\"width\":1104,\"height\":675,\"caption\":\"A simple contract in Solidity\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Backend\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/backend\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Blockchain\",\"item\":\"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"A simple contract in Solidity\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#website\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"name\":\"Codemotion Magazine\",\"description\":\"We code the future. Together\",\"publisher\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#organization\",\"name\":\"Codemotion\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"contentUrl\":\"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png\",\"width\":225,\"height\":225,\"caption\":\"Codemotion\"},\"image\":{\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/Codemotion.Italy\/\",\"https:\/\/x.com\/CodemotionIT\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf\",\"name\":\"Giacomo Barbieri\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g\",\"caption\":\"Giacomo Barbieri\"},\"description\":\"Blogger with over 6 years of experience in blogs and newspapers, passionate about AI, 5G and blockchain. Never-ending learner of new technologies and approaches, I believe in the decentralized government and in the Internet of Money.\",\"sameAs\":[\"https:\/\/facebook.com\/ijaack94\",\"https:\/\/instagram.com\/ijaack94\/\",\"https:\/\/linkedin.com\/in\/giacomobarbieri94\",\"https:\/\/x.com\/ijaack94\"],\"url\":\"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Solidity: how to create a simple smart contract for Blockchain - Codemotion","description":"After choosing the best IDE to develop our first smart contract, we will now write some actual code.","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:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/","og_locale":"en_US","og_type":"article","og_title":"A simple contract in Solidity","og_description":"After choosing the best IDE to develop our first smart contract, we will now write some actual code.","og_url":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/","og_site_name":"Codemotion Magazine","article_publisher":"https:\/\/www.facebook.com\/Codemotion.Italy\/","article_author":"https:\/\/facebook.com\/ijaack94","article_published_time":"2020-01-09T10:28:25+00:00","article_modified_time":"2021-12-23T13:15:37+00:00","og_image":[{"width":1104,"height":675,"url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg","type":"image\/jpeg"}],"author":"Giacomo Barbieri","twitter_card":"summary_large_image","twitter_creator":"@ijaack94","twitter_site":"@CodemotionIT","twitter_misc":{"Written by":"Giacomo Barbieri","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#article","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/"},"author":{"name":"Giacomo Barbieri","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf"},"headline":"A simple contract in Solidity","datePublished":"2020-01-09T10:28:25+00:00","dateModified":"2021-12-23T13:15:37+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/"},"wordCount":702,"publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg","keywords":["Ethereum","Smart Contracts"],"articleSection":["Blockchain"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/","url":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/","name":"Solidity: how to create a simple smart contract for Blockchain - Codemotion","isPartOf":{"@id":"https:\/\/www.codemotion.com\/magazine\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg","datePublished":"2020-01-09T10:28:25+00:00","dateModified":"2021-12-23T13:15:37+00:00","description":"After choosing the best IDE to develop our first smart contract, we will now write some actual code.","breadcrumb":{"@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#primaryimage","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg","width":1104,"height":675,"caption":"A simple contract in Solidity"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/simple-contract-solidity-blockchain\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codemotion.com\/magazine\/"},{"@type":"ListItem","position":2,"name":"Backend","item":"https:\/\/www.codemotion.com\/magazine\/backend\/"},{"@type":"ListItem","position":3,"name":"Blockchain","item":"https:\/\/www.codemotion.com\/magazine\/backend\/blockchain\/"},{"@type":"ListItem","position":4,"name":"A simple contract in Solidity"}]},{"@type":"WebSite","@id":"https:\/\/www.codemotion.com\/magazine\/#website","url":"https:\/\/www.codemotion.com\/magazine\/","name":"Codemotion Magazine","description":"We code the future. Together","publisher":{"@id":"https:\/\/www.codemotion.com\/magazine\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codemotion.com\/magazine\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codemotion.com\/magazine\/#organization","name":"Codemotion","url":"https:\/\/www.codemotion.com\/magazine\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/","url":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","contentUrl":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2019\/11\/codemotionlogo.png","width":225,"height":225,"caption":"Codemotion"},"image":{"@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Codemotion.Italy\/","https:\/\/x.com\/CodemotionIT"]},{"@type":"Person","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/ace6a459089546835d3262bb7aef87bf","name":"Giacomo Barbieri","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codemotion.com\/magazine\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8381a47a5414b1154179659f56400e3eb72c3a592355c40b184a4f8a6a991c87?s=96&d=mm&r=g","caption":"Giacomo Barbieri"},"description":"Blogger with over 6 years of experience in blogs and newspapers, passionate about AI, 5G and blockchain. Never-ending learner of new technologies and approaches, I believe in the decentralized government and in the Internet of Money.","sameAs":["https:\/\/facebook.com\/ijaack94","https:\/\/instagram.com\/ijaack94\/","https:\/\/linkedin.com\/in\/giacomobarbieri94","https:\/\/x.com\/ijaack94"],"url":"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/"}]}},"featured_image_src":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-600x400.jpg","featured_image_src_square":"https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-600x600.jpg","author_info":{"display_name":"Giacomo Barbieri","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/"},"uagb_featured_image_src":{"full":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg",1104,675,false],"thumbnail":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-150x150.jpg",150,150,true],"medium":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-300x183.jpg",300,183,true],"medium_large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-768x470.jpg",768,470,true],"large":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-1024x626.jpg",1024,626,true],"1536x1536":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg",1104,675,false],"2048x2048":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg",1104,675,false],"small-home-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000.jpg",100,61,false],"sidebar-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-180x128.jpg",180,128,true],"genesis-singular-images":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-896x504.jpg",896,504,true],"archive-featured":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-400x225.jpg",400,225,true],"gb-block-post-grid-landscape":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-600x400.jpg",600,400,true],"gb-block-post-grid-square":["https:\/\/www.codemotion.com\/magazine\/wp-content\/uploads\/2020\/01\/round-gold-colored-ethereum-coin-1036637_17b09ee4d040c2fd4fb05beac905f781_2000-600x600.jpg",600,600,true]},"uagb_author_info":{"display_name":"Giacomo Barbieri","author_link":"https:\/\/www.codemotion.com\/magazine\/author\/giacomo-barbieri\/"},"uagb_comment_info":0,"uagb_excerpt":"After choosing the best IDE to develop our first smart contract, we will now write some actual code.","lang":"en","_links":{"self":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/2371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/users\/86"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/comments?post=2371"}],"version-history":[{"count":6,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/2371\/revisions"}],"predecessor-version":[{"id":15516,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/posts\/2371\/revisions\/15516"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media\/2372"}],"wp:attachment":[{"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/media?parent=2371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/categories?post=2371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/tags?post=2371"},{"taxonomy":"collections","embeddable":true,"href":"https:\/\/www.codemotion.com\/magazine\/wp-json\/wp\/v2\/collections?post=2371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}