<?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 Lex Dreitser on Medium]]></title>
        <description><![CDATA[Stories by Lex Dreitser on Medium]]></description>
        <link>https://medium.com/@Dreitser?source=rss-394068dbf7a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*JUhMOJ6aDcc-WxY_u-YfoQ.png</url>
            <title>Stories by Lex Dreitser on Medium</title>
            <link>https://medium.com/@Dreitser?source=rss-394068dbf7a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 07 Apr 2026 14:57:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Dreitser/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[Complete Tutorial on how to build a dApp on Tezos using GRAT and GFT.]]></title>
            <link>https://medium.com/@Dreitser/complete-tutorial-on-how-to-build-a-dapp-on-tezos-using-grat-and-gft-9293ae644de?source=rss-394068dbf7a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/9293ae644de</guid>
            <dc:creator><![CDATA[Lex Dreitser]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 06:28:42 GMT</pubDate>
            <atom:updated>2023-06-01T06:28:42.741Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*0Mf-cX4YqcaWRrV6eKDDGQ.gif" /></figure><p>Building a decentralized application (dApp) on Tezos involves a series of steps, ranging from setting up the development environment to deploying and interacting with the dApp. In this tutorial, we’ll cover the entire process of building a dApp on Tezos.</p><p>Unlike everything else you see out there, this tutorial is approachable and fun, using GRAT — a No-Code Editor, and GFT — a Simple Unity SDK that we developed as open source here at Blockchain Alchemy!</p><p><strong>Note:</strong> This tutorial assumes you have a super basic understanding of blockchain technology and smart contracts and Unity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*d7uChScC2z9rl6yYNuh1ng.jpeg" /><figcaption>NO CODE — This Tutorial Uses GRAT a No-Code Editor for Tezos</figcaption></figure><p>Table of Contents:</p><ol><li>Using GRAT to Code, Convert &amp; Deploy the smart contract</li><li>Integrating with GRAT</li></ol><p>Create and deploy Smart Contract using GRAT</p><h3>Use GRAT</h3><p>GRAT is a no-code editor - so you simply follow the recipe for market contract. Drag and drop all components to build the smart contract, then click convert and deploy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/1*x8_PrWnwboWv9lrHW6xI8w.gif" /></figure><p>Use GFT</p><p>GFT already has functionality to interact with smart contracts. We’ll use this.</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using System.Runtime.InteropServices;<br><br><br>public class TransactionManager : MonoBehaviour<br>{<br>    public MarketData market_data;<br>    <br>    public OrderData order_data;<br>    public GameObject StartGameButton;<br>    public GameObject SendTezButton;<br><br>    // We Register the External Call Here<br>    [DllImport(&quot;__Internal&quot;)]<br>    private static extern void SendTransaction(float tez_amount);<br><br>    [SerializeField]<br>    UIManager UI_Manager;<br><br>    public void ClickInsertCoin(){<br>        SendTransaction(0.25f);<br>    }<br>    //Here we send the transaction.<br>   <br>    //Here we recieve the transaction results.<br>    public void TransactionResult(string result)<br>    {<br>                <br>    }<br><br>    public void TransactionComplete(){<br>        StartGameButton.SetActive(true);<br>        SendTezButton.SetActive(false);<br>    }<br>    public void TransactionFailed(){<br><br>    }<br><br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9293ae644de" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Making a Classic Coin-Op Arcade Game on Blockchain Using GFT by Blockchain Alchemy]]></title>
            <link>https://medium.com/@Dreitser/making-a-classic-coin-op-arcade-game-on-tezos-using-gft-by-blockchain-alchemy-3feb47be8a90?source=rss-394068dbf7a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3feb47be8a90</guid>
            <category><![CDATA[blockchain-development]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[tezos]]></category>
            <category><![CDATA[blockchain-gaming]]></category>
            <dc:creator><![CDATA[Lex Dreitser]]></dc:creator>
            <pubDate>Mon, 24 Apr 2023 07:18:01 GMT</pubDate>
            <atom:updated>2023-05-07T23:31:55.378Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGSlpfOuDG5waJLNEKRx6g.jpeg" /></figure><h3>Get Your Quarters Ready</h3><h4>Retro gamers have such fond memories of coin-operated cabinets (coin-op) where countless quarters were spent - to enjoy a childhood of accessible gaming.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*l7fDOFnTBfaTv1RDP3Q5HA.jpeg" /></figure><h4>This micro-transaction of 25 cents per play - created an economy, and incredible innovation in gaming - you could say it launched gaming as we know it. So, what’s more fitting a way to launch Tezos Gaming, than with an ode to the classics? Here we will re-create the coin-op mechanic using Unity and the GFT. All steps are documented and all code is open-source under MIT License - so you can follow along and begin your own Blockchain Gaming journey on Tezos with ease.</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*IX6dfLUaDjzjinMOHC3NRg.gif" /></figure><h3>Let’s Go</h3><p>This tutorial will cover the implementation of the GFT into a Classic Arcade Game. The final output product is a Unity WebGL game that can be deployed on a server such as Netlify.</p><p>With GFT, this game becomes a Decentralized Application (dApp) — that allows players to pay the developer a quarter for every play. This opens the floodgates for game development, just as the coin-op revolution did in 1990’s America.</p><h3>You’ll learn step-by-step:</h3><blockquote>1. Install GFT</blockquote><blockquote>2. Customize Unity</blockquote><blockquote>3. Customize React</blockquote><blockquote>4. Deploy to Web with Netlify</blockquote><h3>1. Install GFT</h3><h4>What You’ll Need</h4><ol><li>Unity LTS Version <a href="https://unity.com/releases/editor/qa/lts-releases?version=2020.3">Unity LTS version 2020.3</a> <a href="https://unity.com/releases/editor/qa/lts-releases?version=2020.3">[Download]</a></li><li><a href="https://github.com/Blockchain-Alchemy/GFT">The GFT</a> by Blockchain Alchemy <a href="https://github.com/Blockchain-Alchemy/GFT">[Download]</a></li></ol><h4>Install Unity</h4><p>Once you have <a href="https://unity.com/releases/editor/qa/lts-releases?version=2020.3">Unity LTS version 2020.3</a> installed, just open the latest release on the GFT Github [<a href="https://github.com/Blockchain-Alchemy/GFT/releases">Link</a>] and it will open in Unity.</p><h4>Install GFT-Web (React)</h4><p>With the <a href="https://github.com/Blockchain-Alchemy/GFT">GFT repo</a> cloned locally, type:</p><pre>npm install</pre><blockquote>Installing GFT-Web (React) is covered in more detail in the <a href="https://github.com/Blockchain-Alchemy/GFT">Github readme</a> and <a href="https://medium.com/@Dreitser/gtf-gaming-framework-for-tezos-b69d37cca891">GFT Medium article</a>.</blockquote><h3>2. Customize Unity</h3><h4>Add Transaction Manager</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*5CAqrWV96dczSzpIfy2FuQ.png" /></figure><p>Let’s add a New Empty GameObject called “GFT” and drop the Transaction Manager into it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/722/1*2fNHdF8smfOP_OWbxcfwRg.png" /></figure><h4>Delete (Almost) Everything</h4><p>We’re only using a small fraction of GFT’s capabilities, to keep things clean, we open the Transaction Manager and delete everything except:</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using System.Runtime.InteropServices;<br><br>public class TransactionManager : MonoBehaviour<br>{<br>    // We Register the External Call Here<br>    [DllImport(&quot;__Internal&quot;)]<br>    private static extern void SendTransaction(float tez_amount);<br>}</pre><h4>Add Insert Coin Function</h4><p>Since we’re not using the UI Manager, we reference the Send Tez and Start Game Buttons. Next , adding a function that sends 0.20 Tezos - <em>ClickInsertCoin()</em>. Then, if the transaction is successful , the <em>TransactionComplete()</em> function shows the Start Game Button.</p><pre>using System.Collections;<br>using System.Collections.Generic;<br>using UnityEngine;<br>using System.Runtime.InteropServices;<br><br>public class TransactionManager : MonoBehaviour<br>{<br>    public GameObject StartGameButton;<br>    public GameObject SendTezButton;<br><br>    // We Register the External Call Here<br>    [DllImport(&quot;__Internal&quot;)]<br>    private static extern void SendTransaction(float tez_amount);<br>    public void ClickInsertCoin(){<br>        SendTransaction(0.2f);<br>    }<br>    public void TransactionComplete(){<br>        StartGameButton.SetActive(true);<br>        SendTezButton.SetActive(false);<br>    } <br>}</pre><blockquote>Hint: This is already done for you in the TACMAN Repo Unity Release [<a href="https://github.com/Blockchain-Alchemy/TACMAN/releases/tag/publish">Link</a>], just download it for guidance.</blockquote><h3>3. Customize React</h3><h4>Change Contract</h4><p>The demo contract included with GFT does more complex market transactions. For TACMAN, we only need to send some Tezos, so we point to different simpler contract. In <em>src/pages/Home/Player/index.tsx</em></p><pre>// Event Listener for transaction<br>const onSendTransaction = useCallback(<br>  async (amount: number) =&gt; {<br>    try {<br>      // Start connecting wallet<br>      await connectWallet();<br><br>      // Fix sending amount number<br>      amount = Number(amount.toFixed(4));<br><br>      // Request transaction<br>      const op = await tezos.wallet<br>        .transfer({ to: &quot;tz1M2hCvF5AhhbQAkn3LcZ8DTNBggyAKTCvo&quot;, amount })<br>        .send();<br><br>      // Wait for transaction confirmation<br>      await op.confirmation();<br><br>      sendMessage(&quot;GFT&quot;, &quot;TransactionComplete&quot;);<br>      toast.success(&quot;Transaction Success&quot;);<br>      return;<br>    } catch (err) {<br>      console.error(err);<br>      toast.error(&quot;Something went wrong&quot;);<br>      sendMessage(&quot;GFT&quot;, &quot;TransactionFailed&quot;);<br>    }<br>  },<br>  [tezos, connectWallet, sendMessage]<br>);</pre><blockquote>Look out for future tutorials where we’ll teach you how to create Tezos smart contracts.</blockquote><h4>Update Event Listeners</h4><p>We renamed the Unity function so let’s update the Event Listeners. In <em>src/pages/Home/Player/index.tsx</em></p><pre>const eventListeners = useMemo((): UnityEventListener[] =&gt; {<br>  return [<br>    { eventName: &quot;SendTransaction&quot;, callback: onSendTransaction },<br>  ];<br>}, [onSendTransaction]);</pre><blockquote>Hint: This is already done for you in the TACMAN Repo [<a href="https://github.com/Blockchain-Alchemy/TACMAN">Link</a>], just download it for guidance.</blockquote><h3>4. Deploy to Web with Netlify</h3><h4>Run Build</h4><p>We need to compile the Unity so build to WebGL and enter the name public.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*G6NOj_-tTyp4g0C8zzh_QA.png" /></figure><p>Take the output and find the Build directory — move it to the public folder of the GFT-Web (React).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/458/1*ub4l-6YPcVL8tOxOpwzrLQ.png" /></figure><p>Then we run build. In console:</p><pre>npm run build</pre><h4>Drag and Drop the build directory to Netlify</h4><p>Now we simply take the build directory and drag-drop it onto Netlify manual deploy. <a href="https://www.netlify.com/">https://www.netlify.com/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zLxeVB5EOoB_YPK9cnjfjQ.png" /><figcaption>Drop your <strong>build</strong> folder right here.</figcaption></figure><h3>Done!</h3><p><strong>That’s It!</strong> Your game is now deployed as a fully functional dApp on the Tezos blockchain.</p><h4>Where Do We Go from Here?</h4><p><strong>Download Full <em>TACMAN</em> Source Code [</strong><a href="https://github.com/Blockchain-Alchemy/TACMAN"><strong>Link</strong></a><strong>]</strong></p><p><strong>Check out the GFT Full Source Code [</strong><a href="https://github.com/Blockchain-Alchemy/GFT"><strong>Link</strong></a><strong>]</strong></p><p><strong>Check out the GFT Medium Article [</strong><a href="https://medium.com/@Dreitser/gtf-gaming-framework-for-tezos-b69d37cca891"><strong>Link</strong></a><strong>]</strong></p><p><strong>Learn More about Tezos [</strong><a href="https://tezos.com/"><strong>Link</strong></a><strong>]</strong></p><p><strong>Follow Lex [</strong><a href="https://medium.com/@Dreitser"><strong>Link</strong></a><strong>] on Medium, more tutorials coming soon.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3feb47be8a90" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[GTF — Gaming Framework for Tezos]]></title>
            <link>https://medium.com/@Dreitser/gtf-gaming-framework-for-tezos-b69d37cca891?source=rss-394068dbf7a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b69d37cca891</guid>
            <category><![CDATA[tezos]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[gaming]]></category>
            <category><![CDATA[web3-game]]></category>
            <dc:creator><![CDATA[Lex Dreitser]]></dc:creator>
            <pubDate>Tue, 27 Dec 2022 10:06:33 GMT</pubDate>
            <atom:updated>2023-05-07T23:31:23.045Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>GFT</strong> — <strong>G</strong>aming Framework for Tezos</h3><h4>Tutorial and Setup Guide</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cohUuzsfOwH7nOjebS6xGw.jpeg" /></figure><h4>This series of tutorials will give a deep-dive into the workings of <a href="https://github.com/Blockchain-Alchemy/GFT">GF</a>T — the open-source Gaming Framework for <a href="https://tezos.com/">Tezos</a>. You will have a deeper understanding of how the components work. After these tutorials you’ll be able to extend and customize the GFT for any game and deploy it with basic <a href="https://tezos.com/">Tezos</a> blockchain functionality.</h4><figure><img alt="MIT License" src="https://cdn-images-1.medium.com/max/117/1*4Ru4upsd7K9vflDUVcfBfw.jpeg" /></figure><p><strong>GFT is free under MIT license. Everything you see in this tutorial is included in the </strong><a href="https://github.com/Blockchain-Alchemy/GFT"><strong>GitHub Repo</strong></a><strong>!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TVcu5SRvwUkaIhnYlODIgw.gif" /></figure><h3>Setup / Pre-Requisites</h3><h4>Setup</h4><p>There are two easy to install components:</p><ol><li><strong>Web Component </strong>— This is node.js, react, typescript web base of the framework, it does much of the on-chain transactions, and also serves the Unity WebGL component. The setup/download instructions for the web component can be found in the github readme <a href="https://github.com/Blockchain-Alchemy/GFT">here</a>.</li><li><strong>Unity Component </strong>— This is the game component. We have included a sample menu to demonstrate the basics. The unity component is available through a Unity Asset Package as a release <a href="https://github.com/Blockchain-Alchemy/GFT/releases">here</a>.</li></ol><h4>Pre-Requisites</h4><p>Knowledge of JS, Unity, node and react are recommended. These tutorials take you step-by-step through the completed working demo, having the pre-requisite knowledge will help understand the framework, but it’s not required to setup or use GFT.</p><h4>A little background — what are NFTs?</h4><blockquote>“NFTs are non-fungible tokens stored on a blockchain, a form of digital ledger that stores a record of each transaction that takes place,” says Raj Kallem, Head of Development at the 1687 Club, an NFT-based membership club.[1]</blockquote><h3>Tutorial 1: Token-Gating</h3><h4>What is Token Gating</h4><blockquote>Token gating is “a way of adding more value to an NFT by allowing the holder exclusive access to a community, content, or even physical products in addition to the digital token,” Kallem says.[1]</blockquote><h4>How does token gating work in GFT?</h4><p>In GFT, we check the player’s wallet for ownership of an NFT. Confirmed ownership can trigger game mechanics such as gated entry, unlockables and inventory items. In the demo we’ll show use the token-gating to unlock the <strong>Market</strong> and <strong>Start Game</strong> functionality.</p><h4>Let’s get started!</h4><p><em>Before you begin, please make sure you follow the steps to </em><a href="https://github.com/Blockchain-Alchemy/GFT/blob/main/README.md#setup"><em>Set up the GFT</em></a></p><p>We’ll go over the basic mechanic of requiring a token (such as NFT) to start the game.</p><p>There are three parts to this process.</p><ol><li><strong>Connect Wallet</strong></li><li><strong>Send Wallet Status to Unity</strong></li><li><strong>Send Token Ownership to Unity</strong></li></ol><h4>Connect Wallet</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OkMtKphHuNhlH08C9gf-og.png" /></figure><p>In order to check if the user has a token, we need the user’s wallet address. We can do this the awkward/hard way and have them type the 30+ character address in themselves, or the smooth/easy way and have them sign with their wallet.</p><p>We’ll implement <a href="https://tezostaquito.io/">taquito</a> and the <a href="https://www.walletbeacon.io/">beacon framework </a>to accomplish this easily with react.<br><em>Note: The GFT repo has this created for you.</em></p><pre><br>import { useWallet } from &#39;contexts/WalletProvider&#39;;<br><br>const { address, connectWallet, disconnectWallet } = useWallet();<br><br>const handleConnect = () =&gt; {<br>  if (!address) {<br>    connectWallet();<br>  } else {<br>    disconnectWallet();<br>  }<br>};</pre><h4>Send Wallet Status to Unity</h4><p><strong>Render Unity WebGL and Send JS Message [ In JS ]<br></strong>We’ll render the unity component in react using <a href="https://github.com/jeffreylanters/react-unity-webgl">Jeffrey Lanterns React-Unity-WebGL framework</a>. We’ll use Unity’s <a href="https://docs.unity3d.com/Manual/webgl-interactingwithbrowserscripting.html">Interaction with Browser Scripting</a> to send the wallet to the Unity WebGL Component. <br><em>Note: The GFT repo has this created for you.</em></p><pre>// Send WalletConnected to Unity<br>import { useWallet } from &#39;contexts/WalletProvider&#39;;<br><br>const { address } = useWallet();<br>const { isLoaded, sendMessage } = unityContext;<br><br>sendMessage(&#39;GFT&#39;, &#39;WalletConnected&#39;, address);<br></pre><p><strong>Receive Wallet Status [ In Unity ]<br></strong>In the Unity editor we’ll Create an empty GameObject called GFT and create a script inside of it called AccessManager.cs. We’ll create a function that will be called by the browser [js] and will let Unity know that a wallet was connected and receives wallet address. <br><em>Note: The included demo scene has this created for you.</em></p><pre> // AccessManager.cs<br> //This function is called externally when the user connects wallet.<br>    public void WalletConnected(string walletAddressConnected)<br>    {<br>        if (walletAddressConnected == &quot;error&quot;)<br>        {<br>            //Return Error<br>        } else {<br>            walletState = true;<br>            walletAddress = walletAddressConnected;<br>        }<br>        // Update UI<br>        if (UI_Manager == null){<br>            return;   <br>        } else {<br>            UI_Manager.UpdateUI();<br>        }<br>    }</pre><p>Now the user has completed a web3 sign-in using their Tezos wallet, that triggers the next part, where we query the user’s wallet address for a token.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oUD22Gc1bs8Qgl7nXveJlg.png" /></figure><h4>Send Token Ownership</h4><p>Here we repeat the basic steps and give the Unity WebGL Component token (NFT) ownership info.</p><p><strong>Query RPC node and Send JS Message [ In JS ]<br></strong>The fastest way to check the user’s wallet inventory for the token by querying the ownership ledger for the user’s wallet address.<br><em>Note: The GFT repo has this created for you.</em></p><pre>// src/hooks/useToken.ts<br>import { useCallback } from &#39;react&#39;;<br>import { useWallet } from &#39;contexts/WalletProvider&#39;;<br><br>const useToken = () =&gt; {<br>  const { tezos } = useWallet();<br><br>  const getGateToken = useCallback(<br>    async (address: string) =&gt; {<br>      try {<br>        const contract = await tezos.contract.at(<br>          &#39;KT1SGdop74rGobKAETcBPnz9yQkH38hZnpBh&#39;<br>        );<br>        const storage: any = await contract.storage();<br>        const values = await storage.ledger.get({<br>          0: address,<br>          1: 1,<br>        });<br>        return values ? values.toNumber() : 0;<br>      } catch (error) {<br>        console.error(error);<br>      }<br>    },<br>    [tezos]<br>  );<br><br>  return { getGateToken };<br>};<br><br>export default useToken;</pre><p><strong>Receive Ownership Status [ In Unity ]<br></strong>In the Unity editor we’ll add another function to the AccessManager.cs script<br><em>Note: The included demo scene has this created for you.</em></p><pre> // AccessManager.cs<br> // This function is called externally when the user has required token.<br>    public void TokenFound(string tokenNameConnected)<br>    {<br><br>        #if UNITY_WEBGL == true &amp;&amp; UNITY_EDITOR == false<br>            // TokenFound( );<br>        #endif<br>         if (tokenNameConnected == &quot;error&quot;)<br>        {<br>            //Return Error<br>        } else {<br>            tokenState = true;<br>            tokenName = tokenNameConnected;<br>        }<br><br>         // Update UI<br>        if (UI_Manager == null){<br>            return;   <br>        } else {<br>            UI_Manager.UpdateUI();<br>        }<br><br>    }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6m7rKrhIyI5xtXGmUzyVqQ.png" /></figure><h4>Tutorial 1 — Conclusion</h4><p>Here we have the building blocks of an NFT game on Tezos. We can, with this basic code, reliably receive the user’s wallet as a form of user management sign-in and query ownership of assets. This code is basic, and can be extended for greater security and functionality. One example is our <a href="https://github.com/Blockchain-Alchemy/Metaverse-Anti-Cheat">Metaverse Anti-Cheat Framework</a> that prevents JS injection.</p><h3>Tutorial 2 — Market Transaction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k7PkDas1AikQsBHsbU5byg.png" /></figure><p>Here we’ll go over the basic mechanic of getting market prices of a token, and transacting with the market contract. There are three basic parts of this process:</p><ol><li><strong>Send Market Prices to Unity</strong></li><li><strong>Send Market Transaction from Unity</strong></li><li><strong>Send Confirmation to Unity</strong></li></ol><h4>Send Market Prices to Unity</h4><p>Here we query the market ledger, that holds the market data using taquito and react. We sort and parse this data, forming it into a json file. We then pass it to the Unity component.</p><p><strong>Get Market Data and Send to Unity [ In JS ]<br></strong>We query the RPC node for all ledger data which comes unordered, we parse this data by item and price, sending the resulting data to Unity to be displayed.<br><em>Note: The GFT repo has this created for you.</em></p><pre>// src/hooks/useMarket.ts<br>import { useCallback } from &#39;react&#39;;<br>import { useWallet } from &#39;contexts/WalletProvider&#39;;<br>import { useNetwork } from &#39;contexts/NetworkProvider&#39;;<br><br>export type MarketItem = {<br>  owner: string;<br>  token_id: number;<br>  price: number;<br>  amount: number;<br>};<br><br>const useMarket = () =&gt; {<br>  const { config } = useNetwork();<br>  const { tezos } = useWallet();<br><br>  const getMarketItems = useCallback(<br>    async (address: string): Promise&lt;MarketItem[] | undefined&gt; =&gt; {<br>      try {<br>        const contract = await tezos.contract.at(config.Market);<br>        const storage: any = await contract.storage();<br>        return storage.items<br>          .filter((i) =&gt; i.owner === address)<br>          .map((i) =&gt; {<br>            return {<br>              owner: i.owner,<br>              token_id: i.token_id.toNumber(),<br>              price: i.price.toNumber(),<br>              amount: i.amount.toNumber(),<br>            } as MarketItem;<br>          });<br>      } catch (error) {<br>        console.error(error);<br>      }<br>    },<br>    [tezos, config]<br>  );</pre><p><strong>Receive Market Data [ In Unity ]<br></strong>Unity will receive the data as a json file, parse it into items and prices for the player to make a purchase. <br><em>Note: The included demo scene has this created for you.</em></p><pre>//TransactionManager.cs<br>//This function is called externally when the market prices are sent to Unity.<br>    public void LoadPrices(string jsonString){<br>        // We parse the json into the market_data object<br>        market_data = MarketData.CreateFromJSON(jsonString);<br>        // We create the architecture for the order_data manually <br>        string orderData = &quot;{\&quot;items\&quot;:[{\&quot;name\&quot;:\&quot;Ammo\&quot;,\&quot;price\&quot;:0.01,\&quot;amount\&quot;:0},{\&quot;name\&quot;:\&quot;Water\&quot;,\&quot;price\&quot;:0.02,\&quot;amount\&quot;:0},{\&quot;name\&quot;:\&quot;Fuel\&quot;,\&quot;price\&quot;:0.015,\&quot;amount\&quot;:0},{\&quot;name\&quot;:\&quot;Intel\&quot;,\&quot;price\&quot;:0.1,\&quot;amount\&quot;:0}]}&quot;; <br>        if (order_data == null) order_data = OrderData.CreateFromJSON(orderData);    <br>        // Update UI<br>        if (UI_Manager == null){<br>            return;   <br>        } else {<br>            UI_Manager.UpdateUI();<br>        }<br>    }</pre><h4>Send Market Transaction from Unity</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rkCRsNqx5Yoh-NzQJaEKfA.png" /></figure><p>This step adds some complexity as we for the first time send data out of Unity. For this, we’ll need an extra file in the /Plugins/directory. This allows Unity to send data out. We&#39;ll send the market order here.</p><p><strong>Add the .jslib file [ In Unity ]</strong><br>This GFT.jslib file needs to be placed in the/Plugins/WebGL/ directory. <br><em>Note: The included unity package has this created and placed for you.</em></p><pre>//Plugins/WebGL/GFT.jslib<br>mergeInto(LibraryManager.library, {<br>  SendTransaction: function (jsonString) {<br>    try {<br>      window.dispatchReactUnityEvent(&quot;SendTransaction&quot;, jsonString);<br>    } catch (e) {<br>      console.warn(&quot;Failed to dispatch event&quot;);<br>    }<br>  },<br>});</pre><p><strong>Send Market Transaction [ In Unity ]<br></strong>We take the user’s selection and send it as a json file.<br><em>Note: The included demo scene has this created for you.</em></p><pre>//TransactionManager.cs<br>//Here we send the transaction.<br>    public void DoSendTransaction()<br>    {<br>        string jsonString = JsonUtility.ToJson(order_data);<br>        #if UNITY_WEBGL == true &amp;&amp; UNITY_EDITOR == false<br>            SendTransaction(jsonString);<br>        #endif<br>    }</pre><p><strong>Receive Market Order and Initiate Wallet Transaction [ In JS ]</strong><br>Now the JS takes the order and composes a market transaction to be signed by the user’s wallet via beacon.<br><em>Note: The GFT repo has this created for you.</em></p><pre>// src/hooks/useMarket.ts<br> const buyMarketItems = useCallback(<br>    async (items: MarketItem[]) =&gt; {<br>      try {<br>        const contract = await tezos.wallet.at(config.Market);<br>        const op = await contract.methods.buy_items(items).send();<br>        const tx = await op.confirmation(1);<br>        return tx;<br>      } catch (error) {<br>        console.error(error);<br>      }<br>    },<br>    [tezos, config]<br>  );</pre><h3>Confirm Market Transaction</h3><p>Now we need to confirm that the transaction went through and let Unity know to update player’s inventory with new purchases.</p><p><strong>Send Transaction Confirmation [ In JS ]<br></strong>The react component listens for a transaction confirmation or failure and send the information up to the Unity component.<br><em>Note: The GFT repo has this created for you.</em></p><pre>// src/hooks/useMarket.ts<br> const buyMarketItems = useCallback(<br>    async (items: MarketItem[]) =&gt; {<br>      try {<br>        const contract = await tezos.wallet.at(config.Market);<br>        const op = await contract.methods.buy_items(items).send();<br>        const tx = await op.confirmation(1);<br>// Returns response<br>        return tx;<br>      } catch (error) {<br>        console.error(error);<br>      }<br>    },<br>    [tezos, config]<br>  );</pre><p><strong>Receive Confirmation [ In Unity ]</strong><br>Now Unity receives the confirmation and it’s Game-time!<br><em>Note: The included demo scene has this created for you.</em></p><pre>    //TransactionManager.cs<br>    //Here we recieve the transaction results.<br>    public void TransactionResult(string result)<br>    {<br>         if (UI_Manager == null){<br>            return;   <br>        } else {<br>            UI_Manager.DisplayTransactionResults(result);<br>        }<br>    }</pre><h3>Conclusion</h3><p>This tutorial shows how to integrate Tezos-based elements into a game mechanic as a simple, yet functional, reference on how larger scale games would be build on Tezos.</p><p>Follow our progress as we build more open-source games on Tezos. We incorporate GFT into our games so it has real-world use, that lets us update it, and keep it optimized — for the community. We’ll be documenting our next game WWXTZ, with articles and tutorials — giving you insight into the inner workings of these components.</p><h4>Check out GFT in Action:</h4><p>We created a game using the GFT that you can play, try it here:<br><a href="https://tac-man.netlify.app/">https://tac-man.netlify.app/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RGSlpfOuDG5waJLNEKRx6g.jpeg" /><figcaption>Play TACMAN - made using GFT</figcaption></figure><p>Read the Medium article on how GFT was implemented in TACMAN: <a href="https://medium.com/@Dreitser/making-a-classic-coin-op-arcade-game-on-tezos-using-gft-by-blockchain-alchemy-3feb47be8a90">Making a Classic Coin-Op Arcade Game on Tezos Using GFT by Blockchain Alchemy</a></p><p>Upcoming Articles:</p><ul><li>dApp for Brains(intel) Market : WWXTZ</li><li>Dynamic NFTs: Tezoscale</li></ul><h4>References:</h4><ol><li><em>Token Gating and NFTs for Retailers: 2022 Guide</em>, Ana Cvetkovic — <a href="https://www.shopify.com/retail/token-gating">https://www.shopify.com/retail/token-gating</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b69d37cca891" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>