<?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 Fred Liebenberg on Medium]]></title>
        <description><![CDATA[Stories by Fred Liebenberg on Medium]]></description>
        <link>https://medium.com/@fliebenberg?source=rss-f62fc3c37a01------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*fz4F2RyEcBBuJWfy.</url>
            <title>Stories by Fred Liebenberg on Medium</title>
            <link>https://medium.com/@fliebenberg?source=rss-f62fc3c37a01------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 12:33:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@fliebenberg/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[Can a community build an app?]]></title>
            <link>https://medium.com/alphadex-xrd/can-a-community-build-an-app-680cfbb06f1b?source=rss-f62fc3c37a01------2</link>
            <guid isPermaLink="false">https://medium.com/p/680cfbb06f1b</guid>
            <category><![CDATA[decentralized-finance]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[community]]></category>
            <category><![CDATA[decentralized-exchange]]></category>
            <category><![CDATA[radix-dlt]]></category>
            <dc:creator><![CDATA[Fred Liebenberg]]></dc:creator>
            <pubDate>Tue, 06 Jun 2023 08:52:02 GMT</pubDate>
            <atom:updated>2023-07-19T08:24:04.768Z</atom:updated>
            <content:encoded><![CDATA[<p>Is it possible to extend the concept of decentralization that Web3 aspires to and get a group of people with different backgrounds and skill sets to work together voluntarily to build a Web3 application that they can all eventually share the income from if successful?</p><h3>Web3 is not just a technology, it is an ideal</h3><p>In my mind, one of the ideals of Web3 is to replace centralized control and organization with a more community driven approach. One that allows everyone the freedom and opportunity to belong to and contribute to the causes they believe in or want to help succeed. But Web3 is not only about the decentralization of control, it is also about the decentralization of opportunity and benefit. Ideally people who contribute to the success of a project should also be the ones who benefit from it.</p><h3>What am I doing to help make this vision of Web3 a reality</h3><p>I am the founder of a project on the <a href="http://radixdlt.com/">Radix</a> network called <a href="http://alphadex.net/">AlphaDEX</a>, which is a decentralized order book exchange platform. It is called a platform because it is built for others to build on and benefit from by</p><ul><li>sharing most of the exchange fees back to the users of the exchange</li><li>providing all the functionality and tools of a fully decentralized order book exchange except for a dedicated front-end app</li></ul><p>I specifically did not want to build a front-end app because I wanted other developers to build different front-ends that cater for different types of users and in return these developers can earn a portion of the fees their users generate on AlphaDEX.</p><h3>Time for the next step</h3><p>AlphaDEX is only one small step towards achieving the Web3 ideals I mentioned above. It is now time to take the next step: to build a fully fledged exchange app for Radix using the tools and capabilities AlphaDEX makes available and using contributors from the Radix community who will all earn a share in the eventual success of the app.</p><h3>The App</h3><p>The plan is to build a full orderbook exchange app that looks and functions similar to the centralized exchange apps that users are used to using (e.g. Binance, Kucoin, Bitfinex etc). It will provide the ability to place limit and market orders, see live price graphs and orderbook details, see trade details and user orders and provide historic reports of user trades and transactions.</p><p>Although I think it will initially be a web based app, nothing stops us from also building mobile native versions if we get the right people to contribute. Of course, these are just some of basic functionality that I think the app should have, but who knows what other ideas might come from the community of contributors.</p><h3>Who can contribute?</h3><p>Anyone and everyone. This will be a community project. So anyone who has a skill that can help the project be a success are welcome to contribute. Here are just some of the skills I think we might need:</p><ul><li>community managers</li><li>project managers</li><li>marketing enthusiasts</li><li>social media influencers</li><li>UI/UX designers</li><li>graphic designers</li><li>front-end developers</li><li>full-stack developers</li><li>developer leads</li><li>dev ops</li><li>trading experts</li></ul><p>And this is just what I came up with immediately. I am sure there are many more that can contribute using their unique set of skills.</p><h3>But why would people contribute?</h3><p>First, because it will be extremely cool (and useful) to have a fully fledged, decentralized exchange app on Radix that is built and managed by the community.</p><p>Second, because by contributing to the creation and success of the app, people can earn a share of its future earnings.</p><h3>How will earnings sharing work?</h3><p>The project will issue tokens that will give holders a proportionate share in the earnings of the project. On a regular basis (every week, 2 weeks?) some tokens will be distributed to people who have contributed to the project over that period. Contributors will be able to accumulate tokens over time by continuing to contribute to the project.</p><h3>Who will decide the token distribution</h3><p>Everyone will be able to nominate people to receive some of the tokens for a period. The nomination process will be done through a survey at the end of every period (initially it will just be a simple Google form). The nomination results will be publicly available.</p><p>For the first few periods I will maintain a veto over nominations to avoid non-valid votes (e.g. people who never contributed voting for their friends etc.). Eventually this function will be performed by the existing token holders or their representatives.</p><p>I am hoping it will mean that people who participate actively in the project will be rewarded by the other participants. I am aware that it is a very subjective way of allocating tokens and am interested to see if this can work and result in a fair distribution to contributors. It will however mean that people need to make sure others are aware of what they contribute if they want to be nominated.</p><p>The nomination process will give each person 100 nomination points that they can allocate across up to 10 people they think contributed for the period. You can not nominate yourself and you can not allocate more than 40 points to a single person (so you need to nominate at least 3 people).</p><p>The final allocation for the period will be determined by the proportion of total allocation points allocated to each of the nominated people.</p><h3>The tokenomics</h3><p>As mentioned, the project will have its own token that will represent a share of the earning of the project. For each period 1000 tokens will be available for distribution and will be distributed according to the nomination process.</p><p>The final amount of tokens issued will be determined by how long the project takes to finish. The longer the project takes, the more tokens will be issued. It will be up to existing token holders to decide when they want to stop issuing tokens, but this can not happen before at least two months have expired since the first token issue.</p><p>There will be no token airdrop outside of the allocation to contributors, but anyone who receives tokens are free to sell some or all of their tokens as soon as they have received them. This will provide a way to obtain tokens for people who like to speculate on tokens but don’t necessarily want to contribute to the project. It will also help to determine an early price for the tokens and even provide a bit of income to the contributors.</p><p>The app will earn an income from every trade on AlphaDEX that originated from its users through the already built-in platform fee (0.1% of every trade) on AlphaDEX. This income will be distributed to the token holders on a regular (monthly?) basis.</p><p>This is just a broad suggestion of how the tokenomics could work. It will eventually be up to the community of contributors/token holders to decide the exact details of how this should work.</p><h3>What do you think?</h3><p>Am I a crazy idealist or is this the future of app development? Whatever the outcome of this project I am very interested to see the results. If you have any further questions and this sounds like something you would like to contribute to or just be part of as an interested observer, come join us on our project telegram channel <a href="https://t.me/dexter_discussion">Dexter Discussion</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=680cfbb06f1b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/alphadex-xrd/can-a-community-build-an-app-680cfbb06f1b">Can a community build an app?</a> was originally published in <a href="https://medium.com/alphadex-xrd">AlphaDEX XRD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting AlphaDEX to your Svelte app.]]></title>
            <link>https://medium.com/alphadex-xrd/connecting-alphadex-to-your-svelte-app-9754200064c1?source=rss-f62fc3c37a01------2</link>
            <guid isPermaLink="false">https://medium.com/p/9754200064c1</guid>
            <category><![CDATA[decentralized-exchange]]></category>
            <category><![CDATA[decentralized-finance]]></category>
            <category><![CDATA[alphadex]]></category>
            <category><![CDATA[svelte]]></category>
            <category><![CDATA[sveltekit]]></category>
            <dc:creator><![CDATA[Fred Liebenberg]]></dc:creator>
            <pubDate>Thu, 01 Jun 2023 11:06:48 GMT</pubDate>
            <atom:updated>2023-06-01T11:06:48.655Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*G3f544CUXbIOkAM3ORtIUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/199/0*TblUckdwHO_aa1bP.png" /></figure><p>This is a quick tutorial on how to connect your Svelte app to the <a href="https://alphadex.net/">AlphaDEX</a> decentralized exchange platform on <a href="https://radixdlt.com/">Radix DLT</a>. You can find more AlphaDEX related tutorials like this <a href="https://medium.com/p/2fb17ea04dbb/">here</a>.</p><p>This tutorial assumes you have a basic knowledge of how Svelte apps work. If you don’t, then you can learn more about Svelte at <a href="http://svelte.dev/">svelte.dev</a>.</p><p>You will need Node.js installed on your machine to follow this tutorial. If you do not have it installed yet, you can follow the instructions to do so on their website <a href="https://nodejs.org/">nodejs.org</a>.</p><h4>Note about using Svelte-Kit vs standard Svelte</h4><p>This tutorial was specifically done with Svelte-Kit (<a href="http://kit.svelte.dev/">kit.svelte.dev</a>) rather than standard Svelte. I chose to use Svelte-Kit as it seemed to have a few more nuances that needed to be addressed to use the AlphaDEX SDK. I will specifically make mention of these during the tutorial. The tutorial should be very easy to follow in standard Svelte with the only difference being the main working file changing from +page.svelte in the src/routes folder to App.svelte in the src folder.</p><h3>Set up a new Svelte app</h3><p>If you have an existing Svelte app already, you can jump straight to the “Install AlphaDEX SDK” step.</p><h4>Create a new app</h4><p>The fastest way to create a new Svelte app is to use the Node Package Manager (NPM). To use it, move to the folder in which you want to create your new app and run the following command:</p><pre>npm create svelte@latest hello-alphadex-svelte</pre><p>You will be prompted with a few questions about the type of svelte app that you want to create. For the purposes of this tutorial I selected:</p><ul><li>Library project</li><li>Add type checking with TypeScript</li><li>Add ESLint for code linting, Add Prettier for code formatting</li></ul><p>Although you are free to select other options, it will be easiest to follow along with this tutorial if you make the same selections for your project.</p><p>Once you have made your selections a new Svelte app will be created in a new folder called hello-alphadex-svelte which contains all the files needed for a new Svelte app.</p><h4>Run your new app</h4><p>Move to the newly created app directory with this command:</p><pre>cd hello-alphadex-svelte</pre><p>Install all the necessary dependencies for the app using NPM again with the following command:</p><pre>npm install</pre><p>This will take a couple of seconds to run and download the necessary files for your app.</p><p>Once the installation is done, you can now run your new app with this command:</p><pre>npm run dev</pre><p>You now have a development server running for your new Svelte app. To see the output of your app, you can enter the address shown in the message in your browser address bar. It should be something like http://localhost:5173/. Once you have entered the address in your browser, you should see a message welcoming you to your new project.</p><h4>Clean up the app</h4><p>For this tutorial, we want a clean slate to work with, so open the +page.svelte file in the src/routes folder and change it to look like this:</p><pre>&lt;h1&gt;Hello AlphaDEX&lt;/h1&gt;</pre><p>Save the file with your changes and the browser window will automatically be updated to only show “Hello AlphaDEX” on a blank screen. Not the prettiest screen, but we now have a blank slate to show you how to connect your app to AlphaDEX.</p><h3>Install AlphaDEX SDK</h3><p>Before we can connect to AlphaDEX, we need to install the SDK in our project. To do this, make sure you are in your project directory and run the command:</p><pre>npm install alphadex-sdk-js</pre><p>This will install the AlphaDEX SDK files in your project’s node_modulesdirectory, ready to be used in your project.</p><h3>Import the AlphaDEX SDK</h3><p>OK, we are ready to connect our app with AlphaDEX (finally!).</p><p>In order to use the functionality in the SDK, you need to import the required functionality into your app. You can do this in two ways:</p><h4>Method 1 (Import functionality as needed)</h4><p><em>This method does not work with Svelte-Kit</em></p><p>With this method you only import the functions and variables that you will need for a specific task e.g. if we only want to import the init function and clientState variable, we will do it like this:</p><pre>import {init, clientState} from &quot;alphadex-sdk-js&quot;</pre><p>Now you can access the imported functions/variables directly using their name. E.g. I can call the init function and access the clientState variable like this in my code:</p><pre>init();<br>const myOwnVariable = clientState;</pre><h4>Method 2 (Import all functionality at once)</h4><p>With this method you import all the SDK functions, variables and types at once into a reference variable like this: (I called the reference variable adex below, but you can call it anything you like.)</p><pre>import * as adex from &quot;alphadex-sdk-js&quot;</pre><p>Using this method you use the reference variable to get access to the SDK functions, variables and types. E.g. to call the init function and access the clientState variable in your code, you would do it like this:</p><pre>adex.init();<br>const myOwnVariable = adex.clientState;</pre><h4>Only Method 2 works when using Svelte-Kit</h4><p>It seems only Method 2 works with Svelte-Kit so we will use this method for the rest of the tutorial. For standard Svelte, both methods work equally well.</p><h4>Import the SDK into your app</h4><p>To import all the SDK functions, variables and types at once into a reference variable add these lines at the top of your +page.svelte file.</p><pre>&lt;script lang=&quot;ts&quot;&gt;<br>  import * as adex from &quot;alphadex-sdk-js&quot;<br>&lt;/script&gt;</pre><h3>Initialize the SDK</h3><p>In order to connect to the AlphaDEX exchange (we are actually connecting to an AlphaDEX API/Websocket server), we need to run the init function of the SDK once somewhere near the start of our application.</p><p>In our example we are going to run the init function in our +page.sveltefile as this is the first component in our app. Add the following line below your import statement in your +page.svelte file:</p><pre>adex.init();</pre><p>If you save the changes, you application will attempt to connect to the AlphaDEX exchange. You wont see any changes on the screen yet, but if you want you can go into the “Developer Tools” section of your browser, you should see a message like below on the Console:</p><pre>Websocket connection 1 established with AlphaDEX server ws://ws.alphadex.net</pre><p>This confirms that you are now connected to AlphaDEX.</p><h4>We have a problem!</h4><p><em>The problem described below will only happen if you are using Svelte-Kit. If you are using standard Svelte, you can skip to the “Display AlphaDEX information” section.</em></p><p>You might have run into problems when you tried to initialize the AlphaDEX SDK in the step above (if you did not, just try to refresh your browser). You should see the error below on your console:</p><pre>ReferenceError: WebSocket is not defined.</pre><p>The reason for this error is that Svelte-Kit automatically tries to do server side rendering of your app pages and currently the AlphaDEX SDK is not suitable for running on the server. Don’t worry if you don’t know what this means, here is how you fix it.</p><h4>Switch off server side rendering for your app.</h4><p>Create a new file in the src/routes folder called +layout.server.js and add the following content in the file:</p><pre>export const ssr = false; // switch off server side rendering</pre><p>Save the file and run the following command in your console again:</p><pre>npm run dev</pre><p>Refresh your browser and you should see the very welcoming “Hello AlphaDEX” message again.</p><p><em>There might very well be better ways to solve this, so please let me know in the comments if you know how.</em></p><h3>Display AlphaDEX information</h3><p>Now that you are connected to AlphaDEX, you can access all the different variables made available by the SDK in your app.</p><h4>Displaying SDK Status</h4><p>We can very easily show the status of the SDK using the clientState.status variable. To add this to our app, add the following line directly below the init(); line in your +page.svelte file:</p><pre>let sdkStatus = adex.clientState.status</pre><p>And to display the status, add the following line underneath the “Hello Alphadex” heading in the same file:</p><pre>&lt;p&gt;SDK Status: {sdkStatus}&lt;/p&gt;</pre><p>You should see the current SDK status displayed on your screen.</p><h4>We have another problem</h4><p>If you refresh you browser screen, you should see the status showing as “LOADING”. This is indeed the initial status of the SDK when it first tries to establish a connection with AlphaDEX, but it should change very quickly to “READY” to indicate that it has successfully established a connection. But we are not seeing it change to “READY”…yet.</p><p>What is happening is that although the SDK has made a connection to AlphaDEX and the clientState.status variable has changed to “READY”, Svelte does not know that the variable has changed and therefore does not know that it should update its display to show the new value.</p><p>One way to test this is to add a button that we can press that explicitly tells Svelte to update the display for a new value. Lets do it quickly by adding the following lines to the +page.svelte file:</p><pre>...<br>let sdkStatus = adex.clientState.status;</pre><pre>//start of new lines to add<br>function showStatus() {<br>  sdkStatus = adex.clientState.status;<br>}<br>// end of new lines to add<br>...</pre><pre>&lt;p&gt;SDK Status: {sdkStatus}&lt;/p&gt;<br>//start of new lines to add<br>&lt;button on:click={showStatus}&gt;<br>  Click to show current status<br>&lt;/button&gt;<br>// end of new lines to add</pre><p>What the code above does is it adds a button that calls the showStatus function. The showStatus function simply re-assigns the clientstate.status value to sdkStatus and when this happens, Svelte knows that it needs to update the display because a displayed variable sdkStatus has been changed.</p><p>If you save this, you should now see a button that you can press to update the status shown on the screen to its current value. If you reload the browser screen, the status should initially show “LOADING”. When you press the button, it should update the display and show status as “READY”.</p><p>Although it might feel awkward, this is just a way we use to get around Svelte’s way of deciding when to refresh the screen when variables change. It is not very practical to press a button every time we want the latest data though, so lets explore a better way to deal with this problem.</p><h4>How to always display the latest data</h4><p>To get around problems like this, the AlphaDEX SDK offers an <em>observable</em> version of each variable indicated by a $ at the end of the variable name. E.g. the observable version of the status variable we have been using would be called status$.</p><p>I am not going to go into the detail of <em>observables</em> in this tutorial, but all you need to understand is that an <em>observable</em> variable allows you to <em>subscribe</em> to it so that you can receive a notification (and new value) every time it changes.</p><p>Lets implement it in our app and you will understand.</p><p>Add the following code to your +page.svelte file:</p><pre>...</pre><pre>let sdkStatus = adex.clientState.status;<br>// add the lines below<br>adex.clientState.status$.subscribe((newStatus) =&gt; {<br>  sdkStatus = adex.clientState.status;<br>  // for the same result we could also have used the <br>  // newStatus value that we receive from the subscription<br>  // sdkStatus = newStatus;<br>})</pre><pre>...</pre><p>Lets quickly review what the new code does. We call the subscribe function of the status$ observable variable (all observables have this function) and pass as our only argument a function that should be called every time the status$ observable emits a new value.</p><p>The function we pass as an argument will take the value emitted by the status$ observable as an input which I called newStatus, but you could call it anything. The only thing this function does is assign the current value of the clientState.status variable to the sdkStatus variable.</p><p>Notice that what we are doing in the function is exactly what we do when the button gets pressed.</p><p>So now, the sdkStatus variable will get updated every time the status$ observable emits a new value and Svelte will know that it needs to update the display.</p><p>Save your changes and see what happens in the browser. Refresh the page a couple of times and you should briefly notice the status showing “LOADING” before changing to “READY”.</p><p>The same principle applies to any of the other variables provided by the SDK. All the variables have an observable version available that you can subscribe to to make sure you always display the latest value of that variable in your app.</p><h4>Using Svelte stores to store the SDK variables</h4><p>Another popular way to make variables available across multiple components in Svelte is to use <em>stores</em>. In fact, <em>store</em> variables also work on the principle of sending a notification to their <em>subscribers</em> whenever they are updated, so lets see how we could make our clientState variable available using a <em>store</em>.</p><p>First you need to create a new file called store.ts in the src/lib folder and enter the following code:</p><pre>import { writable } from &#39;svelte/store&#39;;<br>import * as adex from &#39;alphadex-sdk-js&#39;;</pre><pre>adex.init();</pre><pre>export const adexState = writable(adex.clientState, function start(set) {<br> <br>// start function that runs with first subscription<br> const sub = adex.clientState.stateChanged$.subscribe(() =&gt; {<br>  set(adex.clientState);<br> });</pre><pre> // stop function that runs when last subscription closes<br> return function stop() {<br>  console.log(&#39;Stopping clientState sub...&#39;);<br>  sub.unsubscribe();<br> };<br>});</pre><p>I will not go into all the details of how stores work in Svelte, but lets quickly review what the code does:</p><ul><li>we import all the AlphaDEX SDK variables and functions into a reference variable called adex like before</li><li>we call the init() function to make sure the SDK is initialized before creating our store variable. Note that we will remove the init() function from our +page.svelte file in the steps below.</li><li>we then export a store variable we called adexState.</li><li>we create our adexState store variable by calling the writable function and passing it two arguments:</li></ul><ol><li>the initial value of the store variable — adexState.clientState</li><li>a start function that gets called when the store variable gets its first <em>subscriber</em></li></ol><ul><li>the start function itself takes a set (function) argument and returns a stop function. The stop function will be called when the last <em>subscriber</em> unsubscribes from the <em>store</em> variable.</li><li>within the start function we only do one thing, we subscribe to the SDK’sclientState.stateChanged$ observable. This observable emits a new value every time any of the variables in the clientState object changes. When this happens we use the set function that was passed as an argument to set the value of our store variable to the latest clientState value.</li><li>within the stop function we also do only one thing. We unsubscribe from the clientState.stateChanged$ observable to make sure we don’t create hanging subscriptions.</li></ul><p>That is the complicated stuff done! If you did not exactly follow what we were doing, don’t worry. You can always learn more about Svelte <em>stores</em> later. For now, lets focus on how this makes your life easier in your components.</p><p>In your +page.svelte file, delete everything and enter the following code:</p><pre>&lt;script lang=&quot;ts&quot;&gt;<br>  import { adexState } from &quot;../lib/store.js&quot;;<br>&lt;/script&gt;</pre><pre>&lt;h1&gt;Hello AlphaDEX&lt;/h1&gt;<br>&lt;p&gt;SDK Status: {$adexState.status}&lt;/p&gt;</pre><p>Our component code looks much simpler now.</p><ul><li>In the &lt;script&gt; tags we simply import our store variable adexState.</li><li>We can then use our store variable anywhere by putting a $ in front of the variable name. The $ at the front is a special Svelte character that tells Svelte that this is a store variable. Svelte will automatically subscribe to such variables when your component is loaded and will automatically unsubscribe when the component is destroyed.</li></ul><p>Save your files and make sure everything works as expected. You should again see the status changing when you refresh the page.</p><h3>Showing more interesting information</h3><p>Now that the hard work is done, you can let your creativity run free and display all kinds of live data from the AlphaDEX exchange.</p><h4>Display all AlphaDEX pairs</h4><p>Lets see if we can display the pairs that are available on the AlphaDEX exchange.</p><p>Add the following lines of code to your +page.sveltefile:</p><pre>&lt;p&gt;SDK status: {$adexState.status}&lt;/p&gt;<br>// new code to add start here<br>&lt;h3&gt;AlphaDEX Pairs&lt;/h3&gt;<br>&lt;ul&gt;<br>  {#each $adexState.pairsList as pair}<br>    &lt;li&gt;<br>      {pair.name}<br>    &lt;/li&gt;<br>  {/each}<br>&lt;/ul&gt;<br>// new code to add ends here</pre><p>Save your file and you should now see a list of names of the pairs available on AlphaDEX.</p><h4>Create a separate PairsList component</h4><p>Lets rather move our list of pairs into its own component so we can re-use it in our app.</p><p>Delete the code you added to +page.svelte in the previous section to display the list of pairs and replace it with this line:</p><pre>&lt;PairsList/&gt;</pre><p>Add the import of the PairsList component (we will create it next) below the other imports in the +page.sveltefile:</p><pre>import PairsList from &quot;../components/PairsList.svelte&quot;;</pre><p>Create a new folder called components in the src folder and create a new file called PairsList.svelte in this folder with the following code:</p><pre>&lt;script lang=&quot;ts&quot;&gt;<br>  import { adexState } from &quot;../lib/store.js&quot;;<br>&lt;/script&gt;</pre><pre>&lt;ul&gt;<br>  {#each $adexState.pairsList as pair (pair.address)}<br>    &lt;li&gt;<br>      {pair.name}<br>    &lt;/li&gt;<br>  {/each}<br>&lt;/ul&gt;</pre><p>Notice that we import the adexState store variable again here to use in our PairsList component.</p><p>Save your new PairsList.svelte file as well as the changes to your +page.svelte file and you should again see the list of pairs just like you did before, but now they are displayed in their own separate component.</p><h3>Changing AlphaDEX variables</h3><p>So far we have only been reading variables with AlphaDEX data, but the AlphaDEX SDK also have some variables that you can change that will affect the data that is available through the SDK (see a full list of these variables in the <a href="https://www.npmjs.com/package/alphadex-sdk-js">SDK documentation</a>).</p><p>For example, the AlphaDEX SDK only keeps a fully updated order book and order history for one pair at a time (it will take way too much bandwidth and memory to keep this information for all pairs on AlphaDEX). This pair is specified by the currentPairAddress field in the clientState object. If you change this field, the SDK will automatically update a number of other variables to reflect the newly selected pair. Lets incorporate this functionality in our app.</p><h4>Update the PairsList component</h4><p>First, lets update our PairsList component to enable the user to select a specific pair and set it as the current pair of the SDK.</p><p>Change your PairsList.svelte file to look like this:</p><pre>&lt;script lang=&quot;ts&quot;&gt;<br>  import { adexState } from &quot;../lib/store.js&quot;;<br>  import { clientState } from &quot;alphadex-sdk-js&quot;;</pre><pre>  function selectPair(pairAddress) {<br>    clientState.currentPairAddress = pairAddress;<br>  }</pre><pre>&lt;/script&gt;</pre><pre>&lt;ul&gt;<br>  {#each $adexState.pairsList as pair (pair.address)}<br>    &lt;li&gt;<br>      &lt;button on:click={selectPair(pair.address)}&gt;<br>        {pair.name}<br>      &lt;/button&gt;<br>    &lt;/li&gt;<br>  {/each}<br>&lt;/ul&gt;</pre><p>Lets quickly run through the changes.</p><ul><li>We added an import of the clientState object from the AlphaDEX SDK. We need to update the fields in this object when we want the SDK to fetch new information from the AlphaDEX exchange. We cannot use the <em>store</em> variable to change values in clientState.</li><li>We added a new function called selectPair to our component. This function takes a pairAddress parameter and then sets the clientState.currentPairAddress field to the new pair address. This will prompt the SDK to update all the other fields in the clientState object that are related to the currently selected pair.</li><li>We also changed our list of pairs to now consist of buttons that will call the selectPair function with the appropriate pair address when they are clicked.</li></ul><p>Once you save your new PairsList.js file, you will notice the list now consist of buttons that you can click.</p><h4>Add a PairInfo component</h4><p>At the moment we can’t see any changes when we select a new pair, so lets add a component to show the details of the currently selected pair.</p><p>Create a file called PairInfo.svelte in your src/components folder and add the following lines of code to the file:</p><pre>&lt;script lang=&quot;ts&quot;&gt;<br>  import { adexState } from &quot;../lib/store.js&quot;;<br>&lt;/script&gt;</pre><pre>&lt;h3&gt;Information for currently selected pair&lt;/h3&gt;<br>&lt;p&gt;Name: {$adexState.currentPairInfo.name}&lt;/p&gt;<br>&lt;p&gt;Radix Address: {$adexState.currentPairInfo.address}&lt;/p&gt;<br>&lt;p&gt;Last Price: {$adexState.currentPairInfo.lastPrice}&lt;/p&gt;<br>&lt;p&gt;No of sell prices in orderbook: {$adexState.currentPairOrderbook.sells.length}&lt;/p&gt;<br>&lt;p&gt;No of buy prices in orderbook: {$adexState.currentPairOrderbook.buys.length}&lt;/p&gt;</pre><p>This file adds no new functionality to what we have learned so far. It uses the AdexState <em>store</em> variable to access the AlphaDEX data and then displays a number of data points related to the currently selected pair.</p><p>Add the PairInfo component to your +page.svelte file by importing it and adding it as a component :</p><pre>...<br>// add the following line below the other import statements<br>import PairInfo from &quot;../components/PairInfo.svelte&quot;;<br>...<br>// add the following line below the &lt;PairsList/&gt; line<br>&lt;PairInfo/&gt;</pre><p>Save the PairInfo.svelte and +page.svelte files and you should now see a display of the currently selected pair’s info on the screen. The info should change when you click on another pair in the list.</p><h3>Can you build your own exchange?</h3><p>Congratulations! You now know how to display live exchange information in a Svelte app. At the moment it might not look like the information is live as there is still very little activity on the AlphaDEX test instance, but rest assured that your application will automatically update every time there is a change on the AlphaDEX exchange.</p><p>We only touched on the very basics of what the AlphaDEX SDK allows you to do. If you want to find out more about what information is available through the SDK, you can find its developer documentation <a href="https://www.npmjs.com/package/alphadex-sdk-js">here</a>.</p><p>The only aspect we have not touched on is how to submit a transaction to the AlphaDEX on-ledger component, but we will leave that for another tutorial.</p><p>Can you build the best looking exchange front-end for the Radix network? We are keen to see what you come up with and remember, you can earn a fee for all orders that get placed through your app, so there is a real incentive to build you own exchange using the AlphaDEX SDK.</p><p>If you get stuck on this tutorial or have any further questions about AlphaDEX, give us a shout on our <a href="https://t.me/alphadex_xrd">telegram channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9754200064c1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/alphadex-xrd/connecting-alphadex-to-your-svelte-app-9754200064c1">Connecting AlphaDEX to your Svelte app.</a> was originally published in <a href="https://medium.com/alphadex-xrd">AlphaDEX XRD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[AlphaDEX Tutorials]]></title>
            <link>https://medium.com/alphadex-xrd/alphadex-tutorials-2fb17ea04dbb?source=rss-f62fc3c37a01------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fb17ea04dbb</guid>
            <category><![CDATA[decentralized-finance]]></category>
            <category><![CDATA[radix-dlt]]></category>
            <category><![CDATA[decentralized-exchange]]></category>
            <category><![CDATA[alphadex]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Fred Liebenberg]]></dc:creator>
            <pubDate>Tue, 09 May 2023 14:15:15 GMT</pubDate>
            <atom:updated>2023-06-02T07:55:12.109Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*G3f544CUXbIOkAM3ORtIUw.png" /></figure><p>This article provides a quick reference to various tutorials written for the <a href="https://alphadex.net/">AlphaDEX</a> decentralized exchange platform on the <a href="https://radixdlt.com/">Radix DLT</a> network. If you have written a tutorial about an AlphaDEX feature, let us know on our <a href="https://t.me/alphadex_xrd">telegram channel</a> and we will gladly list it here.</p><h3>How to connect to the AlphaDEX SDK in your javascript/typescript app.</h3><ul><li><a href="https://medium.com/@fliebenberg/connecting-alphadex-to-your-react-js-app-d8822e99cdcd">Connecting AlphaDEX to your REACT JS app.</a></li><li>Connecting AlphaDEX to your ANGULAR app. (coming soon)</li><li><a href="https://medium.com/@fliebenberg/connecting-alphadex-to-your-svelte-app-9754200064c1">Connecting AlphaDEX to your SVELTE app</a>.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fb17ea04dbb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/alphadex-xrd/alphadex-tutorials-2fb17ea04dbb">AlphaDEX Tutorials</a> was originally published in <a href="https://medium.com/alphadex-xrd">AlphaDEX XRD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Connecting AlphaDEX to your React JS app.]]></title>
            <link>https://medium.com/alphadex-xrd/connecting-alphadex-to-your-react-js-app-d8822e99cdcd?source=rss-f62fc3c37a01------2</link>
            <guid isPermaLink="false">https://medium.com/p/d8822e99cdcd</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[alphadex]]></category>
            <category><![CDATA[decentralized-exchange]]></category>
            <category><![CDATA[radix-dlt]]></category>
            <category><![CDATA[decentralized-finance]]></category>
            <dc:creator><![CDATA[Fred Liebenberg]]></dc:creator>
            <pubDate>Tue, 09 May 2023 14:01:10 GMT</pubDate>
            <atom:updated>2023-05-09T14:11:59.619Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*G3f544CUXbIOkAM3ORtIUw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/128/1*KfItPnn5AIb-ld4vu9Ynyg.png" /></figure><p>This is a quick tutorial on how to connect your React JS app to the <a href="https://alphadex.net/">AlphaDEX</a> decentralized exchange platform on <a href="https://radixdlt.com/">Radix DLT</a>. You can find more AlphaDEX related tutorials like this <a href="https://medium.com/p/2fb17ea04dbb/">here</a>.</p><p>This tutorial assumes you have a basic knowledge of how React apps work. If you don&#39;t, then you can learn more about React at <a href="https://reactjs.org/">reactjs.org</a>.</p><p>You will need Node.js installed on your machine to follow this tutorial. If you do not have it installed yet, you can follow the instructions to do so on their website <a href="https://nodejs.org/">nodejs.org</a>.</p><h3>Set up new React app</h3><p>If you have an existing React app already, you can jump straight to the “Install AlphaDEX SDK” step.</p><h4>Create a new app</h4><p>The fastest way to create a new React app is to use a Node.js package called create-react-app. To use it, move to the folder in which you want to create your new app and run the following command:</p><pre>npx create-react-app hello-alphadex-react</pre><p>This might take a few seconds and will create a new folder called hello-alphadex-react which contains all the files needed for a new React app.</p><h4>Run your new app</h4><p>Move to the newly created app directory with this command:</p><pre>cd hello-alphadex-react</pre><p>Run your new app with this command:</p><pre>npm start</pre><p>A new browser window should open up with your new app. If it does not open automatically, you can open your browser and type localhost:3000 into the address bar. You should see a blank screen with a spinning React logo and a link to the React website.</p><h4>Clean up the app</h4><p>For this tutorial, we want a clean slate to work with, so open the App.js file in the src directory and change it to look like this:</p><pre>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;h1&gt;Hello AlphaDEX&lt;/h1&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><p>Save the file with your changes and the browser window will automatically be updated to only show “Hello AlphaDEX” on a blank screen. Not the prettiest screen, but we now have a blank slate to show you how to connect your app to AlphaDEX.</p><h3>Install AlphaDEX SDK</h3><p>Before we can connect to AlphaDEX, we need to install the SDK in our project. To do this, make sure you are in your project directory and run the command:</p><pre>npm install alphadex-sdk-js</pre><p>This will install the AlphaDEX SDK files in your project’s node_modulesdirectory, ready to be used in your project.</p><h3>Import the AlphaDEX SDK</h3><p>OK, we are ready to connect our app with AlphaDEX (finally!).</p><p>In order to use the functionality in the SDK, you need to import the required functionality into your app. You can do this in 2 ways.</p><h4><strong>Method 1 (Import functionality as needed)</strong></h4><p>With this method you only import the functions and variables that you will need for a specific task e.g. if we only want to import the init function and clientState variable, we will do it like this:</p><pre>import {init, clientState} from &quot;alphadex-sdk-js&quot;</pre><p>Now you can access the imported functions/variables directly using their name. E.g. I can call the init function and access the clientState variable like this in my code:</p><pre>init();<br>const myOwnVariable = clientState;</pre><h4><strong>Method 2 (Import all functionality at once)</strong></h4><p>With this method you import all the SDK functions, variables and types at once into a reference variable like this: (I called the reference variable adex below, but you can call it anything you like.)</p><pre>import * as adex from &quot;alphadex-sdk-js&quot;</pre><p>Using this method you use the reference variable to get access to the SDK functions, variables and types. E.g. to call the init function and access the clientState variable in your code, you would do it like this:</p><pre>adex.init();<br>const myOwnVariable = adex.clientState;</pre><h3>Initialize the SDK</h3><p>In order to connect to the AlphaDEX exchange (we are actually connecting to an AlphaDEX API/Websocket server), we need to run the init function of the SDK once somewhere near the start of our application.</p><p>In our example we are going to run the init function in our App.js file as this is the first (root) component in our app. You can also run the init function in the index.js file of your project. Add the following lines just below the existing import statements in your App.js file:</p><pre>import { init } from &quot;alphadex-sdk-js&quot;;<br><br>init();</pre><p>If you save the changes, you application will attempt to connect to the AlphaDEX exchange. You wont see any changes on the screen yet, but if you want you can go into the “Developer Tools” section of your browser, you should see a message like below on the Console:</p><pre>Websocket connection 1 established with AlphaDEX server ws://ws.alphadex.net</pre><p>This confirms that you are now connected to AlphaDEX.</p><h3>Display AlphaDEX information</h3><p>Now that you are connected to AlphaDEX, you can access all the different variables made available by the SDK in your app.</p><h4>Save AlphaDEX variables in your app state</h4><p>The AlphaDEX clientState object contains all the variables that can be used by your app. These variables are automatically kept up to date by the SDK, which means they are constantly changed to reflect the latest values on the exchange.</p><p>To use the clientState object in your app, you need to import it from alphadex-sdk-js. If you followed Method 1 above for importing the sdk variables, then you need to add clientState to your import statement:</p><pre>import {init, clientState} from &quot;alphadex-sdk-js&quot;;</pre><p>If you used Method 2 by importing all the variables as a reference variable, then clientState is already imported and can be accessed as adex.clientState in your code.</p><p>To display the constantly changing values of the clientState object in your react app, you want to save them in your app state using the useState hook.</p><p>To import the useState function into your App.js file, add this line at the top of the file:</p><pre>import { useState } from &quot;react&quot;;</pre><p>Then add the following line to your App.js file as the <strong>first line in your App() function:</strong></p><pre>const [adexState, setAdexState] = useState(clientState);</pre><p>This line sets a state variable called adexState equal to the initial value of clientState and also provides a function called setAdexState which we can use to update the adexState variable in our app.</p><h4>Display AlphaDEX data on the screen</h4><p>Lets display some AlphaDEX information on the screen. Add the following line to the App.js file just below the “Hello AlphaDEX” heading:</p><pre>&lt;p&gt; AlphaDEX SDK connection status: {adexState.status} &lt;/p&gt;</pre><p>This line prints out the status of the SDK connection on the screen. Save the file and you should see a new line on your screen showing the status as “LOADING”.</p><p>Well done! You have just displayed your first AlphaDEX value to the screen.</p><p>There is a problem though. The status should actually be “READY” to indicate that the AlphaDEX connection is live and all variables are being updated and not “LOADING”, which is the initial status of the connection while it is fetching information from AlphaDEX. So our app is displaying the status as it was when we first loaded the clientState object, but it is not showing any updates to the data after that. Lets fix that…</p><h4>Display live AlphaDEX data on the screen</h4><p>The problem is occurring because React does not know that the fields in the clientState object has changed in the background (that is what the SDK is doing), so it does not know to show the new information on the screen. We need to explicitly tell it that the clientState object has changed to force it to display the new updated information on the screen.</p><p>To do this, we will subscribe to an observable variable that the SDK makes available for this purpose. I will not go into the details of how observables work in this tutorial, but suffice to know that is will let our app know every time data changes happen in the clientState object, which allows us to tell the app to show the new information on the screen.</p><p>We will subscribe to the observable variable in a React useEffect hook. First, we need to add useEffect to our import statement at the top of the App.js file:</p><pre>import { useEffect, useState } from &quot;react&quot;;</pre><p>Now we add the useEffect code as the second line in our App() function:</p><pre>...<br>const [adexState, setAdexState] = useState(clientState);<br>// new useEffect code starts here<br>useEffect(() =&gt; {<br>  let sub = clientState.stateChanged$.subscribe(newState =&gt; setAdexState(newState));<br>  return () =&gt; if (sub) {sub.unsubscribe()};<br>}, []);<br>// new useEffect code stops here</pre><p>Lets quickly run through what the new code does:</p><ul><li>We setup a React useEffect hook by calling the useEffect function and passing it two parameters, a function that it will run only once in this case and an empty array [] to indicate that the effect must only run once when the App component is loaded.</li><li>The function we pass into the useEffect will create a new subscription called sub to an observable variable called clientState.stateChanged$. Every time the observable variable changes, it will emit a new variable called newState which we will then use to update our adexState variable to. By using the function setAdexState to set our adexState variable, we are also telling React to update what is displayed on the screen to reflect the new value.</li><li>We also create a return function in the useEffect which will be called when the App component is destroyed by React (probably when you exit the app website) to make sure we destroy our subscription sub to prevent memory leaks in our app.</li></ul><p>If you save the data and look at the output on the screen, it should now correctly reflect the status as “READY”. You can click the refresh button on your browser to see the value briefly showing “LOADING” and then “READY” as it gets updated after the connection with AlphaDEX is established.</p><h3>Showing more interesting information</h3><p>Now that the hard work is done, you can let your creativity run free and display all kinds of live data from the AlphaDEX exchange.</p><h4>Display all AlphaDEX pairs</h4><p>Lets see if we can display the pairs that are available on the AlphaDEX exchange.</p><p>Add the following lines of code to your App.js file:</p><pre>&lt;p&gt;AlphaDEX SDK Connection status: {adexState.status}&lt;/p&gt;<br>// new code to add start here<br>&lt;h3&gt;AlphaDEX Pairs&lt;/h3&gt;<br>&lt;ul&gt;<br>  {adexState.pairsList.map((pair, index) =&gt; &lt;li key={index}&gt;{pair.name}&lt;/li&gt;)}<br>&lt;/ul&gt;<br>// new code to add ends here</pre><p>Save your file and you should now see a list of names of the pairs available on AlphaDEX.</p><h4>Create a separate PairsList component</h4><p>Lets rather move our list of pairs into its own component so we can re-use it in our app.</p><p>Delete the code you added to App.js in the previous section to display the list of pairs and replace it with this line:</p><pre>&lt;PairsList adexState={adexState} /&gt;</pre><p>Add the import of the PairsList component (we will create it next) below the other imports in the App.js file:</p><pre>import{ PairsList } from &quot;./PairsList&quot;;</pre><p>In the src directory create a new file called PairsList.js with the following code:</p><pre>export function PairsList(props) {<br>  return (<br>    &lt;div&gt;<br>      &lt;h3&gt;AlphaDEX Pairs&lt;/h3&gt;<br>      &lt;ul&gt;<br>        {props.adexState.pairsList<br>          .map((pair, index) =&gt; &lt;li key={index}&gt;{pair.name}&lt;/li&gt;)<br>         }<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>Notice that we pass the adexState variable as a prop to our new PairsList component. This is the simplest way to pass the AlphaDEX data between your components.</p><p>Save your new PairsList.js file as well as the changes to your App.js file and you should again see the list of pairs just like you did before, but now they are displayed in their own separate component.</p><h3>Accessing AlphaDEX data in all components</h3><p>There are several approaches you can follow to access the AlphaDEX data in all your components. We have already implemented one approach, which is to pass the AlphaDEX data between components using props, but this can get quite complicated in more advanced apps with many different levels of components.</p><p>Another approach would be to implement a state management library like Redux to hold the AlphaDEX data, but that is beyond the scope of this tutorial.</p><p>One other approach that is easy to implement and avoids the complexity of passing props, is to create a React Context variable that can then be shared with all child components in your app.</p><h4>Create a context variable for AlphaDEX data</h4><p>To create a React context variable for the AlphaDEX data, add createContext to your import from “react” and create a context called AdexStateContext with the following lines of code in your App.js file:</p><pre>// new import statement that includes createContext<br>import { createContext, useEffect, useState } from &quot;react&quot;;<br><br>// create a new context - add as first line after import statements<br>export const AdexStateContext = createContext();</pre><h4>Add a context provider to the App component</h4><p>To pass the context variable to all child components of your app, you need to wrap the contents of your App component with a Context Provider component. Change the return portion of your App component to look like this:</p><pre>return (<br>  &lt;AdexStateContext.Provider value={adexState}&gt;<br>    &lt;h1&gt;Hello AlphaDEX&lt;/h1&gt;<br>    &lt;p&gt;AlphaDEX SDK connection status: {adexState.status}&lt;/p&gt;<br>    &lt;PairsList /&gt;<br>  &lt;/AdexStateContext.Provider&gt;<br>);</pre><p>Note that we replaced the wrapping &lt;div&gt; component with the AdexState.Provider component and removed the adexState prop from the PairsList component.</p><p>We assigned the adexState state variable to the AdexStateContext. This means we can now access the adexState variable in any of the child components using the AdexStateContext.</p><p>In PairsList.js we now need to import the useContext function and the AdexStateContext we just created to access the AlphaDEX data in the component. We can then assign the data to a local variable and use that variable in our component. The updated PairsList.js file should look like this:</p><pre>import { useContext } from &quot;react&quot;;<br>import { AdexStateContext } from &quot;./App&quot;;<br><br>export function PairsList() {<br>  const adexState = useContext(AdexStateContext);<br>return (<br>  &lt;div&gt;<br>      &lt;h3&gt;AlphaDEX Pairs&lt;/h3&gt;<br>      &lt;ul&gt;<br>        {adexState.pairsList<br>          .map((pair, index) =&gt; &lt;li key={index}&gt;{pair.name}&lt;/li&gt;)<br>        }<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>Note that we removed any reference to props from the PairsList component.</p><p>You can now access the AdexStateContext in any of the components in your app as long as they are a child component of the App component.</p><h3>Changing AlphaDEX variables</h3><p>So far we have only been reading variables with AlphaDEX data, but the AlphaDEX SDK also have some variables that you can change that will affect the data that is available through the SDK (see a full list of these variables in the <a href="https://www.npmjs.com/package/alphadex-sdk-js">SDK documentation</a>).</p><p>For example, the AlphaDEX SDK only keeps a fully updated order book and order history for one pair at a time (it will take way too much bandwidth and memory to keep this information for all pairs on AlphaDEX). This pair is specified by the currentPairAddress field in the clientState object. If you change this field, the SDK will automatically update a number of other variables to reflect the newly selected pair. Lets incorporate this functionality in our app.</p><h4>Update the PairsList component</h4><p>First, lets update our PairsList component to enable the user to select a specific pair and set it as the current pair of the SDK.</p><p>Change your PairsList.js file to look like this:</p><pre>import { useContext } from &quot;react&quot;;<br>import { AdexStateContext } from &quot;./App&quot;;<br>import { clientState } from &quot;alphadex-sdk-js&quot;;<br><br>export function PairsList() {<br>  const adexState = useContext(AdexStateContext);<br><br>  const selectPair = (pairAddress) =&gt; {<br>    clientState.currentPairAddress = pairAddress;<br>  }<br><br>return (<br>  &lt;div&gt;<br>      &lt;h3&gt;AlphaDEX Pairs&lt;/h3&gt;<br>      &lt;ul&gt;<br>        {adexState.pairsList<br>          .map((pair, index) =&gt; <br>            &lt;li key={index}&gt;<br>              &lt;button = onClick={() =&gt; selectPair(pair.address)}&gt;<br>                {pair.name}<br>              &lt;/button&gt;<br>            &lt;/li&gt;)<br>        }<br>      &lt;/ul&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>Lets quickly run through the changes.</p><ul><li>We added an import of the clientState object from the AlphaDEX SDK. We need to update the fields in this object when we want the SDK to fetch new information from the AlphaDEX exchange.</li><li>We added a new function called selectPair to our component. This function takes a pairAddress parameter and then sets the clientState.currentPairAddress field to the new pair address. This will prompt the SDK to update all the other fields in the clientState object that are related to the currently selected pair.</li><li>We also changed our list of pairs to now consist of buttons that will call the selectPair function with the appropriate pair address when they are clicked.</li></ul><p>Once you save your new PairsList.js file, you will notice the list now consist of buttons that you can click.</p><h4>Add a PairInfo component</h4><p>At the moment we can’t see any changes when we select a new pair, so lets add a component to show the details of the currently selected pair.</p><p>Create a file called PairInfo.js in your src directory and add the following lines of code to the file:</p><pre>import { useContext } from &quot;react&quot;<br>import { AdexStateContext } from &quot;./App&quot;<br><br>export function PairInfo() {<br>  const adexState = useContext(AdexStateContext);<br>  return (<br>    &lt;div&gt;<br>      &lt;h3&gt; Information for currently selectd pair&lt;/h3&gt;<br>      &lt;p&gt;Name: {adexState.currentPairInfo.name}&lt;/p&gt;<br>      &lt;p&gt;Address: {adexState.currentPairInfo.address}&lt;/p&gt;<br>      &lt;p&gt;Last Price: {adexState.currentPairInfo.lastPrice}&lt;/p&gt;<br>      &lt;p&gt;No of sell prices in orderbook: {adexState.currentPairOrderbook.sells.length}&lt;/p&gt;<br>      &lt;p&gt;No of buy prices in orderbook: {adexState.currentPairOrderbook.buys.length}&lt;/p&gt;<br>    &lt;/div&gt;<br>  )<br>}</pre><p>This file adds no new functionality to what we have learned so far. It uses the AdexStateContext to access the AlphaDEX data and then displays a number of data points related to the currently selected pair.</p><p>Add the PairInfo component to your App.js file by importing it and adding it as a child component in the App component:</p><pre>...<br>// add the following line below the other import statements<br>import { PairInfo } from &quot;./PairInfo&quot;;<br>...<br>// add the following line below the &lt;PairsList/&gt; line<br>&lt;PairInfo/&gt;</pre><p>Save the PairInfo.js and App.js files and you should now see a display of the currently selected pair’s info on the screen. The info should change when you click on another pair in the list.</p><h3>Can you build your own exchange?</h3><p>Congratulations! You now know how to display live exchange information in a React app. At the moment it might not look like the information is live as there is still very little activity on the AlphaDEX test instance, but rest assured that your application will automatically update every time there is a change on the AlphaDEX exchange.</p><p>We only touched on the very basics of what the AlphaDEX SDK allows you to do. If you want to find out more about what information is available through the SDK, you can find its developer documentation <a href="https://www.npmjs.com/package/alphadex-sdk-js">here</a>.</p><p>The only aspect we have not touched on is how to submit a transaction to the AlphaDEX on-ledger component, but we will leave that for another tutorial.</p><p>Can you build the best looking exchange front-end for the Radix network? We are keen to see what you come up with and remember, you can earn a fee for all orders that get placed through your app, so there is a real incentive to build you own exchange using the AlphaDEX SDK.</p><p>If you get stuck on this tutorial or have any further questions about AlphaDEX, give us a shout on our <a href="https://t.me/alphadex_xrd">telegram channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d8822e99cdcd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/alphadex-xrd/connecting-alphadex-to-your-react-js-app-d8822e99cdcd">Connecting AlphaDEX to your React JS app.</a> was originally published in <a href="https://medium.com/alphadex-xrd">AlphaDEX XRD</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>