{"id":1522,"date":"2020-03-01T07:47:05","date_gmt":"2020-03-01T07:47:05","guid":{"rendered":"http:\/\/org.saito.tech\/?page_id=1522"},"modified":"2021-05-19T03:31:11","modified_gmt":"2021-05-19T03:31:11","slug":"tutorial-3-polkadot-and-other-cryptocurrencies","status":"publish","type":"page","link":"https:\/\/org.saito.tech\/tutorial-3-polkadot-and-other-cryptocurrencies\/","title":{"rendered":"Tutorial 3 &#8211; Polkadot and Cryptocurrencies"},"content":{"rendered":"\n<p>In this tutorial we create a wallet plugin that can send and receive other cryptocurrencies like Polkadot. We explain how to use the \/lib directory to handle more complicated user interfaces. And we learn a bit about the standard Saito UI library. As before, we recommend downloading <a href=\"http:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/tutorial02.zip\">the finished zipfile<\/a> or walking through our <a href=\"https:\/\/github.com\/SaitoTech\/saito-lite\/tree\/master\/mods\/tutorial03\">annotated online code<\/a>. This is what we are building.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" width=\"1024\" height=\"529\" src=\"https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-1024x529.png\" alt=\"\" class=\"wp-image-2616\" srcset=\"https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-1024x529.png 1024w, https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-300x155.png 300w, https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-768x397.png 768w, https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-1536x793.png 1536w, https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-2048x1058.png 2048w, https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-1162x600.png 1162w, https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-774x400.png 774w, https:\/\/org.saito.tech\/wp-content\/uploads\/2021\/05\/Screen-Shot-2564-05-19-at-09.52.40-387x200.png 387w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption>The finished product.<\/figcaption><\/figure>\n\n\n\n<h4>Steps<\/h4>\n\n\n\n<p>Create your application directory as usual. But this time create a subdirectory called \/lib inside your application directory. We put a another subdirectory inside it called &#8220;email-appspace&#8221;. This is where we will put the code that displays and manages the user-facing parts of our application. You can see this directory contains: a javascript class and a template file that contains the HTML we will insert into the page. We require the javascript file within our application javascript and can now simplify our <em>respondTo<\/em> function as follows:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&nbsp; respondTo(type) {\n&nbsp; &nbsp; if (type == 'email-appspace') {\n&nbsp; &nbsp; &nbsp; let obj = {};\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.render = function (app, mod) {\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tutorial03EmailAppspace.render(app, mod);\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; obj.attachEvents = function (app, mod) {\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Tutorial03EmailAppspace.attachEvents(app, mod);\n&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }\n&nbsp; &nbsp; &nbsp; return obj;\n&nbsp; &nbsp; }\n&nbsp; &nbsp; return null;\n&nbsp; }<\/pre>\n\n\n\n<p>Look inside <a href=\"https:\/\/github.com\/SaitoTech\/saito-lite\/blob\/master\/mods\/tutorial03\/lib\/email-appspace\/tutorial03-appspace.js\">\/lib\/email-appspace\/tutorial03-appspace.js <\/a>and everything should be self-explanatory. <em>render(app, mod) <\/em>writes our HTML template file into the &#8220;email-appspace&#8221; space provided. <em>attachEvents(app, mod) <\/em>then adds interactivity to the elements provided. With more complicated modules this type of code organization keeps our module clean. Our application file handles interactions with the blockchain and peer-to-peer network while UI-facing elements are handled as UI library components. <\/p>\n\n\n\n<blockquote class=\"wp-block-quote\"><p>PRO-TIP: if you look closely at <em>tutorial03-appspace.js <\/em>you&#8217;ll notice that it invokes the class <em>GameCryptoTransferManager. <\/em>This is one of many standard UI elements available to all Saito applications. You can find them within the <a href=\"http:\/\/github.com\/SaitoTech\/saito-lite\/blob\/master\/lib\/saito\/ui\">\/lib\/saito\/ui directory<\/a>. Other useful components include modal popups, overlays, the header elements, as well as game-specific components used by the Saito Game Engine. In this case, adding GameCryptoTransferManager gives us access to  the non-interactive UI popups that indicate interactions with other blockchains. Feel welcome to customize these UI elements and provide them as part of your module.<\/p><\/blockquote>\n\n\n\n<p>Now look at the way that our module is interacting with our external blockchain. These functions are all inside the <a href=\"http:\/\/github.com\/SaitoTech\/saito-lite\/blob\/master\/lib\/saito\/wallet.js\">\/lib\/saito\/wallet.js<\/a> class &#8211; scroll down for the section identified by the &#8220;PREFERRED CRYPTOS&#8221; header:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">app.wallet.checkBalance(address, ticker);\n\napp.wallet.sendPayment(senders=[], receivers=[], amounts=[], timestamp, mycallback, ticker);\n\nasync app.wallet.receivePayment(senders=[], receivers=[], amounts=[], timestamp, mycallback, ticker, tries = 36, pollWaitTime = 5000);<\/pre>\n\n\n\n<p>Developers can find full document on available wallet-level functions. The important thing to note is that calling these wallet-level functions is blockchain agnostic and identifies chains by their standard crypto ticker-symbols. Many applications like the games in the Saito Arcade are coded so that users can decide for themselves which modules they wish to install and how those cryptocurrency modules work. <\/p>\n\n\n\n<h4>Conclusion<\/h4>\n\n\n\n<p>In this tutorial, we highlight the generic functions\/interface provided in <a href=\"http:\/\/github.com\/SaitoTech\/saito-lite\/blob\/master\/lib\/saito\/wallet.js\">\/lib\/saito\/wallet.js<\/a> in order to emphasize the flexibility that Saito provides developers. If you have a specific module that you wish to interact with on a lower-level however, you can always fetch the module and deal with it directly. For those interested in Cryptocurrency Module construction and looking to avoid the wallet-interface completely, the parent class for all cryptocurrency modules is available at <a href=\"http:\/\/github.com\/SaitoTech\/saito-lite\/blob\/master\/lib\/templates\/abstractcryptomodule.js\">\/lib\/templates\/abstractcryptomodule.js<\/a>.<\/p>\n\n\n\n<p>We are continuing to work to improve Saito&#8217;s ability to support cryptocurrency applications. If you have any feedback or suggestions please feel very welcome to reach out to <em>info@saito.tech<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial we create a wallet plugin that can send and receive other cryptocurrencies like Polkadot. We explain how to use the \/lib directory to handle more complicated user interfaces. And we learn a bit about the standard Saito&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"inline_featured_image":false},"_links":{"self":[{"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/pages\/1522"}],"collection":[{"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/comments?post=1522"}],"version-history":[{"count":13,"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/pages\/1522\/revisions"}],"predecessor-version":[{"id":2625,"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/pages\/1522\/revisions\/2625"}],"wp:attachment":[{"href":"https:\/\/org.saito.tech\/wp-json\/wp\/v2\/media?parent=1522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}