{"id":1742,"date":"2018-01-04T02:16:18","date_gmt":"2018-01-04T02:16:18","guid":{"rendered":"http:\/\/www.talkcrypto.org\/blog\/?p=1742"},"modified":"2018-01-08T00:38:35","modified_gmt":"2018-01-08T00:38:35","slug":"hello-world-ethereum-smart-contract","status":"publish","type":"post","link":"https:\/\/www.talkcrypto.org\/blog\/2018\/01\/04\/hello-world-ethereum-smart-contract\/","title":{"rendered":"Hello World Ethereum Smart Contract"},"content":{"rendered":"<h3>Introduction<\/h3>\n<p>There are lots of simple Ethereum Hello World tutorials around to cater for everyone&#8217;s level. This tutorial builds on a 2016 version by Karl Floersh and attempts to keep things very simple. All that is required to be installed is Meta Mask which is currently a Chrome only plugin and is essentially an Ethereum light client browser plugin.<\/p>\n<p>More formally:<\/p>\n<blockquote><p>&#8220;<em>MetaMask is a bridge that allows you to visit the distributed web of tomorrow in your browser today. It allows you to run Ethereum dApps right in your browser without running a full Ethereum node.<\/em>&#8220;<\/p><\/blockquote>\n<h3>Outcome<\/h3>\n<p>To deploy a hello world smart contract on the Ethereum network. Here is the code. It&#8217;s 1 contract consisting of 1 function and 1 event.<\/p>\n<pre class=\" language-markup\"><code class=\" language-markup\">contract HelloWorld {  \r\n    event log_string(bytes32 log); \/\/ Event\r\n\r\n    function () { \/\/ Fallback Function\r\n        log_string(\"Hello World!\");\r\n    }\r\n}\r\n<\/code><\/pre>\n<p>This guide should only take about 10 minutes to follow.<\/p>\n<h3>Step 1: Install MetaMask<\/h3>\n<p>In Chrome, search for MetaMask and install it as a plugin. Then create an account and change the network to Ropsten. This is the test network.<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone wp-image-1743\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-1.29.54-PM-300x263.png\" alt=\"\" width=\"378\" height=\"331\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-1.29.54-PM-300x263.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-1.29.54-PM.png 700w\" sizes=\"(max-width: 378px) 100vw, 378px\" \/><\/p>\n<p>In order to get some test ether, click &#8220;BUY&#8221; and click &#8220;Ropsten test Faucet&#8221;.<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1744\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-1.31.14-PM-300x222.png\" alt=\"\" width=\"365\" height=\"270\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-1.31.14-PM-300x222.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-1.31.14-PM.png 704w\" sizes=\"(max-width: 365px) 100vw, 365px\" \/><\/p>\n<p>This will take you to https:\/\/faucet.metamask.io\/ where you can &#8220;request 1 ether from faucet&#8221;.<\/p>\n<h3>Step 2: The Hello World code<\/h3>\n<p>Once you have MetaMask installed and managed to get some test ether, the next step is to compile the hello world code provided. Let&#8217;s understand the code first:<\/p>\n<pre class=\" language-markup\"><code class=\" language-markup\">contract HelloWorld {  \r\n    event log_string(bytes32 log); \/\/ Event\r\n\r\n    function () { \/\/ Fallback Function\r\n        log_string(\"Hello World!\");\r\n    }\r\n}<\/code><\/pre>\n<p>The first line declares a contract called HelloWorld. Next, an event is defined and accepts 1 argument of type bytes32. A function is then declared that invokes the event.<\/p>\n<p>For more info about events check out:<\/p>\n<p>https:\/\/media.consensys.net\/technical-introduction-to-events-and-logs-in-ethereum-a074d65dd61e<br \/>\nhttps:\/\/ethereum.stackexchange.com\/questions\/11228\/what-is-an-event<br \/>\nhttp:\/\/solidity.readthedocs.io\/en\/develop\/contracts.html#events<\/p>\n<h3>Step 3: Compile and deploy the code<\/h3>\n<p>We will use the very popular online IDE (Integrated Development Environment) called Remix at http:\/\/remix.ethereum.org\/. Copy and paste the code in and click Run &gt; Create<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-1745\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.26.55-PM-300x122.png\" alt=\"\" width=\"475\" height=\"193\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.26.55-PM-300x122.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.26.55-PM-768x311.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.26.55-PM-1024x415.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.26.55-PM.png 1974w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><\/p>\n<p>A MetaMask notification will then appear. Click Submit to deploy the contract to the Ropsten blockchain.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1746\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.27.59-PM-254x300.png\" alt=\"\" width=\"339\" height=\"401\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.27.59-PM-254x300.png 254w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.27.59-PM.png 706w\" sizes=\"(max-width: 339px) 100vw, 339px\" \/><\/p>\n<h3>Step 4: View the deployed contract<\/h3>\n<p>Open MetaMask again and wait a few minutes for the contact to be deployed. Then click on it to open up the contract in Etherscan.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1748\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.32.42-PM-300x268.png\" alt=\"\" width=\"345\" height=\"308\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.32.42-PM-300x268.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.32.42-PM.png 708w\" sizes=\"(max-width: 345px) 100vw, 345px\" \/><\/p>\n<p>This is what it should look like: https:\/\/ropsten.etherscan.io\/tx\/0xa142914ac224047fbf39a3b2ed92a68bc24fd301466d059fbe0e7810bdc8e5e9<\/p>\n<p>Congratulations. You have just deployed a very simple Hello World smart contract.<\/p>\n<h3>Step 5: Invoke the contract<\/h3>\n<p>The contract is now alive on the Ethereum blockchain. The final question is how to we interact with it or trigger it.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1749\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.34.30-PM-300x125.png\" alt=\"\" width=\"552\" height=\"230\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.34.30-PM-300x125.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.34.30-PM-768x319.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.34.30-PM-1024x426.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.34.30-PM.png 1928w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/p>\n<p>This is where we go back to MetaMask and send a transaction to the contract. First get the contract address. Look for the To field in the original contract deployed link at https:\/\/ropsten.etherscan.io\/tx\/0xa142914ac224047fbf39a3b2ed92a68bc24fd301466d059fbe0e7810bdc8e5e9<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1750\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.37.13-PM-300x20.png\" alt=\"\" width=\"555\" height=\"37\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.37.13-PM-300x20.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.37.13-PM-768x51.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.37.13-PM-1024x69.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.37.13-PM.png 1402w\" sizes=\"(max-width: 555px) 100vw, 555px\" \/><\/p>\n<p>In my case it is: 0xfd3811943d7e924607a2443465bc5deeb5847e14<\/p>\n<p>In MetaMask, click send and use the contract address as the Recipient Address. Leave the other fields as is and click Next.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1751\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.39.02-PM-267x300.png\" alt=\"\" width=\"343\" height=\"385\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.39.02-PM-267x300.png 267w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.39.02-PM.png 716w\" sizes=\"(max-width: 343px) 100vw, 343px\" \/><\/p>\n<p>Again, leave all the default values as is and click Submit.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1752\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.39.45-PM-255x300.png\" alt=\"\" width=\"336\" height=\"395\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.39.45-PM-255x300.png 255w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.39.45-PM.png 710w\" sizes=\"(max-width: 336px) 100vw, 336px\" \/><\/p>\n<p>Wait a few minutes for the transaction to go through and then check the Event Log of the transaction.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1753\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.41.42-PM-300x40.png\" alt=\"\" width=\"510\" height=\"68\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.41.42-PM-300x40.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.41.42-PM-768x102.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.41.42-PM-1024x136.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.41.42-PM.png 1854w\" sizes=\"(max-width: 510px) 100vw, 510px\" \/><\/p>\n<p>https:\/\/ropsten.etherscan.io\/tx\/0x6b7f88e9590ec5af87133394d1301bbe4df736a66aff9c9519605f6a9dc4b0a7#eventlog<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1754\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.11-PM-300x101.png\" alt=\"\" width=\"475\" height=\"160\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.11-PM-300x101.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.11-PM-768x260.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.11-PM-1024x346.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.11-PM.png 1490w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><\/p>\n<p>The data field will be in hexidecimal. Change this to text and it should read &#8220;Hello World&#8221;!<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1755\" src=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.52-PM-300x55.png\" alt=\"\" width=\"425\" height=\"78\" srcset=\"https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.52-PM-300x55.png 300w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.52-PM-768x141.png 768w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.52-PM-1024x187.png 1024w, https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/Screen-Shot-2018-01-04-at-2.42.52-PM.png 1322w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/p>\n<h3>Summary<\/h3>\n<p>There are so many ways to deploy a smart contract. This guide used an online development environment in conjunction with a Chrome plugin called MetaMask to deploy a simple Hello World smart contract to the Ethereum testnet blockchain.<\/p>\n<p>The idea was to get up and going quickly with the minimum of moving parts.<\/p>\n<p>Ref:\u00a0https:\/\/karl.tech\/learning-solidity-part-1-deploy-a-contract\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction There are lots of simple Ethereum Hello World tutorials<\/p>\n","protected":false},"author":1,"featured_media":1756,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1742","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ethereum"],"featured_image_urls":{"full":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false],"thumbnail":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300-150x128.jpg",150,128,true],"medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300-300x128.jpg",300,128,true],"medium_large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false],"large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false],"1536x1536":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false],"2048x2048":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false],"chromenews-featured":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false],"chromenews-large":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false],"chromenews-medium":["https:\/\/www.talkcrypto.org\/blog\/wp-content\/uploads\/2018\/01\/meta300.jpg",300,128,false]},"author_info":{"info":["seandotau"]},"category_info":"<a href=\"https:\/\/www.talkcrypto.org\/blog\/category\/ethereum\/\" rel=\"category tag\">Ethereum<\/a>","tag_info":"Ethereum","comment_count":"0","_links":{"self":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1742","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=1742"}],"version-history":[{"count":3,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1742\/revisions"}],"predecessor-version":[{"id":1759,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/posts\/1742\/revisions\/1759"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media\/1756"}],"wp:attachment":[{"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/media?parent=1742"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/categories?post=1742"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.talkcrypto.org\/blog\/wp-json\/wp\/v2\/tags?post=1742"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}