<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>blockchain on smarx.com</title>
    <link>https://smarx.com/tags/blockchain/</link>
    <description>Recent content on smarx.com</description>
    <language>en-us</language>
    <managingEditor>smarx@smarx.com (Steve Marx)</managingEditor>
    <webMaster>smarx@smarx.com (Steve Marx)</webMaster>
    <lastBuildDate>Thu, 20 Aug 2020 16:22:00 -0400</lastBuildDate>
    
        <atom:link href="https://smarx.com/tags/blockchain/index.xml" rel="self" type="application/rss+xml" />
    
    
    <item>
      <title>Smart Contracts Are Stored Procedures</title>
      <link>https://smarx.com/posts/2020/08/smart-contracts-are-stored-procedures/</link>
      <pubDate>Thu, 20 Aug 2020 16:22:00 -0400</pubDate>
      <author>smarx@smarx.com (Steve Marx)</author>
      <guid>https://smarx.com/posts/2020/08/smart-contracts-are-stored-procedures/</guid>
      <description>&lt;p&gt;You may have heard the term &amp;ldquo;smart contracts&amp;rdquo; before, particularly if you&amp;rsquo;ve read about the Ethereum blockchain. The term is quite a misnomer. (Try searching for &lt;a href=&#34;https://duckduckgo.com/?q=%22smart+contracts+are+neither%22&amp;amp;ia=web&#34;&gt;&amp;ldquo;smart contracts are neither&amp;rdquo;&lt;/a&gt; in your favorite search engine.) Vitalik Buterin, the inventor of Ethereum, &lt;a href=&#34;https://twitter.com/VitalikButerin/status/1051160932699770882&#34;&gt;regrets the term&lt;/a&gt;.&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;I find smart contracts incredibly cool. My last job was conducting &lt;a href=&#34;https://diligence.consensys.net&#34;&gt;security audits of smart contracts&lt;/a&gt;.&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt; Before that, I co-authored a blog about them called &lt;a href=&#34;https://programtheblockchain.com&#34;&gt;Program the Blockchain&lt;/a&gt;, and I built a security capture the flag game called &lt;a href=&#34;https://capturetheether.com/&#34;&gt;Capture the Ether&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You should think smart contracts are cool too. And what could be cooler than &lt;strong&gt;stored procedures&lt;/strong&gt;?&lt;/p&gt;





    




    


&lt;figure class=&#34;flex flex-col items-center&#34;&gt;
    
    &lt;a href=&#34;https://smarx.com/posts/2020/08/smart-contracts-are-stored-procedures/sp-featured-cover.png&#34; data-lightbox=&#34;136dd476368c30ef3064c0a3fa67aec9&#34; &gt;
    
    &lt;img class=&#34;mx-auto&#34; src=&#34;https://smarx.com/posts/2020/08/smart-contracts-are-stored-procedures/sp-featured-cover_hu3454504efd757966de9e689fddfc51cf_161396_728x0_resize_lanczos_2.png&#34; width=&#34;728&#34; height=&#34;329&#34;&gt;
    
    &lt;/a&gt;
    
    
&lt;/figure&gt;

&lt;h2 id=&#34;first-whats-a-blockchain&#34;&gt;First, what&amp;rsquo;s a blockchain?&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;m not going to try to explain how a blockchain works. There&amp;rsquo;s no point, because Grant Sanderson of &lt;a href=&#34;https://www.youtube.com/c/3blue1brown&#34;&gt;3Blue1Brown&lt;/a&gt; &lt;em&gt;nails it&lt;/em&gt; in the video below. When I share a video that&amp;rsquo;s almost 30 minutes long, I usually equivocate a bit, but I&amp;rsquo;ll say without qualification that &lt;strong&gt;you should watch this video&lt;/strong&gt;:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube-nocookie.com/embed/bBC-nXj3Ng4&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;You&amp;rsquo;re welcome.&lt;/p&gt;
&lt;h2 id=&#34;a-blockchain-is-a-database&#34;&gt;A blockchain is a database&lt;/h2&gt;
&lt;p&gt;A blockchain can be described in many ways, but from a functional perspective, I think it&amp;rsquo;s best thought of as a distributed, history-preserving&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt; database&lt;sup id=&#34;fnref:4&#34;&gt;&lt;a href=&#34;#fn:4&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;4&lt;/a&gt;&lt;/sup&gt;. The magic of the blockchain (as explained in the video above&amp;mdash;you did watch it, right?) is that it makes it possible for the whole world to agree on the state of that database.&lt;/p&gt;
&lt;p&gt;In the most popular use, the blockchain state we&amp;rsquo;re all agreeing on is everyone&amp;rsquo;s account balances, which result from a bunch of transactions. This use case, known as a cryptocurrency, is an important enabling technology in its own right.&lt;/p&gt;
&lt;p&gt;But it&amp;rsquo;s small potatoes.&lt;/p&gt;
&lt;h2 id=&#34;smart-contracts-are-stored-procedures&#34;&gt;Smart contracts are stored procedures&lt;/h2&gt;
&lt;p&gt;If the blockchain is a database, then smart contracts are the &lt;a href=&#34;https://en.wikipedia.org/wiki/Stored_procedure&#34;&gt;stored procedures&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In Ethereum, a simple transfer of ether (Ethereum&amp;rsquo;s native cryptocurrency) looks something like this&lt;sup id=&#34;fnref:5&#34;&gt;&lt;a href=&#34;#fn:5&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;5&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;k&#34;&gt;from&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;Alice&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;     &lt;/span&gt;Bob&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;amount&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;ether&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;data&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Thanks for feeding my cat while I was on vacation.&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This transaction describes a very simple state transformation. Alice&amp;rsquo;s balance is decreased by 1 ether, and Bob&amp;rsquo;s balance is increased by the same amount. But what about the &lt;code&gt;data&lt;/code&gt; field? Without the involvement of smart contracts, that data is just permanently stored as part of the transaction. Future historians will never have to wonder why Alice paid Bob 1 ether.&lt;/p&gt;
&lt;p&gt;Ethereum has a special kind of transaction, which is sent to no one:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;k&#34;&gt;from&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;Alice&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;     &lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;null&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;c&#34;&gt;# !!&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;amount&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;m&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;ether&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;data&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;...&lt;span class=&#34;w&#34;&gt;     &lt;/span&gt;&lt;span class=&#34;c&#34;&gt;# bytecode&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Such a transaction is used to create a smart contract. A smart contract is an account, just like Alice&amp;rsquo;s account or Bob&amp;rsquo;s account. The only difference is that it has a piece of code associated with it. That code is executed automatically if somebody sends a transaction to the smart contract account. Hence the term &amp;ldquo;stored procedure&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Ethereum smart contracts have their own ether balance like any other account, and they also have storage, which they can use to persist state between code invocations. When invoked, they can manipulate storage and interact with other accounts (including other smart contracts) by sending their own transactions.&lt;/p&gt;
&lt;h2 id=&#34;a-simple-example&#34;&gt;A simple example&lt;/h2&gt;
&lt;p&gt;That explanation was a bit abstract. Let me show you a real, working example written in &lt;a href=&#34;https://solidity.readthedocs.io/en/latest/&#34;&gt;Solidity&lt;/a&gt;, Ethereum&amp;rsquo;s primary smart contract language. The following smart contract splits incoming ether evenly between two parties&lt;sup id=&#34;fnref:6&#34;&gt;&lt;a href=&#34;#fn:6&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;6&lt;/a&gt;&lt;/sup&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-solidity&#34; data-lang=&#34;solidity&#34;&gt;&lt;span class=&#34;kr&#34;&gt;pragma solidity&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;7&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;0&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

&lt;span class=&#34;kd&#34;&gt;contract&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;SplitterBot3000&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
    &lt;span class=&#34;kt&#34;&gt;address&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;payable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;immutable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
    &lt;span class=&#34;kt&#34;&gt;address&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;payable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;immutable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bob&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
    
    &lt;span class=&#34;n&#34;&gt;constructor&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;kt&#34;&gt;address&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;payable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;_alice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;kt&#34;&gt;address&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;payable&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;_bob&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;alice&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;_alice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
        &lt;span class=&#34;n&#34;&gt;bob&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;_bob&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
    
    &lt;span class=&#34;n&#34;&gt;receive&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;payable&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;external&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
        &lt;span class=&#34;kt&#34;&gt;bool&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;success&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;
        &lt;span class=&#34;kt&#34;&gt;bytes&lt;/span&gt; &lt;span class=&#34;kr&#34;&gt;memory&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;returnData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;;&lt;/span&gt;

        &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;success&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;returnData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;alice&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;call&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;value&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
        &lt;span class=&#34;nb&#34;&gt;require&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;success&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Transfer to alice failed.&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;

        &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;success&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;returnData&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;bob&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;call&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;value&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;nb&#34;&gt;msg&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;.&lt;/span&gt;&lt;span class=&#34;nb&#34;&gt;value&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;/&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;}(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
        &lt;span class=&#34;nb&#34;&gt;require&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;success&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;Transfer to bob failed.&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;);&lt;/span&gt;
    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Using this smart contract is as simple as sending a transaction to it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;k&#34;&gt;from&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;Charlie&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;to&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;     &lt;/span&gt;SplitterBot3000&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;amount&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;ether&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;k&#34;&gt;data&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;   &lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Assuming Alice and Bob are regular (non-smart-contract) accounts, this transaction results in Charlie&amp;rsquo;s balance being decreased by 2 ether, and Alice and Bob&amp;rsquo;s accounts each being increased by 1 ether.&lt;/p&gt;
&lt;p&gt;If Alice and/or Bob &lt;em&gt;are&lt;/em&gt; smart contracts, then all sorts of things could have happened! Stored procedures can have cascading effects, after all.&lt;/p&gt;
&lt;h2 id=&#34;okay-but-why&#34;&gt;Okay, but why?&lt;/h2&gt;
&lt;p&gt;It&amp;rsquo;s possible that I&amp;rsquo;ve succeeded in giving you a good mental model for what a smart contract is. But you may not be convinced that smart contracts are &lt;em&gt;cool&lt;/em&gt;. This is because the example I used is quite boring.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s think about something considerably more exciting: &lt;strong&gt;gambling&lt;/strong&gt;. Imagine that you and I want to bet $1 on the outcome of a coin flip. How can we do this in a way that&amp;rsquo;s fair to both of us? Here&amp;rsquo;s my proposal:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Send me $1.&lt;/li&gt;
&lt;li&gt;I&amp;rsquo;ll flip a coin.&lt;/li&gt;
&lt;li&gt;If it comes up &amp;ldquo;tails&amp;rdquo;, I&amp;rsquo;ll send you $2.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Sound good?&lt;/p&gt;
&lt;p&gt;If that doesn&amp;rsquo;t sound fair to you, it&amp;rsquo;s because you don&amp;rsquo;t &lt;strong&gt;trust&lt;/strong&gt; me. This is wise. But you &lt;em&gt;can&lt;/em&gt; trust a &lt;del&gt;stored procedure&lt;/del&gt; smart contract. Over on Program the Blockchain, I wrote a blog post called &lt;a href=&#34;https://programtheblockchain.com/posts/2018/03/16/flipping-a-coin-in-ethereum/&#34;&gt;Flipping a Coin in Ethereum&lt;/a&gt;, which shows how we can gamble over the internet in a perfectly safe and fair way.&lt;/p&gt;
&lt;h2 id=&#34;more-use-cases&#34;&gt;More use cases&lt;/h2&gt;
&lt;p&gt;Maybe gambling isn&amp;rsquo;t your thing. How about shopping? Using a smart contract, &lt;a href=&#34;https://eprint.iacr.org/2018/740.pdf&#34;&gt;digital goods can be sold&lt;/a&gt; in such a way that the buyer and seller don&amp;rsquo;t have to trust each other at all. (If and only if the digital goods are delivered, the payment is delivered too.)&lt;/p&gt;
&lt;p&gt;How about voting? A trivial version is the ubiquitous &amp;ldquo;multisignature wallet&amp;rdquo; contract. See &lt;a href=&#34;https://programtheblockchain.com/posts/2018/07/11/writing-a-trivial-multisig-wallet/&#34;&gt;Writing a Trivial Multisig Wallet&lt;/a&gt; for an example. But much more sophisticated voting and governance schemes are regularly being invented on Ethereum.&lt;/p&gt;
&lt;p&gt;How about &lt;a href=&#34;https://en.wikipedia.org/wiki/Prediction_market&#34;&gt;prediction markets&lt;/a&gt;? Insurance? Crowdfunding? Auctions? Peer-to-peer lending? A lot of the easiest use cases center around digital assets, but people are tracking ownership and selling physical objects &lt;a href=&#34;https://media.consensys.net/the-purchase-and-sale-of-real-property-on-ethereum-55bdc289a7b5&#34;&gt;like houses&lt;/a&gt; with smart contracts too.&lt;/p&gt;
&lt;h2 id=&#34;resources&#34;&gt;Resources&lt;/h2&gt;
&lt;p&gt;If this piqued your curiosity about smart contracts, I have a few recommendations for where you can learn more:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The first post on Program the Blockchain, &lt;a href=&#34;https://programtheblockchain.com/posts/2017/12/06/what-is-a-smart-contract/&#34;&gt;What Is a Smart Contract?&lt;/a&gt;, explains smart contracts in a more technical way.&lt;/li&gt;
&lt;li&gt;If you&amp;rsquo;re interested in learning to write smart contracts, the rest of &lt;a href=&#34;https://programtheblockchain.com/posts&#34;&gt;Program the Blockchain&lt;/a&gt; are great! (Nobody ever accused me of modesty.)&lt;/li&gt;
&lt;li&gt;The original &lt;a href=&#34;https://ethereum.org/en/whitepaper/&#34;&gt;Ethereum whitepaper&lt;/a&gt; explains the blockchain as a series of state transitions. It also provides the motivation for smart contracts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;And of course, stay tuned to this blog, where I will undoubtedly write more about smart contracts. I would &lt;em&gt;love&lt;/em&gt; it if you would &lt;a href=&#34;https://smarx.substack.com&#34;&gt;&lt;strong&gt;subscribe to my newsletter&lt;/strong&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;But note that he didn&amp;rsquo;t originate the term. That honor goes to &lt;a href=&#34;https://en.wikipedia.org/wiki/Nick_Szabo&#34;&gt;Nick Szabo&lt;/a&gt;, whose ideas led directly to Bitcoin. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;By the way, my old team is hiring! If you&amp;rsquo;re interested in doing smart contract security work, &lt;a href=&#34;https://diligence.consensys.net/contact/&#34;&gt;reach out to them&lt;/a&gt;, and tell them I sent you! &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;You may prefer &amp;ldquo;immutable&amp;rdquo;, especially if you&amp;rsquo;re used to immutable data structures. But I think that terminology confuses a lot of people. Obviously the blockchain is mutable. Otherwise you couldn&amp;rsquo;t transfer cryptocurrency. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:4&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;You may also prefer the term &amp;ldquo;ledger&amp;rdquo; to database. This is okay, but particularly when discussing smart contracts, it fails to capture the expressiveness. &lt;a href=&#34;#fnref:4&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:5&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;This is an oversimplification, but not that big of one. Read &lt;a href=&#34;https://programtheblockchain.com/posts/2017/12/29/how-ethereum-transactions-work/&#34;&gt;How Ethereum Transactions Work&lt;/a&gt; for a more detailed treatment. &lt;a href=&#34;#fnref:5&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:6&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;There&amp;rsquo;s an Office Space / Superman III opportunity here! What if an odd amount of ether is sent? There will be a tiny remainder, but those remainders might add up, right? Two problems: 1) There&amp;rsquo;s no way to get those scraps out of the smart contract because it has no code to send it. 2) The maximum remainder for each transaction is 1 &lt;em&gt;wei&lt;/em&gt;, which is 1/10&lt;sup&gt;18&lt;/sup&gt; of an ether. At today&amp;rsquo;s ether prices, it would take on the order of ten quadrillion odd-valued transactions before you made your first dollar. &lt;a href=&#34;#fnref:6&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
  </channel>
</rss>
