<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mitch Pierias on Medium]]></title>
        <description><![CDATA[Stories by Mitch Pierias on Medium]]></description>
        <link>https://medium.com/@mitchpierias?source=rss-cbff57364085------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*dR5m7ixZME80JnFINv6h0Q.jpeg</url>
            <title>Stories by Mitch Pierias on Medium</title>
            <link>https://medium.com/@mitchpierias?source=rss-cbff57364085------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 16:43:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mitchpierias/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Advanced EOS Series — Part 9 — Payable Actions]]></title>
            <link>https://medium.com/coinmonks/advanced-eos-series-part-9-payable-actions-42bf878bee36?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/42bf878bee36</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[eosio]]></category>
            <category><![CDATA[smart-contracts]]></category>
            <category><![CDATA[blockchain-development]]></category>
            <category><![CDATA[eos]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Wed, 11 Sep 2019 10:49:01 GMT</pubDate>
            <atom:updated>2020-08-26T11:39:19.559Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced EOS Series — Part 9 — Payable Actions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S6NRjwS8UAP77fq8wXYeuA.jpeg" /></figure><p>The purpose of this series is to bring together the missing pieces you’ll need to complete your skills as a distributed application developer on the EOSIO blockchain. Each post is ordered by difficulty, so if you’ve just stumbled in here and feel lost, I’d recommend <a href="https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8">starting with Part 1</a> and working your way up. The full code for these examples can be found <a href="https://github.com/MitchPierias/advanced-eos-examples/tree/master/09_Payable-Actions">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/advanced-eos-examples">MitchPierias/advanced-eos-examples</a></p><p>By now you’ve managed to achieve all kinds of functionality with your smart contract, but your still missing a fundamental piece, receiving and transferring value…</p><h4>Let’s Get Paid</h4><p>Things are different on the EOSIO network… payments are made to the eosio.token contract, and not directly to the contract’s action like on other blockchains. This means we need to listen for payments being made to our contract and provide the appropriate actions. Don’t worry, it’s simpler than it sounds! We are going to listen to the eosio.token::transfer notification sent by the eosio.token contract. Simply define our handler method by replacing our regular [[eosio::action] definition with [[eosio.token::on_notify(“eosio.token::transfer”)]]. This notification is sent when a token transfer occurs which involves your contract’s account. Let’s breakdown the complete transfer notification handler.</p><pre>[[eosio::on_notify(&quot;eosio.token::transfer&quot;)]] <em>void </em>purchase(name user, name receiver, asset value, string memo) {</pre><pre>   if (receiver != get_self() || caller == get_self()) return;<br>   <br>   eosio::symbol token_symbol(&quot;SYM&quot;, 0);<br>   eosio::check(value.amount &gt; 0, &quot;Insufficient value&quot;);<br>   eosio::check(value.symbol == token_symbol, &quot;Illegal asset symbol&quot;);<br>   <br>   wallet_table balances(get_self(), get_self().value);<br>   <em>auto</em> wallet = balances.find(caller.value);<br>   <br>   if (wallet != balances.end()) {<br>     balances.modify(wallet, get_self(), [&amp;](<em>auto</em> &amp;<em>row</em>) {<br>       row.balance += value.amount;<br>     });<br>   } else {<br>     balances.emplace(get_self(), [&amp;](<em>auto</em> &amp;<em>row</em>) {<br>       row.account = caller;<br>       row.balance = value.amount;<br>     });<br>   }<br>}</pre><p>You’ll notice our method looks very similar to a regular action, and that’s because it is an action! The difference being, this action is called by an INLINE_ACTION invoked by the eosio.token contract, and not directly by public accounts.</p><h4>Breaking it down</h4><p>Let’s pull apart each line and look at what it’s doing. The method definition includes our subscription to the eosio.token::transfer notification. We need to handle all the arguments passed along with the notification.</p><pre>[[eosio::on_notify(&quot;eosio.token::transfer&quot;)]] <em>void </em>purchase(name user, name receiver, asset value, string memo) {<br>  ... contract code ...<br>}</pre><p>The first argument is the eosio::name value of the transfer sender, the second is the eosio::name value of the receiver. This should be your contracts account name when receiving funds, we will validate this in the next part. Finally we have the transfer value as an eosio::asset and a memo std::string.</p><p>Okay, now before we do anything, we first need to validate the sending and receiving participants are who we expected. It’s time to validate!</p><pre>if (receiver != get_self() || caller == get_self()) return;</pre><p>This line is our sanity check, first making sure our contract get_self() is the intended receiver, and secondly, that our contract did not call this transfer on itself.</p><pre>eosio::symbol token_symbol(&quot;SYM&quot;, 0);<br>eosio::check(value.amount &gt; 0, &quot;Insufficient value&quot;);<br>eosio::check(value.symbol == token_symbol, &quot;Illegal asset symbol&quot;);</pre><p>We will continue validating the transferred asset by first defining the token symbol, then checking the sent value greater than zero, and it’s symbol matches that which we expect. You should do any other kind of validation you’d like here. You might want to check the current time is within your funding period, or that the caller is a registered and active user.</p><p>Now we’ve validated our arguments, we can perform the actions we’d like to undertake.</p><pre>wallet_table balances(get_self(), get_self().value);<br><em>auto</em> wallet = balances.find(caller.value);</pre><p>First we will allocate our wallet_table and search for our caller. Allot of this will now look similar to the previous sections on multi_index tables.</p><pre>if (wallet != balances.end()) {<br>  balances.modify(wallet, get_self(), [&amp;](<em>auto</em> &amp;<em>row</em>) {<br>    row.balance += value.amount;<br>  });<br>} else {<br>  balances.emplace(get_self(), [&amp;](<em>auto</em> &amp;<em>row</em>) {<br>    row.account = caller;<br>    row.balance = value.amount;<br>  });<br>}</pre><p>The last piece of code simply checks if the wallet was found (user’s transferred before), then either creates a new entry or updates the existing balance.</p><p>And that’s it! If your deploying to a local blockchain, you’ll need to also deploy the eosio.token contract and then create and issue tokens before you can execute a transfer to your account. Please follow the <a href="https://developers.eos.io/eosio-home/docs/token-contract">official documentation</a> if you need a step-by-step guide on interacting with the eosio.token contract.</p><h4>Debugging</h4><p>You might run into pesky errors working with transfers and assets. I stumbled into the symbol precision mismatch error, thrown when you attempt to issue or transfer assets using a different precision than was specified at creation. So if I created my asset with 10000.00 SYS, then I’d need to issue and transfer using two decimal precision like 12.00 SYS and not 12 SYS.</p><h4>What’s next?</h4><p>Make sure you click the <em>follow</em> button if you would like to be notified when I share more examples in this series. Alternatively follow my GitHub profile, and don’t forget to clap and star to show appreciation.</p><p><a href="https://github.com/MitchPierias/advanced-eos-examples">MitchPierias/advanced-eos-examples</a></p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42bf878bee36" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/advanced-eos-series-part-9-payable-actions-42bf878bee36">Advanced EOS Series — Part 9 — Payable Actions</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Complete Electron Pipeline — Development to Rollout]]></title>
            <link>https://medium.com/@mitchpierias/the-complete-electron-pipeline-development-to-rollout-63668dd46649?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/63668dd46649</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[electron]]></category>
            <category><![CDATA[gatsbyjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Mon, 04 Feb 2019 03:40:48 GMT</pubDate>
            <atom:updated>2019-02-04T18:18:58.913Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Complete Electron Pipeline — Development to Rollout</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jz_lS3wHIYTp9R2s7DOfRw.jpeg" /></figure><p>This article aims to outline a complete Electron development to rollout project pipeline. I’ll be covering everything from creating your initial Electron boilerplate with React, all the way through to building and publishing to an Amazon AWS S3 Bucket. We will then look at creating a static Gatsby site to list our distributions, delving into automatic S3 deployment and utilizing CloudFront and Route 53. The complete project for this can be <a href="https://github.com/MitchPierias/Agora">found on Github</a>.</p><p><a href="https://github.com/MitchPierias/Agora">MitchPierias/Agora</a></p><h3>The Project Environment</h3><h4>Electron with React Boilerplate</h4><p>Let’s get our project started by laying out our boilerplate, we’re going to make this easier by using create-reacton-app. Short disclaimer, I wrote it… so if your having problems, sorry! Okay back to work, install create-reactron-app globally and then execute with your PROJECT_NAME.</p><pre>npm install -g create-reactron-app<br>create-reactron-app PROJECT_NAME<br>cd PROJECT_NAME</pre><p>It’s that simple! Now you have a fully fledged Electron app with React boilerplate! You can run npm run start to open a development environment or npm run build &amp;&amp; npm run dist to compile distribution binaries. It’s up to you what you’d like your app to do and look like from here. In the next section we will look at publish your distributions so their available to anyone!</p><h3>Publishing Distributions</h3><p>Let’s look at deploying out binaries for public access using an Amazon AWS S3. You’ll need to setup an <a href="https://aws.amazon.com/">Amazon AWS account</a> before we start an hopefully have experience with the AWS services.</p><h4>Getting your credentials</h4><p>Login to your AWS account and access the <strong>IAM service</strong> and <a href="https://console.aws.amazon.com/iam/home?#/users">navigate into the users</a> area. Select <strong>Add User</strong> and specify a name for the user who will access this projects deployment bucket, I named mine after the project agora-deploy. Tick <strong>Programmatic access</strong> and proceed to <strong>Set permissions</strong>. Here you want to search for <em>‘S3’ </em>and select the <strong>S3-Manager </strong>permission. This will grant full access to S3 instances, primarily the read-write we need. Finally <strong>Add Tags,</strong> <strong>Review</strong> and <strong>Create user</strong> once you’ve configured any extras. Be sure to copy the access_key_id and access_secret_key displayed, we will need these later to configure the AWS-CLI. The permissions for your new user should now contain at least the following.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*joSvez9wfGh58jHuGInEFg.png" /><figcaption>IAM Access Permissions</figcaption></figure><h4>AWS Command Line Interface</h4><p>Please follow the instructions on the following link to install and setup AWSCLI for your operating system.</p><p><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html">What is the AWS Command Line Interface?</a></p><p>Once you’ve got the command line tools working, open the credentials file with nano ~/.aws/credentials and insert the keys we copied early when creating a new IAM user. I’ve named my configuration agora-deploy, this is useful if you have multiple projects with separate AWS access on your system.</p><pre>[agora-deploy]<br>aws_access_key_id=JFRSHDKGYCNFPZMWUTBV<br>aws_secret_access_key=FK84mfPSdRtZgpDqWvb04fDen0fr3DZ87hTYEE1n</pre><h4>S3 Buckets</h4><p>Now that you’ve setup your command line, navigate back to AWS console and create a new bucket to hold your distribution binaries. Just use the default settings when creating the bucket, then navigate through the Permissions and into the Bucket Policy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*E7qMVUhxPi4OH-GuoO0yKg.png" /><figcaption>Bucket policy permissions</figcaption></figure><p>Insert the following policy, granting public access to GetObject’s from the bucket. Be sure to insert YOUR_BUCKET_ARN followed by the top level directory your opening, I used /* here for all contents.</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;PublicReadGetObject&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: &quot;*&quot;,<br>            &quot;Action&quot;: &quot;s3:GetObject&quot;,<br>            &quot;Resource&quot;: &quot;YOUR_BUCKET_ARN/*&quot;<br>        }<br>    ]<br>}</pre><p>And your set, the buckets now ready to serve your distribution. You could manually upload the build files, or continue onto the next section were we will look at automating distribution publishing.</p><h4>Configuring Electron-Builder</h4><p>We need to add some additional configuration to our Electron build properties for our new S3 instance. Add the following publish settings to your package.json.</p><pre>&quot;build&quot;: {<br>  ...<br>  &quot;publish&quot;: [<br>    {<br>      <em>&quot;provider&quot;</em>:&quot;s3&quot;,<br>      &quot;bucket&quot;:&quot;YOUR_BUCKET_NAME&quot;<br>    }<br>  ]<br>}</pre><p>I also updated my scripts with the following two commands.</p><pre><em>&quot;scripts&quot;: {<br>  ...<br>  &quot;dist&quot;</em>: &quot;electron-builder --publish never --linux --mac&quot;,<br>  <em>&quot;release&quot;</em>: &quot;npm run dist --publish always&quot;<br>}</pre><p>The dist script compiles binaries without publishing and the release script executes the dist script with while overwriting the --publish flag. If you’ve configured your AWS command line credentials and spelled everything correctly, you should be able to run npm run release to have electron-builder build and publish your distributions.</p><h3>Content Delivery</h3><p>Now that we have our application project setup, building and publishing, we can move onto creating our web interface to help user easily find the installer they need. The source code for this section can be found at the following GitHub repository.</p><p><a href="https://github.com/MitchPierias/Agora-Static">MitchPierias/Agora-Static</a></p><h4>Project Setup</h4><p>I’m going to be building a static site to list the distributions. For this I’ll be using Gatsby and configuring automatic publishing to S3, and served from CloudFront. Let’s start by installing Gatsby’s command line interface tools, then run gatsby new followed by our application name to create our project boilerplate.</p><pre>npm install -g gatsby-cli<br>gastby new APP_NAME</pre><p>I’ll quickly add links to the binaries using the S3 Object URL within the index.js component. You can build your site out however you’d like here.</p><pre>&lt;Link to=”<a href="https://s3-ap-southeast-2.amazonaws.com/agora-distribution/Agora-0.2.3.dmg">https://s3-ap-southeast-2.amazonaws.com/agora-distribution/Agora-0.2.3.dmg</a>”&gt;Mac&lt;/Link&gt;<br>&lt;Link to=” <a href="https://s3-ap-southeast-2.amazonaws.com/agora-distribution/Agora+0.2.3.AppImage">https://s3-ap-southeast-2.amazonaws.com/agora-distribution/Agora+0.2.3.AppImage</a>”&gt;Linux&lt;/Link&gt;</pre><p>Finally we can run npm run build to compile our static site. We can move onto configuring our S3 and CloudFront environment to display it. The output of our build will be in the public folder, the contents of this folder is what we will move to our S3 Bucket.</p><blockquote>Please be aware that some AWS services can take up to 24 hours to propagate changes across all edge locations, and be discoverable.</blockquote><p>Before we can begin, you’ll need to have a domain name ready. We could do this with the resource URL’s generated for our instances, but there’s really no reason you’d ever need to do such a thing.</p><h4>Configuring HTTPS</h4><p>As a bonus to our users, we’re going to setup SSL so they can trust we really are who we say we are. Within the AWS console, navigate to the <strong>Certificate Manager</strong> and <strong>Request a certificate</strong>. Follow the prompts to setup, entering your domain or multiple domains, and selecting <strong>DNS Validation</strong> as the validation method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*SeUyofLZogMMTNnahV5tRA.jpeg" /></figure><p>Once your certificate has been requested, you’ll need to follow the instructions listed to complete issuance. It may take up too an hour for Route 53 and Certificate Manager to synchronize and issue the certificate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/1*Ux2dnQLHWk2jsLlOfRYQrA.png" /></figure><h4>S3 Hosting</h4><p>We’re going to need an S3 bucket to hold all our static build files. Open S3 and create a new bucket, using your domain name as the bucket’s name. Next open the bucket settings navigate to <strong>Properties</strong> and configure your Static website hosting like so. We’re telling our bucket to act as a web server, returning the specified index document when no resource is specified and the error document when a resource isn’t found. We will set ours as the default files outputted from Gatsby’s build process. We don’t need to configure our bucket policy yet, we will have CloudFront do that later.</p><h4>Setting up Cloudfront</h4><p>We could configure our S3 Bucket to directly serve our content, but then we loose the advantage of SSL encryption and high speed delivery. Let’s setup a CloudFront instance instead to build an edge cache from our bucket contents and deliver it with SSL. Open the <strong>CloudFront Service</strong> within AWS, <strong>Create Distribution</strong>, and Get Started with a <strong>Web distribution</strong>. We have a little bit to configure here so stay patient.</p><p><strong>Origin Settings</strong></p><ul><li><strong>Origin Domain Name: </strong>YOUR_S3_BUCKET_ARN</li></ul><p><strong>Default Cache Behavior Settings</strong></p><ul><li><strong>Viewer Protocol Policy:</strong> Redirect HTTP to HTTPS</li></ul><p><strong>Distribution Settings</strong></p><ul><li><strong>SSL Certificate:</strong> Custom SSL Certificate <em>(Select the cert assigned earlier)</em></li><li><strong>Default Root Object:</strong> index.html</li></ul><p>You can setup any additional configuration here you like, like custom headers. Next select <strong>Create Distribution</strong> and Amazon will start up the new instance. This will take some time, go have a coffee while the instance starts and propagates across all edge locations. We will need the service to be discoverable for the next section, configuring Route 53.</p><h4>Domain Routing</h4><p>So we’ve setup CloudFront to cache and serve our static site from S3, now we need to configure Route53 to provide a user friendly domain for our CloudFront instance. Navigate over to <strong>Route53</strong>, select the <strong>Hosted Zone</strong> associated with your domain, or create one if you haven’t already. Then <strong>Create Record Set</strong>, type A — IPv4 address, select Alias Yes and set the Alias Target as your CloudFront instance. Again, the CloudFront instance could take up too 24 hours to appear across other services. Once this is setup, you should be able to visit your domain after a few minutes and see your static site appear.</p><h4>Automating S3 Deployment</h4><p>We previous manually copied the entire contents of the build folder into our S3 bucket. There’s nothing technically wrong with this… but we’re all about automation and making things simpler! So let’s setup gatsby-plugin-s3 to deploy our build to S3 in just one command.</p><pre>npm install -s gatsby-plugin-s3</pre><p>Then we want to configure the plugin within our gatsby-config.js file. Add the following configuration object into the plugins array:</p><pre>plugins: [<br>  ...<br>  {<br>    resolve: &#39;gatsby-plugin-s3&#39;,<br>    options: {<br>      bucketName: &#39;agora.pierias.com&#39;<br>    }<br>  }<br>  ...<br>]</pre><p>Finally we’re going to add a deploy command to the package.json like so:</p><pre><em>&quot;scripts&quot;</em>: {<br>  <em>...<br>  &quot;deploy&quot;</em>: &quot;gatsby-plugin-s3 deploy&quot;<br>  ...<br>}</pre><p>Before you can run this you’ll need to call npm run build to update the plugins in .cache, then you can run the npm run deploy command, following the prompts to deploy to S3. Remember to setup your ~/.aws/credentials with your AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY from the AWS IAM service. More details on the <a href="https://www.gatsbyjs.org/docs/deploying-to-s3-cloudfront">S3 plugin can be found here</a>.</p><h4>Thank you!</h4><p>You should now have a full production pipeline setup. We could also add a GraphQL query to our Gatsby site in order to fetch the latest build resource URL from our deployment S3 Bucket. If you’d like to visit the live website deployed in this example, it can be found at <a href="https://agora.pierias.com/">https://agora.pierias.com</a>.</p><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p>📝 Read this story later in <a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_read_later_text">Journal</a>.</p><p>🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: <a href="https://usejournal.com/newsletter/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text">Get the noteworthy newsletter &gt;</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=63668dd46649" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced EOS Series — Part 6 —Contract-to-Contract Communication]]></title>
            <link>https://medium.com/coinmonks/advanced-eos-series-part-6-contract-to-contract-communication-ab352a8b60aa?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/ab352a8b60aa</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[eos]]></category>
            <category><![CDATA[eosio]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Thu, 31 Jan 2019 03:50:21 GMT</pubDate>
            <atom:updated>2020-08-26T15:13:18.456Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced EOS Series — Part 6 —Contract-to-Contract Communication</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*neSMLfVmMP0XASz1D-7j0w.jpeg" /></figure><p>Welcome back to the Advanced EOS development series, here I’ll be touching on techniques and functionality rarely covered by tutorials or courses. The purpose of this series is to bring together the missing pieces you’ll need to complete your skills as a distributed application developer on the EOSIO blockchain. Each post is ordered by difficulty, so if you’d like a general overview I’d recommend <a href="https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8">starting with Part 1</a> and working your way up. The full code for these examples can be found <a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/06_Contract-to-Contract-Communication">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/06_Contract-to-Contract-Communication">MitchPierias/Advanced-EOS-Examples</a></p><blockquote>As these are advanced topics, I’m dangerously assuming you already know the basics and are looking to further your knowledge. For that reason, the code shared in these articles will be concise to the topic being discussed.</blockquote><h3>Before we start…</h3><p>Executing inline actions requires custom account permissions. Due to security reasons, the release version of EOS now requires the eosio.code permission on the contract invoking an inline action. Let’s look at creating custom permissions for our contract account.</p><h4><strong>Modifying Account Permissions</strong></h4><p>To being we modify the permissions of our timeline account before invoking actions on our user contract. We need the eosio.code permission to invoke our inline actions, so we&#39;re going to overwrite our active key on the account calling the actions. Let&#39;s use the cleos set account permission command to achieve this.</p><pre>cleos set account permission timeline active<br>&#39;{<br>  &quot;threshold&quot;:1,<br>  &quot;keys&quot;:[{<br>    &quot;key&quot;:&quot;YOUR_PUBLIC_KEY&quot;,<br>    &quot;weight&quot;:1<br>  }],<br>  &quot;accounts&quot;:[{<br>    &quot;permission&quot;:{<br>      &quot;actor&quot;:&quot;timeline&quot;,<br>      &quot;permission&quot;:&quot;eosio.code&quot;<br>    },&quot;weight&quot;:1<br>  }]<br>}&#39;<br>owner -p timeline@owner</pre><p>Now we’ve modified our permissions, we can take a closer look at the eosio::action method to invoke actions between one contract and another.</p><h4>The User Contract</h4><p>To begin we will write a user contract to manage registration, activation and validation of our users. Let’s define our user Profile struct and a create action to register new users. We will also quickly add a activate action to change the active state on our users. Remember to initialize your contract and serialize your ABI actions.</p><pre>// @abi action<br>void create(const account_name username) {<br>  profile_table profiles(_self, _self);<br>  auto result = profiles.find(username);<br>  eosio_assert(result == profiles.end(), &quot;User already registered&quot;);<br>  // Store new user profile<br>  profiles.emplace(_self, [&amp;](auto&amp; profile) {<br>    profile.uuid = username;<br>  });<br>}</pre><pre>// @abi action<br>void activate(const account_name username, bool isActive) {<br>  profile_table profiles(_self, _self);<br>  auto results = profiles.find(username);<br>  profiles.modify(results, 0, [&amp;](auto&amp; profile) {<br>    profile.active = isActive;<br>  });<br>}</pre><pre>// @abi table profiles i64<br>struct Profile {<br>  uint64_t      uuid;<br>  bool          active = true;<br>  bool          approved = true;<br>  bool          flagged = false;<br>  auto primary_key() const { return uuid; }<br>  EOSLIB_SERIALIZE(Profile, (uuid)(active)(approved)(flagged));                         };</pre><pre>typedef multi_index&lt;N(profiles), Profile&gt; profile_table;</pre><p>We’re also going to write a validate method to check if a specified user passes all our validation requirements. For this we will fetch the user’s profile and check their active state, if they’ve been flagged <em>(warned)</em> and if they’re account is approved.</p><pre>// @abi action<br>void validate(const account_name username) {<br>  profile_table profiles(_self, _self);<br>  auto results = profiles.find(username);<br>  eosio_assert(results-&gt;active, &quot;User inactive&quot;);<br>  eosio_assert(!results-&gt;flagged, &quot;User flagged&quot;);<br>  eosio_assert(results-&gt;approved, &quot;User not approved&quot;);                         }</pre><h4>The Timeline Contract</h4><p>Now we’re going to write a timeline contract to handle publishing and removing posts. To keep this post concise I’m just going to be covering the publishing aspect. Let’s define the Tweet struct to store our published tweets.</p><pre>// @abi table tweets i64<br>struct Tweet {<br>  uint64_t       id;<br>  account_name   author;<br>  string         msg;<br>  bool           flagged;<br>  auto primary_key() const { return id; }<br>  EOSLIB_SERIALIZE(Tweet, (id)(author)(msg)(flagged));<br>};</pre><pre>typedef multi_index&lt;N(tweets), Tweet&gt; tweet_table;</pre><h4>Inter-contract Communication</h4><p>Our inter-contract communication is going to happen when we attempt to publish a tweet with our timeline contract. We will need to validate our user’s account before we store the tweet. Let’s use the action(PERMISSIONS,TO_ACCOUNT,TO_ACTION,DATA_TUPLE).send() method to call our validate action on our user contract.</p><pre>// @abi action<br>void publish(const account_name username, const string&amp; msg_str) {<br>  <br>  eosio::action(<br>    permission_level{_self, N(active)},<br>    N(user),<br>    N(validate),<br>    std::make_tuple(username)<br>  ).send();</pre><pre>  tweet_table tweets(_self, _self);<br>  tweets.emplace(_self, [&amp;](auto&amp; obj) {<br>    obj.id = tweets.available_primary_key();<br>    obj.author = username;<br>    obj.msg = msg_str;<br>  });<br>}</pre><p>It’s as simple as that! You should be able to call another contract’s action as long as you’ve correctly setup eosio.code permissions on the contract’s account making the calls.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ab352a8b60aa" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/advanced-eos-series-part-6-contract-to-contract-communication-ab352a8b60aa">Advanced EOS Series — Part 6 —Contract-to-Contract Communication</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced EOS Series —  Part 5 — One-to-many Relationships]]></title>
            <link>https://medium.com/coinmonks/advanced-eos-series-part-5-one-to-many-relationships-42d2e075e05d?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/42d2e075e05d</guid>
            <category><![CDATA[blockchain-developer]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[eos]]></category>
            <category><![CDATA[dapps]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Fri, 11 Jan 2019 04:11:58 GMT</pubDate>
            <atom:updated>2020-08-26T15:36:36.639Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced EOS Series — Part 5 — One-to-many Relationships</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*qFR_SZnTB-EEPtUP5NSnFg@2x.jpeg" /></figure><p>Welcome back to the Advanced EOS development series, here I’ll be touching on advanced techniques and functionality which is rarely covered by tutorials or courses. The purpose of this series is to bring together the missing pieces you’ll need to complete your skills as a distributed application developer on the EOS network. Each post is ordered by difficulty, so if you’d like a general overview I’d recommend <a href="https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8">starting with Part 1</a> and working your way up. The full code for these examples can be found <a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/05_Table-One-To-Many-Relationships">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/05_Table-One-To-Many-Relationships">MitchPierias/Advanced-EOS-Examples</a></p><blockquote>As these are advanced or extended topics, I’m dangerously assuming you already know the basics and are looking to further your knowledge. For that reason, the code shared in these articles will be concise to the purpose being discussed.</blockquote><p>This post will be relatively short, but cover a fundamental and seemingly uncovered method with multi index tables, unique primary indexes.</p><h3>One-to-many Relationships</h3><p>I come from a background in <a href="https://neo4j.com/developer/graph-database/">Graph Databases</a>, a wonderful land where data is directly linked too it’s related data, like MySQL joins but on steroids. So if you’re like me and have mastered the basics of EOS tables, then you’ve probably asked the question, but how do I create a relationship between multiple tables and rows? Well in this example we’ll be looking into not one, but multiple methods for creating one-to-many relationships using EOS multi_index tables.</p><p>In these examples we will look at three different methods for creating relationships between our EOS table rows; Vectors, Indexes and Scopes.</p><blockquote>For simplicity, the following examples will not be validating the caller account.</blockquote><h3>Vectors</h3><p><a href="http://www.cplusplus.com/reference/vector/vector/">Vectors in C++</a> represent the structure of a dynamic array, allowing us to store an arbitrarily sized collection of values. Let’s explore vectors by storing an array of unique Item identifiers for a players Profile. Here identifiers stored in the Profile table will correspond to the id of rows in our Item table.</p><pre>struct Profile {<br>  name              account;<br>  vector&lt;uint64_t&gt;  items;<br>}<br><br>struct Item {<br>  uint64_t          id;<br>  string	            name;<br>}</pre><p>Now inside our create() method, we can simply push a reference to the Item using the Item.id we stored prior and the push_back() method of the vector class.</p><pre>owners.modify(currentPlayer, 0, [&amp;](auto&amp; owner) {<br>  owner.items.push_back(itemID);<br>});</pre><p>We can even go a step further and define a sub-collection within our item vector vector&lt;uint64_t, uint32_t&gt; items; where uint64_t is our item identifier and uint32_t is the item’s age. Alternatively a secondary struct (collection) can be stored inside the vector like vector&lt;Item&gt; items;.</p><p>Vectors are a great way to store related data and references directly within our table, however table rows can quickly grow large from excessive user input or improper data management. Let’s explore Secondary Indexes instead to create relationships between our tables.</p><h3>Secondary Indexes</h3><p>Using secondary indexes provides an alternative way we can scale our references while avoiding excessively large arrays <em>(vectors)</em> in our table rows. It also allows us to move seamlessly between parent-child rows in our table by using a backwards reference from the child to the parent. Let’s take a practical look at this by extending our project from our previous Vector section. First we’re going to modify our structures, removing the items vector from the Profile struct and adding a reference to our owner within the Item struct.</p><pre>struct Profile {<br>    name 	account;<br>}<br><br>struct Item {<br>    uint64_t	uid;<br>    string	name;<br>    name		owner;<br>}</pre><p>Now we need to add search functionality so we can find our Item by owner. Let’s create a secondary index and add it too our multi_index definition.</p><pre>struct Item {<br>    ...<br>    uint64_t get_owner() const { return owner; }<br>}<br><br>typedef multi_index&lt;N(items), Item, indexed_by&lt;N(byowner), const_mem_fun&lt;Item, uint64_t, &amp;Item::get_owner&gt;&gt; item_table;</pre><p>Where the name of our index will be byowner and it will return the uint64_t owner key using the get_owner function.</p><blockquote>The multi_index method allows us to define up too 16 additional indexes for each table.</blockquote><p>We will no longer be updating our Player from within our add item function. Instead we will be storing a reference to the signee account in the owner property of our newly created item. Let’s update our additem action to achieve this;</p><pre>items.emplace(account, [&amp;](auto&amp; item) {<br>    ...<br>    item.owner = account;<br>});</pre><p>Now we can get all our items for a player like so;</p><pre>void indexes::get(const name account) {<br>  item_table items(_self, _self);<br>  auto accounts_items = items.get_index&lt;N(byowner)&gt;();<br>  auto iter = accounts_items.lower_bound(account);<br>  while (iter != accounts_items.end(); iter++) { // Do stuff }<br>}</pre><h3>Scope</h3><p>For this final method we’re going to use the table scope to represent relationships between our table rows. Using the scope adds a form of protected security, where data can only be found if it’s scope is known.</p><h4>The EOS Data Structure</h4><pre><em>- code       * The account name assigned write permission (contract)<br>-- scope     * The account where the data is stored<br>--- table    * Name of the table being stored<br>---- record  * A table row</em></pre><p>We’re going to modify our Item to utilize the table scope for looking up all player&#39;s items. To simplify our project, we’ll remove remove the owner reference and get_owner() index from our Item struct and multi_index table definition.</p><pre>struct Item {<br>    uint64_t    	id;<br>    string	name;<br>    auto primary_key() const { return id; };<br>    EOSLIB_SERIALIZE(Item, (id)(name));<br>};<br><br>typedef multi_index&lt;N(items), Item&gt; item_table;</pre><p>The real magic happens over in our setters and getters, let’s take a look at how they’ve changed.</p><pre>item_table items(_self, account);<br>auto item = items.emplace(account, [&amp;](auto&amp; item) {<br>  ... configure item<br>});</pre><p>If you look at our table instantiating, you’ll notice we are now using the scope of our account, rather than the contract’s code itself. Our get action has been modified in the same way.</p><pre>item_table items(_self, account);<br>auto iter = playerItems.lower_bound();<br>while (iter != playerItems.end()) { ... }</pre><p>Simple as that! Isolating data with the scope makes finding data relative to the user is much simpler, however, things like counting all items for all users becomes much more difficult. It’s important to choose a method(s) that apply to the objective of your application.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42d2e075e05d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/advanced-eos-series-part-5-one-to-many-relationships-42d2e075e05d">Advanced EOS Series —  Part 5 — One-to-many Relationships</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced EOS Series — Part 4 — Table Uniqueness]]></title>
            <link>https://medium.com/coinmonks/advanced-eos-series-part-4-table-uniqueness-835843a207fc?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/835843a207fc</guid>
            <category><![CDATA[eos]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[blockchain-development]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Mon, 24 Dec 2018 05:35:58 GMT</pubDate>
            <atom:updated>2020-08-27T11:54:01.937Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced EOS Series — Part 4 — Table Uniqueness</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EiofFa9-wj6IoL06gbTilw@2x.jpeg" /></figure><p>Welcome back to the Advanced EOS development series, here I’ll be touching on advanced techniques and functionality which is rarely covered by tutorials or courses. The purpose of this series is to bring together the missing pieces you’ll need to complete your skills as a distributed application developer on the EOS network. Each post is ordered by difficulty, so if you’d like a general overview I’d recommend <a href="https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8">starting with Part 1</a> and working your way up. The full code for these examples can be found <a href="https://github.com/MitchPierias/Advanced-EOS-Examples">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/04_Table-Uniqueness">MitchPierias/Advanced-EOS-Examples</a></p><blockquote>As these are advanced or extended topics, I’m dangerously assuming you already know the basics and are looking to further your knowledge. For that reason, the code shared in these articles will be concise only to the purpose being discussed.</blockquote><p>This post will be relatively short, but cover a fundamental and seemingly uncovered method with multi index tables, unique primary indexes.</p><h3>Unique Indexes</h3><p>By now we’re able to create rows in our tables indexed by our unique account_name identifiers, but how do we use a different primary_key and ensure it&#39;s unique? Fortunately the developers at EOSio have provided us with the available_primary_key() function.</p><p>Let’s begin by creating a struct to define an Item in our items table. We’ll use a uint64_t like normal to specify our primary key called id.</p><pre>// @abi table items i64<br>struct Item {<br>  uint64_t          id;<br>  string            name;<br>  uint64_t          attack;<br>  account_name      owner;<br><br>  auto primary_key() const { return id; };<br>  EOSLIB_SERIALIZE(Item, (id)(name)(attack));<br>};<br><br>typedef multi_index&lt;N(items), Item&gt; items_table;</pre><p>You’ll notice this is the same table struct we used in <a href="https://medium.com/coinmonks/advanced-eos-series-part-3-secondary-indexes-1798f339cbb8">Advanced EOS Series — Part 3 — Secondary Indexes</a>. Let’s now update our actions to generate a unique primary key, instead of requiring them as an argument.</p><pre>void inventory::create(const account_name account, const string name, const uint64_t attack) {<br><br>  items_table items(_self, _self);<br><br>  items.emplace(account, account, [&amp;](auto&amp; item) {<br>    item.id = items.available_primary_key();<br>    item.name = name;<br>    item.attack = attack;<br>    item.owner = account;<br>  });<br>}</pre><p>We’ve removed the uint64_t indexfrom our action void post(const account_name username, uint64_t index const string&amp; msg_str), and we’ve replaced the index with items.available_primary_key() to set the primary key id when we’re creating a new item.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><figure><a href="http://bit.ly/2G71Sp7"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKX2mtg7p1lOs7JmosPLsA.png" /></a></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=835843a207fc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/advanced-eos-series-part-4-table-uniqueness-835843a207fc">Advanced EOS Series — Part 4 — Table Uniqueness</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced EOS Series — Part 3 — Secondary Indexes]]></title>
            <link>https://medium.com/coinmonks/advanced-eos-series-part-3-secondary-indexes-1798f339cbb8?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/1798f339cbb8</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[blockchain-development]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[eos]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Mon, 17 Dec 2018 03:19:29 GMT</pubDate>
            <atom:updated>2020-08-27T12:34:19.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yDR8EaAMFVj9dY17rk3V1g@2x.jpeg" /></figure><h3>Advanced EOS Series — Part 3 — Secondary Indexes</h3><p>Welcome back to the Advanced EOS development series, here I’ll be touching on advanced techniques and functionality which is rarely covered by tutorials or courses. The purpose of this series is to bring together the missing pieces you’ll need to complete your skills as a distributed application developer on the EOS network. Each post is ordered by difficulty, so if you’d like a general overview I’d recommend <a href="https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8">starting with Part 1</a> and working your way up. The full code for these examples can be found <a href="https://github.com/MitchPierias/Advanced-EOS-Examples">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/03_Secondary-Indexes">MitchPierias/Advanced-EOS-Examples</a></p><blockquote>As these are advanced or extended topics, I’m dangerously assuming you already know the basics and are looking to further your knowledge. For that reason, the code shared in these articles will be concise only to the purpose being discussed.</blockquote><h3>Primary Indexes</h3><p>By now you should know how to define a multi-index table in EOS using a struct, but for the sake of completeness let’s briefly glance over our basic table definition.</p><h4>Defining the struct</h4><p>we’re going to start by defining our struct and it’s required primary_key function which is the index used when we call find(KEY) . For now let’s use the users account_name for uniqueness and cover a more versatile method in the following chapter.</p><pre>// @abi table items i64<br>struct Item {<br>  account_name      id;<br>  string            name;<br>  uint64_t          attack;<br>  account_name      owner;<br><br>  auto primary_key() const { return id; };<br>  EOSLIB_SERIALIZE(Item, (id)(name)(attack)(owner));<br>};</pre><h4>Creating the Table</h4><p>Now we’ve outlined our structure. we can define our multi-index table using the multi_index&lt;TABLE_NAME, TABLE_STRUCT&gt; method from the EOS library;</p><pre>typedef multi_index&lt;N(items), Item&gt; items_table;</pre><p>After our typedef, we can simply define a reference and then initialize our table in our constructor, or we can initialize a reference within each function as we need it.</p><h3>Secondary Indexes</h3><p>Let’s expand the functionality of our table by adding a secondary index to fetch items by their respective owner. Our Item struct will now look like;</p><pre>// @abi table items i64<br>struct Item {<br>  auto              id;<br>  string            name;<br>  uint64_t          attack;<br>  account_name      owner;<br><br>  auto primary_key() const { return id; };<br>  uint64_t get_owner() const { return owner; };<br>  EOSLIB_SERIALIZE(Item, (id)(name)(attack)(owner));<br>};</pre><p>I’ve added the line unit64_t get_owner() const { return owner; }; below our primary_key index. This function simply returns the value for owner when called.</p><h4>Defining the Secondary Index</h4><p>Let’s define this as a secondary index in our multi-index table so we can access it later;</p><pre>typedef multi_index&lt;N(items), Item, indexed_by&lt;N(byowner), const_mem_fun&lt;Item, uint64_t, &amp;Item::get_owner&gt;&gt;&gt; item_table;</pre><p>Don’t let that line scare you, it’s just our previous declaration with one additional argument.</p><pre>indexed_by&lt;N(byowner), const_mem_fun&lt;Item, uint64_t, &amp;Item::get_owner&gt;&gt;</pre><p>This is the line which defines our secondary index. We’re using the indexed_by&lt;INDEX_NAME, LOOKUP_FUNCTION_DEFINITION&gt; to specify the index namedbyowner.</p><ul><li>INDEX_NAME; can be whatever you like and doesn’t need to syntactically match our function get_owner, just remember it’s the name we will use to access the secondary index later in our actions.</li><li>LOOKUP_FUNCTION_DEFINITION: which looks like cons_mem_fun&lt;STRUCT, RETURN_VALUE, LOOKUP_FUNCTION&gt; in our example, constructs our secondary index function and assigns it to the function of our index definition.</li></ul><h4>Using the Secondary Index</h4><p>So we’ve indexed our item’s owner, but how can we use our index to find items owned by a particular user? For this we will be stepping into an action and using the multi-index table method get_index&lt;INDEX_NAME&gt;(), let’s create an action called inventory to fetch a users items.</p><pre>// @abi action<br>void inventory(const account_name account) {<br>  item_table items(_self, _self);<br>  auto playerItems = items.get_index&lt;N(byowner)&gt;();<br>  auto iter = playerItems.lower_bound(account);<br>  while (iter != playerItems.end()) {<br>    print(&quot;Item &quot;, iter-&gt;name);<br>    iter++;<br>  }<br>}</pre><p>Let’s break out the following line and delve a little deeper into what it’s responsible for;</p><pre>auto playerItems = items.get_index&lt;N(byowner)&gt;();</pre><p>This line is using the get_index function of our item_table instance to fetch the index we defined previously. Notice we’re using the same name N(byowner) we specified earlier to reference the index we’re seeking.</p><p>And that’s secondary indexes, now we have our index, we can perform all the functions we would normally do with the primary_index. In the example we’re using lower_bound, but you could use find, get, upper_bound, begin, or end to suit your particular use case.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><figure><a href="http://bit.ly/2G71Sp7"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKX2mtg7p1lOs7JmosPLsA.png" /></a><figcaption><a href="http://bit.ly/2G71Sp7"><strong>Click to read today’s top story</strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1798f339cbb8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/advanced-eos-series-part-3-secondary-indexes-1798f339cbb8">Advanced EOS Series — Part 3 — Secondary Indexes</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Dream Team — React with Electron]]></title>
            <link>https://medium.com/@mitchpierias/the-dream-team-react-with-electron-c808ecb5b55e?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/c808ecb5b55e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[electron]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Fri, 14 Dec 2018 05:07:58 GMT</pubDate>
            <atom:updated>2018-12-26T15:07:06.096Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Dream Team — React with Electron</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jrPO3qBkDhFmj5SGkcGP3Q.jpeg" /></figure><p>So you ‘re either a React developer dabbling into the world of electron, or your looking to extend the abilities of Electron. Either way, you’ve ended up here because you’ve asked yourself the same question that took me down the rabbit hole, “How can I use React inside Electron?”.</p><p>I’m not going to be making anything spectacular in this example. To be honest, I had trouble compiling my own Electron project with React, so I simplified everything down to this boilerplate template. In this example, we’re simply going to make React compile our basic project, then build our application distributions using Electron. The complete code for this example can be found <a href="https://github.com/MitchPierias/React-Electron-Boilerplate">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/React-Electron-Boilerplate">MitchPierias/React-Electron-Boilerplate</a></p><p>I’ve now created a simple create module you can install globally using npm install -g create-reactron-app then simply execute create-reactron-app &lt;APP_NAME&gt; I’m still developing this tool and would appreciate any contributions you’d like to add, the <a href="https://github.com/MitchPierias/Reactron">source code can be found here</a>.</p><h3>Creating the Project</h3><p>Before we can start building our electron application we first need to install a few dependencies and define our project structure. Firstly, create a new directory for your project and navigate inside, then run npm init and fill out the prompts to create your project boilerplate.</p><pre>mkdir reactron &amp;&amp; cd reactron<br>npm init</pre><p>Now we’re ready to start installing our dependencies like React and React DOM! We’re also installing path as a production dependency cause we will be using it in with Electron later.</p><pre>npm install --save react react-dom path</pre><p>I’m not going to go over the React code, that could take a very long time depending on how far we choose to go. So I’m going to assume you know the basics. If not, you can just copy the files in the ./src directory from the <a href="https://github.com/MitchPierias/React-Electron-Boilerplate">GitHub repo</a> and follow <a href="https://www.google.com/search?q=Learn+React">one of these tutorials</a> if you’d like to learn more.</p><h3>Webpack Setup</h3><p>Now we need to compile our React project down into a single bundle, for this we will use Webpack.</p><pre>npm install --save-dev webpack webpack-cli</pre><p>We’re also going to need webpack loaders like babel, style loaders and html compilers, let’s install those and delve a little deeper into what they do.</p><pre>npm install --save-dev babel-core@6 babel-loader@7 babel-preset-env@1 babel-preset-react@6</pre><p>Babel is the loader responsible for parsing all our fancy new-age Javascript into the currently supported specification ES5.</p><ul><li><strong>babel-core:</strong> Transforms your ES6 code into ES5.</li><li><strong>babel-loader:</strong> Webpack helper plugin to parse ES6 dependencies into ES5.</li><li><strong>babel-preset-env:</strong> Determines which transformations/plugins to use and polyfills.</li><li><strong>babel-preset-react:</strong> Presets for all React plugins.</li></ul><pre>npm install --save-dev css-loader style-loader html-webpack-plugin</pre><ul><li><strong>style-loader:</strong> Compiles the referenced <em>css</em> files in our React components and injects them into the build file.</li><li><strong>css-loader:</strong> Is the parser to help Webpack interpret and transform our CSS.</li><li><strong>html-webpack-plugin:</strong> Outputs a compiled <em>html</em> file with resources adn tags linked.</li></ul><p>There’s going to be allot of dependencies building up now… don’t worry, it’s just because of Webpacks extensability. Let’s define our project structure and start coding our resources, your project should resemble something like the following;</p><pre>Reactron<strong><br></strong>|- assets<br>  ...react-assets...<br>|- build<br>  |- bundle.js<br>  |- index.html<br>|- dist<br>  <em>...electron-build-files...</em><br>|- node_modules<br>  <em>...installed-modules...</em><br>|- src<br>  |- <em>index.js</em><br>  |- <em>index.html</em><br>  |- <em>index.css</em><br>|- <em>package.json</em><br>|- <em>main.js</em><br>|- <em>webpack.config.js</em></pre><h4>Configuring Webpack</h4><p>Now we’re ready to start configuring Webpack to bundle our React project and resources into our ./build directory for Electron. To start, open webpack.config.js and import the webpack, path and html-webpack-plugin modules.</p><pre>const webpack = require(&#39;webpack&#39;);<br>const path = require(&#39;path&#39;);<br>const HtmlWebPackPlugin = require(&quot;html-webpack-plugin&quot;);</pre><h4>HTML-Webpack-Plugin</h4><pre>const htmlPlugin = new HtmlWebPackPlugin({<br> title: &quot;Reactron&quot;,<br> template: &quot;./src/index.html&quot;,<br> filename: &quot;./index.html&quot;<br>});</pre><p>Then we will configure our html-webpack-plugin. This will handle injecting resources and data into our ./src/index.html template through the Webpack build process, outputting the compiled result along with the bundled Javascript into the output directory.</p><h4>The Webpack Build Pipeline</h4><p>Now we are finally ready to configure our Webpack build pipline. Below everything we just wrote, define the following;</p><pre>module.exports = {<br> entry: &#39;./src/index.js&#39;,<br> target: &#39;electron-renderer&#39;,<br> output: {<br>  path: path.resolve(__dirname, &#39;build&#39;),<br>  publicPath: &#39;./&#39;,<br>  filename: &#39;bundle.js&#39;<br> },<br> module: {<br>  rules: [<br>   {<br>    test: /\.js$/,<br>    exclude: [<br>     /node_modules/,<br>     /.json?/<br>    ],<br>    use: {<br>     loader: &#39;babel-loader&#39;,<br>     query: {<br>      presets: [&quot;env&quot;,&quot;react&quot;]<br>     }<br>    }<br>   }, {<br>    test: /\.(s*)css$/,<br>    use: [&#39;style-loader&#39;,&#39;css-loader&#39;]<br>   }<br>  ]<br> },<br> plugins:[<br>  htmlPlugin<br> ],<br> resolve: {<br>  extensions: [&#39;.js&#39;,&#39;.jsx&#39;]<br> }<br>}</pre><p>I don’t want too delve deep into Webpack, but you can <a href="https://webpack.js.org/">read the the official documentation and examples here</a> if you’d like to explore it further. This code snippet is essentially telling Webpack where our entry file is, where we want to output, and using what modules and plugins.</p><h3>Electron</h3><p>We’ve now build our Electron renderer with React, bundled with Webpack, and now we’re ready to begin coding our Electron application to serve it all.</p><pre>npm install --save-dev electron</pre><h4>Coding our Electron Application</h4><p>Let’s open the ./main.js file and copy in the following;</p><pre>const { app, BrowserWindow } = require(&#39;electron&#39;);<br>const path = require(&#39;path&#39;);</pre><pre>let mainWindow = null;</pre><pre>function createWindow() {<br> <br> mainWindow = new BrowserWindow({<br>  width:600,<br>  height:400<br> });<br> <br> mainWindow.loadFile(path.resolve(__dirname,&#39;build/index.html&#39;));<br> <br> mainWindow.on(&#39;closed&#39;, () =&gt; {<br>  if (process.platform !== &#39;darwin&#39;) app.quit();<br> });<br>}</pre><pre>app.on(&#39;ready&#39;, createWindow);</pre><p>This is the absolute minimum code to start an Electron application. We’re importing our modules path and the app and BrowserWindow components from electron, then defining an empty mainWindow reference and createWindow() function before attaching it to the app.on(‘ready’) event. Our createWindow function is initializing a new BrowserWindow, loading the ./build/index.html file we compiled with Webpack earlier, and handling the mainWindow.on(‘closed’) event.</p><h4>Running the App</h4><p>And that’s it! We can execute npm webpack --mode production to compile and then node electron . to start our Electron application. Let’s complete our project by compiling everything into a distribution with electron-builder.</p><h3>Electron Builder</h3><pre>npm install --save-dev electron-builder</pre><h4>The Build Property</h4><p>The majority of our electron-builder configuration happens inside the build property of our package.json.</p><pre>&quot;build&quot;: {<br>  &quot;productName&quot;:&quot;Reactron&quot;,<br>  &quot;appId&quot;:&quot;com.reactron.app&quot;,<br>  &quot;directories&quot;: {<br>    &quot;buildResources&quot;:&quot;build&quot;,<br>    &quot;output&quot;:&quot;dist&quot;<br>  }<br>  ...<br>}</pre><p>We’re defining our productName which is self explanatory and the appId which is typically a unique identifier like a URL on the web. The important property is the directories, here you’ll specify the buildResources where Electron will find your bundled Webpack output, and the output setting which defines the directory to output the build.</p><pre>&quot;directories&quot;: {<br>  ...<br>},<br>&quot;files&quot;: [<br>  &quot;**/*&quot;,<br>  &quot;build/**/*&quot;,<br>  &quot;node_modules/**/*&quot;<br>]</pre><p>Now we specify the files to scan and package into our application bundle and we’re ready to run!</p><pre>node electron-builder</pre><h4>Notes</h4><ul><li>Electron code signing for Mac will only resolve on a Mac.</li><li>Can’t find file public/electron.js requires “extends”:null in the package.json build settings.</li></ul><h4>Resources</h4><ul><li><a href="https://electronjs.org/docs">Electron Documentation</a></li><li><a href="https://reactjs.org/docs">React Documentation</a></li><li><a href="https://www.electron.build/configuration/configuration">Electron-Builder Configuration</a></li><li><a href="https://webpack.js.org/concepts/">Webpack Documentation</a></li><li><a href="https://github.com/jantimon/html-webpack-plugin#options">html-webpack-plugin Documentation</a></li></ul><figure><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_image"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f2IVAl0TbsfES9cFGYr40g.png" /></a></figure><p><strong>This story is published in Noteworthy, where 10,000+ readers come every day to learn about the people &amp; ideas shaping the products we love.</strong></p><p><strong>Follow our publication to see more product &amp; design stories featured by the </strong><a href="https://usejournal.com/?utm_source=medium.com&amp;utm_medium=noteworthy_blog&amp;utm_campaign=guest_post_text"><strong>Journal</strong></a><strong> team.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c808ecb5b55e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced EOS Series —  Part 2 — Singletons]]></title>
            <link>https://medium.com/coinmonks/advanced-eos-series-part-2-singletons-9e903772f71c?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/9e903772f71c</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[blockchain-development]]></category>
            <category><![CDATA[eos]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dapps]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Fri, 07 Dec 2018 04:23:08 GMT</pubDate>
            <atom:updated>2020-08-27T13:48:52.263Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aFh0nsIXQHlxxc-wG7llfA@2x.jpeg" /></figure><h3>Advanced EOS Series — Part 2 — Singletons</h3><p>Welcome to the Advanced EOS development series where I’ll be touching on techniques and functionality which is rarely covered by tutorials and courses. The purpose of this series is to bring together the missing pieces you’ll need to complete your skills as an application developer on the EOS network. Each post is ordered by difficulty, so if you’d like a general overview I’d recommend <a href="https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8">starting with Part 1</a> and working your way up. For Part 2 of this series, we will be looking at Singletons, all code for this example can be found <a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/02_Singletons">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/02_Singletons">MitchPierias/Advanced-EOS-Examples</a></p><blockquote>As these are advanced or extended topics, I’m dangerously assuming you already know the basics and are looking to further your knowledge. For that reason, the code shared in these articles will be concise to the topic being discussed.</blockquote><blockquote>Singletons should be used to store contract state, or as an alternative to multi-index tables when only one row is required.</blockquote><h4>Persistence</h4><p>We’re going to explore singletons as a method to persist our contract state. Using a table for this would be a waste of resources given that our data would only ever occupy one row.</p><h4>Defining the Singleton</h4><p>For this example, we will use a singleton to store our contracts configuration state. Let’s define our singleton using a struct. We will use a Boolean called closed and char_count which we can use to limit users post size.</p><pre>struct Config {<br>  bool		closed = false;<br>  uint32_t	char_count = 144;<br>};<br><br>typedef singleton&lt;N(settings), Config&gt; settings_table;</pre><p>Next we will create a placeholder variable for our instance, making it global within the context of our contract.</p><pre>settings_table config;</pre><h4>Initializing the Singleton</h4><p>We can initialize our singleton each time we use it or in our contracts constructor so it’s available within every action of our contract. Our contract in this instance is named singletons, but you can call it what you’d like.</p><pre>singletons(action_name self) : contract(self), config(_self, _self) {}</pre><p>Similar to the multi-index table, initializing the singleton takes a contract-code and scope. In this example we’ve set both the code and scope to _self.</p><h4>Getting Singleton Values</h4><p>Now that we have our singleton initialized, we can start interacting with values by reading our char_count value and printing it to the console.</p><pre>auto state = config.get();<br>print(state.char_count);</pre><p>And that’s it! Our config.get() retrieves the singleton we initialized earlier and assigns it to our state variable. Now we can access the properties of our struct using dot notation.</p><h4>Setting Singleton Values</h4><p>In this example we will update the char_count property using the member function singleton.set(STRUCT,PAYER). Let’s look at two methods to update our singleton.</p><p><strong>Method 1 — Inline Updating</strong></p><p>The simplest method is to build our struct inline, passing it directly to our set function as we set it, like so;</p><pre>config.set(Config{true, 172}, _self);</pre><p>Here we are setting closed to true and our char_count to 172 while delegating _self as the payer for this RAM. This method is clean when your struct contains only a few properties, and maintains property order, but we will need a better method for larger structs.</p><p><strong>Method 2 — Retrieve and Update</strong></p><p>Next let’s reopen our contract using a fetch and update method. First we will get our current Config state using the singleton.get() method, set the closed value, then set the state again.</p><pre>auto state = config.get();<br>state.closed = false;<br>config.set(state, _self);</pre><p>And that’s Singletons, simple! In the next part we will be looking at multi-index table indexes, primarily focusing on using secondary indexes. Make sure to click <em>follow</em> if you’d like to be notified when I share more examples.</p><blockquote><a href="https://coincodecap.com/?utm_source=coinmonks">Get Best Software Deals Directly In Your Inbox</a></blockquote><figure><a href="https://coincodecap.com/?utm_source=coinmonks"><img alt="" src="https://cdn-images-1.medium.com/max/584/0*OJ-qb5G6i863msBB.png" /></a></figure><figure><a href="http://bit.ly/2G71Sp7"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKX2mtg7p1lOs7JmosPLsA.png" /></a><figcaption><a href="http://bit.ly/2G71Sp7"><strong>Click to read today’s top story</strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9e903772f71c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/advanced-eos-series-part-2-singletons-9e903772f71c">Advanced EOS Series —  Part 2 — Singletons</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced EOS Series — Part 1 —  Cryptographic Hashes]]></title>
            <link>https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8?source=rss-cbff57364085------2</link>
            <guid isPermaLink="false">https://medium.com/p/a251a8d371b8</guid>
            <category><![CDATA[blockchain-development]]></category>
            <category><![CDATA[dapps]]></category>
            <category><![CDATA[eos]]></category>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Mitch Pierias]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 07:20:41 GMT</pubDate>
            <atom:updated>2019-10-07T08:55:44.443Z</atom:updated>
            <content:encoded><![CDATA[<h3>Advanced EOS Series — Part 1 — Cryptographic Hashes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9O9awZFyxQjLzA_PFlj6lQ.jpeg" /></figure><p>Welcome to the Advanced EOS development series where I’ll be touching on techniques and functionality which is rarely covered by tutorials and courses. The purpose of this series is to bring together the missing pieces you’ll need to complete your skills as an application developer on the EOS network. Each post is ordered by difficulty, so if you’d like a general overview I’d recommend starting right here and working your way up. The full code for these examples can be found <a href="https://github.com/MitchPierias/Advanced-EOS-Examples">here on GitHub</a>.</p><p><a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/01_Hashes">MitchPierias/Advanced-EOS-Examples</a></p><blockquote>As these are advanced or extended topics, I’m dangerously assuming you already know the basics and are looking to further your knowledge. For that reason, the code shared in these articles will be concise to the topic being discussed.</blockquote><h3>The Cryptographic Hash Function</h3><p>Let’s begin by looking at hashes, all resources for this example can be found <a href="https://github.com/MitchPierias/Advanced-EOS-Examples/tree/master/01_Hashes">here on GitHub</a>. In cryptography, a hashing algorithm takes an input and generates a fixed sized jumble known as the output digest. The digest is deterministic and irreversible, meaning the same input will always generate the same output and the output can’t be reversed to obtain the original input. A good hashing algorithm minimizes output collision by using a ‘high degree of difficulty’ in the shortest amount of computation time. Collision or clashing being the likelihood of two different inputs producing the same output.</p><h4>Application of Hashes</h4><p>Typically we will use a hash function for authentication and indexing data, I like to think of it as a method of compressing uniqueness. For example, comparing two arbitrarily sized files or users emails would be time intensive and expose vulnerable user data. We could instead generate a fingerprint by hashing the files contents or users email and more efficiently index and compare the data using the hash result.</p><p>This is as about as much as we need to know at this point, but if you’d like to itch your curiosity then I’d encourage some proactive Googling or take a look at Blockgeeks article on <a href="https://blockgeeks.com/guides/cryptographic-hash-functions/">The In’s and Outs of Cryptographic Hash Functions</a>.</p><h3>Coding Our Hash Function</h3><p>Now that we have a very basic understanding of hashes, we can look into how to generate our very own within our EOS smart contract. We’re going to create an action which takes an input string and outputs a checksum256 hash digest, then for the purpose of this example, print the result.</p><p>Let’s start by including the crypto.h library and the EOS print.h wrapper from the EOS framework.</p><pre>include &lt;eosiolib/crypto.h&gt;</pre><blockquote>Notice the <em>.h</em> extension on our crypto.h filename? This means we&#39;re using a <em>C</em> library and not <em>C++</em>, so our methods will be expecting <em>C</em> type inputs.</blockquote><p>Now we can define our action and allocate a reference for our checksum256 output like so.</p><pre>checksum256 sum{};</pre><p>The EOS framework provides a set of methods for various hashing algorithms. We’ll use the sha256 for this example because it’s fast, secure and typical used in most cases.</p><pre>sha256(const_cast&lt;char*&gt;(str.c_str()), str.size(), &amp;sum);</pre><p>Our sha256 method expects <em>C</em> type inputs, so we first need to convert our string to a char set, then pass the size of the string and a checksum256 reference which will be updated with the output digest. Now all that remains is printing the hashed output result.</p><pre>printhex(&amp;sum, sizeof(sum));</pre><p>We could also return the checksum256 here and use it as a private internal action.</p><h3>Taking it Further — <strong>Checksum to String</strong></h3><blockquote>Credit for this implementation goes to <a href="https://github.com/miguelmota">Miguel Mota</a> for developing a solution to convert checksum256 too a hexadecimal string.</blockquote><p>So what happens if we want to convert our digest back into a string? For this we will need a new method. To begin with, let’s define a template for our input argument and define the method itself. This template is defined outside of our method definition, typically at the top of our file. Templates simply allow us to define the variable type at the time we call the function, then the compiler will take care of substitution and making it all work.</p><pre>template &lt;typename CharT&gt;</pre><pre>string to_hex(const CharT* data, uint32_t length) {<br>  // Method Body<br>}</pre><p>Now we can start working on the body of our method. To start with we will create a string for our result, a char set to draw characters from later, and force our data to a uint8_t.</p><pre>string result;<br>const char* hex_chars = &quot;0123456789abcdef&quot;;<br>uint8_t* c = (uint8_t*)data;</pre><p>Finally we will iterate over each char in our input data, match the corresponding hexadecimal character, and append it to our resulting string.</p><pre>for (uint32_t i = 0; i &lt; length; ++i) {<br>  (result += hex_chars[(c[i] &gt;&gt; 4)]) += hex_chars[(c[i] &amp; 0x0f)];<br>}</pre><pre>return result;</pre><p>And that’s it! We now have a method to create a checksum256 from a char set, and a method to convert that checksum256 into a string. In the next article we will be looking at singletons and how we can utilize them to store application state and configuration.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fcb4DtiO6FZA%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dcb4DtiO6FZA&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fcb4DtiO6FZA%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6fa37477ef8e3060b841bcc256f4818f/href">https://medium.com/media/6fa37477ef8e3060b841bcc256f4818f/href</a></iframe><h4>What’s next?</h4><p>Make sure you click the <em>follow</em> button if you would like to be notified when I share more examples in this series. Part 2 will be covering how we can utilize Singletons in EOS to store contract state and configuration.</p><figure><a href="http://bit.ly/2G71Sp7"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fKX2mtg7p1lOs7JmosPLsA.png" /></a><figcaption><a href="http://bit.ly/2G71Sp7"><strong>Click to read today’s top story</strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a251a8d371b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/coinmonks/advanced-eos-series-part-1-cryptographic-hashes-a251a8d371b8">Advanced EOS Series — Part 1 —  Cryptographic Hashes</a> was originally published in <a href="https://medium.com/coinmonks">Coinmonks</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>