<?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 Tommy Chan on Medium]]></title>
        <description><![CDATA[Stories by Tommy Chan on Medium]]></description>
        <link>https://medium.com/@tommychan?source=rss-e7c0f498f7a4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Q332vvtNn0-6Wqhy.jpg</url>
            <title>Stories by Tommy Chan on Medium</title>
            <link>https://medium.com/@tommychan?source=rss-e7c0f498f7a4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 08:41:11 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tommychan/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[The Graph Curator Program Retrospective (from a Developer’s Viewpoint)]]></title>
            <link>https://tommychan.medium.com/the-graph-curator-program-retrospective-from-a-developers-viewpoint-13e7e16fbc14?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/13e7e16fbc14</guid>
            <category><![CDATA[curator]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[the-graph]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Sun, 20 Dec 2020 06:40:51 GMT</pubDate>
            <atom:updated>2020-12-20T19:35:15.065Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*yzCwwXdzZlzwxEZB.jpg" /></figure><h3>Introduction</h3><p>For the past two months, I have had the pleasure and opportunity to participate in The Graph’s curator Program. The Curator Program was created to help educate users about curation and signalling, get them familiar with subgraphs, and contributing to The Graph ecosystem. This article will provide a retrospective regarding my experience so far as a participant in the Curator Program.</p><h3>Mission of The Graph</h3><p>The Graph started about 2.5 years ago to help developers quickly build on blockchains while creating a public data layer on Ethereum (and possibly more support on other chains soon). With the explosion of DeFi, The Graph has grown to process about 800 MM requests a day.</p><h3>Roles in The Graph Ecosystem</h3><p>There are multiple roles within The Graph’s ecosystem to ensure the smooth operation of the protocol as a whole. I won’t go into the details, but you can read more about that <a href="https://thegraph.com/blog/the-graph-network-in-depth-part-1">here</a>.</p><p>I won’t go into details with regards to other roles, but as a Curator, our job functions are:</p><ul><li>Write and develop subgraphs</li><li>Discover new subgraphs that others write and access the quality</li><li>Signal to Indexers which APIs and subgraphs they should be including</li></ul><p>To ensure that there are high-quality subgraphs that the indexers can reliably index, the Curator’s role is to signal high-quality APIs and earn a commission off each query.</p><h3>The Graph’s Curator Program</h3><p>The program’s goal is to ensure curators gain the necessary skills required to be a successful curator on the network.</p><p>Suppose we find or build a subgraph that we believe in. In that case, we deposit GRT on a bonding curve to signal to intend to enable discovery for the subgraph for others (and earn a portion of query fees).</p><h3>Retrospective on the Curator Program</h3><p>There were definitely some moments in the program that stood out to me. In no particular order:</p><h4>Hearing the Co-founder Talk About the Vision</h4><p>Just hearing the story Yaniv told regarding how he started the protocol was something inspiring to me. To be able to index data and be the backbone to enable Web3 resonates with me as I’m also a developer, and I genuinely believe in a decentralized web. I’m glad to be a part of the new revolution, and I think The Graph is paving the way forward to enable this.</p><h4>Realizing that The Graph Team is a Small Team</h4><p>To be honest, I’m blown away by the level of thought and planning that went into this curator program. The team managed to develop the 4 part assignments for the curators to ensure their understanding and commitment to the role are upheld. They also had to handle questions and queries of the 1500+ curators that enrolled, in addition to going through each of the 4 assignments everyone single curator handed in.</p><p>For such a small team to accomplish this, they must not sleep a lot. Even my partner was impressed when I told her about the program and the goal of the program.</p><h4>Knowing That Curators Are From Around The World</h4><p>Well designed decentralized protocols are designed to be inclusive and open. The Graph embodies this mantra. The curators are not judged by their race, age, or religion, but rather their desire to signal good quality API/subgraphs. It’s refreshing to know this, especially in a world where there can be so much animosity and distrust.</p><h3>Conclusion</h3><p>Overall, I’m just speechless at what a small team has managed to accomplish with the program, and I’m so grateful that The Graph is paving the way forward for a decentralized, Web3 future. In a sea of token projects, it’s sometimes hard to find a project with a laser focus on its mission, and I’m glad I have found one in The Graph. I’m personally super excited about 2021 and where the space is going. Having worked on various projects that leverage subgraphs, I know first hand how useful The Graph is for providing developers with an API for their Web3 apps.</p><p>I can’t wait to start signaling on subgraphs next year when that aspect of the protocol comes online!</p><p>For more information, visit The Graph website: <a href="https://thegraph.com/">https://thegraph.com</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=13e7e16fbc14" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Tutorial: Build a Subgraph to Index Farming Staking Rewards Data]]></title>
            <link>https://tommychan.medium.com/tutorial-build-a-subgraph-to-index-farming-staking-rewards-data-8bd88b5efc44?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/8bd88b5efc44</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[the-graph]]></category>
            <category><![CDATA[the-graph-protocol]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Sun, 22 Nov 2020 06:21:46 GMT</pubDate>
            <atom:updated>2020-12-20T04:08:51.211Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>The Decentralized Finance (DeFi) space blossomed in 2020 and we have seen an exponential growth of the sector, from just over 500MM to over 14B (USD) total locked valued (inside contracts) at the end of November of 2020. Part of the success of the space can be attributed to the incentives that were created for providing liquidity to new DeFi projects. In order to attract capital to these new projects, these startups offer rewards in exchange for investors’ capital.</p><p>These incentives are what is known as Liquidity Mining or Yield Farming and this has attracted a lot of capital inflow. Farmers (aka investors) that want a part of a project’s governance tokens in the quest for the best yield have flocked to these projects. However, it is quite difficult to know what a user has earned from participating in these liquidity mining programs. Thankfully, we can write a custom subgraph to index all the earnings from staking in the farming (liquidity providing) contracts.</p><h3>Benefits of Creating a Subgraph</h3><p>The benefit of creating a subgraph to index the farming rewards is that we can monitor and track a user’s profits and losses (P+L) as a result of providing liquidity. Users who are not careful can actually risk losing capital mining the tokens as the price of the tokens can change drastically. Therefore, it’s imperative that we have good data to provide insights to track investments gains and losses.</p><p>In addition, reading from the blockchain is an expensive and tedious operation as we need to set up a node to query the state of the chain.</p><h3>Create the Subgraph</h3><p>In this hands on tutorial, we will read the Sushi MasterChef staking rewards contract. This is rewards contract for the original SushiSwap exchange, which was tremendously popular with yield farmers.</p><p>The MasterChef contract can be located here: <a href="https://etherscan.io/address/0xc2edad668740f1aa35e4d8f227fb8e17dca888cd#readContract">https://etherscan.io/address/0xc2edad668740f1aa35e4d8f227fb8e17dca888cd#readContract</a></p><h3>1.) Create the schema</h3><p>The first thing we want to do when we build a subgraph is to determine what the schema of the data to be stored should look like. In our example, the data we want is what the rewards are being given out for a specific user, so naturally we would want a User entity:</p><pre>type User @entity {<br>  id: ID!<br>  liquidityPositions: [LiquidityPosition!] @derivedFrom(field: &quot;user&quot;)<br>}<br><br>type LiquidityPosition @entity {<br>  id: ID!<br>  user: User!<br>  poolAddress: Bytes!<br>  balance: BigDecimal!<br>  pendingReward: BigDecimal!<br>}</pre><p>Next, we want to create an object that references this User, and in our example we call that a LiquidityPosition. What we want is to extract the position of a user’s staked token and also their pending rewards so we can calculate the estimated profits at any point in time.</p><p>This is an important part of the process and it will depend around your specific use case.</p><h3>2.) Update subgraph.yaml</h3><p>The next step is to define which contracts and which events from that contract we want to listen for. To determine this, you will need to do some manual investigation first.</p><p>Start by going through the contract’s history and looking for a transaction you would like to listen to. Once you find a transaction, you can see which emits are being emitted. In our example, any time the contract emits a Withdraw or Deposit event, we want to be aware of it. Therefore, in the eventHandlers section, we write which event we want to listen to. In addition, we need to write a handler for it. For now, leave that empty.</p><p>Next, we need to look at the startBlock of the contract — we don’t want to start before this block since it won’t exist! The MasterChef contract started at block 10736242, so that’s what we’ll use.</p><p>We also need to grab the ABI or the interface file that the contract represents. We can do so by going to Etherscan and then copying the contract’s ABI. We’ll save this content under abi/MasterChef.json</p><p>Finally, we need to use the entities that we created earlier, so add those in the entities section.</p><p>Your file should look like this at this point:</p><pre>specVersion: 0.0.2<br>description: Fetches the user staked balances on the Sushiswap AMM protocol.<br>repository: https://github.com/tommytchan/masterchef-sushi-stakers-subrgraph<br>schema:<br>  file: ./schema.graphql<br>dataSources:<br>  - kind: ethereum/contract<br>    name: MasterChef<br>    network: mainnet<br>    source:<br>      address: &#39;0xc2edad668740f1aa35e4d8f227fb8e17dca888cd&#39;<br>      abi: MasterChef<br>      startBlock: 10736242<br>    mapping:<br>      kind: ethereum/events<br>      apiVersion: 0.0.4<br>      language: wasm/assemblyscript<br>      entities:<br>        - User<br>        - LiquidityPosition<br>      abis:<br>        - name: MasterChef<br>          file: ./abis/MasterChef.json<br>      eventHandlers:<br>        - event: Withdraw(indexed address,indexed uint256,uint256)<br>          handler: &lt;TO BE FILLED OUT&gt;<br>        - event: Deposit(indexed address,indexed uint256,uint256)<br>          handler: &lt;TO BE FILLED OUT&gt;<br>      file: ./src/mapping.ts</pre><h3>3.) Create the mapping.ts file</h3><p>The final piece of information we need to provide is the mapping.ts file. This file will let the graph indexer know how to parse out the blockchain data and to store that information as the entities that we have defined earlier. There are 2 events that are interested in listening for: Withdraw and Deposit. Therefore, we would need to write the corresponding functions that are required to store the entities on the graph.</p><p>We’ll start by writing the function handleDeposit():</p><pre>export function <em>handleDeposit</em>(event: Deposit): void {<br>  let pid = event.params.pid;<br>  let contractAddrs = event.address as Address;<br>  let userAddrs = event.params.user;<br>  handleEvent(pid, userAddrs, contractAddrs);<br>}</pre><p>This function will take the event, which is of a Deposit event, and will extract key information that we need, and send it to our handleEvent method.</p><p>Now let’s look at handleWithdraw():</p><pre>export function <em>handleWithdraw</em>(event: Withdraw): void {<br>  let pid = event.params.pid;<br>  let contractAddrs = event.address as Address;<br>  let userAddrs = event.params.user;<br>  handleEvent(pid, userAddrs, contractAddrs);<br>}</pre><p>This function is very similar to the previous one, except this one has an input of Withdraw. Both of these function will call our handleEvent to actually handle the logic to create the entities in the graph.</p><pre>function getLpId(poolAddress: Address, userAddress: Address): string {<br>  return poolAddress.toHexString().concat(&#39;-&#39;).concat(userAddress.toHexString());<br>}</pre><pre>function convertTokenToDecimal(tokenAmount: BigInt, exchangeDecimals: BigInt): BigDecimal {<br>  if (exchangeDecimals == ZERO_BI) {<br>    return tokenAmount.toBigDecimal();<br>  }<br>  return tokenAmount.toBigDecimal().div(exponentToBigDecimal(exchangeDecimals));<br>}</pre><pre>function handleEvent(pid: BigInt, userAddrs: Address, contractAddrs: Address): void {<br>  let masterChef = MasterChef.<em>bind</em>(contractAddrs);<br>  let pool = masterChef.poolInfo(pid);<br>  let poolAddress = pool.value0;<br>  let userId = userAddrs.toHex();<br>  let user = User.<em>load</em>(userId);<br>  if (user == null) {<br>    user = new User(userId);<br>    user.save();<br>  }<br>  let lpId = getLpId(poolAddress, userAddrs);<br>  let lp = LiquidityPosition.<em>load</em>(lpId);<br>  if (lp == null) {<br>    lp = new LiquidityPosition(lpId);<br>    lp.user = user.id;<br>    lp.poolAddress = poolAddress;<br>  }<br>  lp.balance = convertTokenToDecimal(masterChef.userInfo(pid, userAddrs).value0, BI_18);<br>  lp.save();<br>}</pre><p>The handleEvent function will check to see if the user exists and will create one if it doesn’t. Afterwards it will check to see if the LiquidityPosition exists. Again if it doesn’t exist, it will create a new one. When we have the User and the LiquidityPosition, we then query the MasterChef contract by first binding the contract to the address, and then calling the MasterChef contract by getting the pool first, which will give us the staking pool address that we want to store. In the MasterChef contract, there are multiple staking pools and thus we need to differentiate which pool the user has staked in.</p><p>Once we have this information, we can then query the balance of a user’s staking reward by again calling the contract, this time with the userInfo method.</p><p>We won’t cover the library for saving the entities as the graph <a href="https://thegraph.com/docs/define-a-subgraph#writing-mappings">has a section on this</a>. What is important here is that we have extracted custom information that we need in order to store it for our use.</p><p>The final thing to do now is to update the subgraph.yaml file with our new functions we created like so:</p><pre>eventHandlers:<br>  - event: Withdraw(indexed address,indexed uint256,uint256)<br>    handler: handleDeposit<br>  - event: Deposit(indexed address,indexed uint256,uint256)<br>    handler: handleWithdraw</pre><h3>4.) Deploy the Subgraph</h3><p>Once we have all the pieces ready, the next thing is to configure the deployment to The Graph!</p><p>Our deployment script is simple — we just need to call `graph deploy`:</p><pre>graph deploy &lt;my_username&gt;/masterchef-sushi-stakers-subgraph --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/</pre><p>Once it is deployed, you can go on the website for the subgraph that was located for you to check the parsing status. Click on the Logs tab to see the parsing status and history.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HW0W7rEEOBvkQRiaApOLRQ.png" /></figure><h3>Conclusion</h3><p>We have just described how to create a brand new subgraph with the custom entities that are required. This subgraph is actually deployed live and is being used for <a href="https://apy.vision/">APY.vision</a>, a tool for liquidity providers to get analytics for their pools on AMMS such as Uniswap and Balancer.</p><p>For more information about how to create a subgraph, please refer to <a href="https://thegraph.com/docs/define-a-subgraph">docs section on the Graph’s website</a>. Happy subgraphing!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8bd88b5efc44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing Memorial.Network]]></title>
            <link>https://tommychan.medium.com/introducing-memorial-network-61f440627b98?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/61f440627b98</guid>
            <category><![CDATA[matic-network]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Fri, 30 Oct 2020 20:13:43 GMT</pubDate>
            <atom:updated>2020-10-30T20:20:34.107Z</atom:updated>
            <content:encoded><![CDATA[<h3>Memorial Network is a community-driven metaverse of permanent digital NFT memorials to honor loved ones and preserve family history.</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*KsohC85hiyzVu0OqpNI0Yg.gif" /></figure><blockquote><em>“There’s that quote that you die two deaths — when you actually die and the last time someone utters your name,” she told me. “I actually think that we die three deaths: the time when you die, the last time someone utters your name, and </em><strong><em>the time when the final traces of you are erased from the Internet.”</em></strong></blockquote><blockquote><em>And that will probably be a really long time for most of us because it’s the Internet.</em></blockquote><p>– Taylor Majewski <a href="https://divinations.substack.com/p/who-gets-to-solve-death">https://divinations.substack.com/p/who-gets-to-solve-death</a></p><h3>I. Genesis Block (Birth)</h3><p>We’ve seen a lot of people being affected by COVID19 this year (over 1MM deaths and rising) and wanted to build something meaningful and everlasting.</p><p>With blockchain technology, we can remember our loved ones and pass on our legacies forever (or at least a really <em>really</em> long time) through digital memorial plots represented as NFTs on a permanent, immutable store.</p><p>The Memorial.Network metaverse is represented by a pyramid with a limited supply of 10,000 memorial plots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*c5sWAsvC9eqrZdFd.png" /></figure><h3>II. Community Governance (Life)</h3><p>Once your acquire your memorial plot NFT (ERC-721 token), you have the option to <strong>activate</strong> your memorial.</p><p>This <strong>activation</strong> will lock your memorial for transfer/trading forever, but unlocks multimedia uploads to your memorial AND begins <strong>generation</strong> of MEM governance tokens (ERC-20 token).</p><p>Governance of Memorial.Network is up to the community through the MEM token.</p><p>MEM tokens can be used to vote on proposals such as additional land creation, or new gallery features to be added. If the community decides to allow for new memorial plots, these new memorials can only be acquired by MEM tokens.</p><h3>III. Eternal Memories (Afterlife)</h3><p>Each memorial contains information about the loved ones, mementos, space for family to upload media to IPFS (decentralized file storage), an area for family and friends to give condolences, and a public museum view in an interactive setting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2_53Tzgr6_2mxhL8.png" /></figure><p>In addition, we plan to link memorials together to create a cohesive family history and the community can make proposals to add in other features such as donations, semi-private access to view family history information and linking a person’s NFT art in the museum.</p><p>Ultimately, we want the community to shape the direction of the project through an easy to use governance interface.</p><p>We’re excited to see what ideas the community can bring. The possibilities are unlimited as is this journey called life, where legends never die.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*57l2lDs8eRbGfS2i.png" /></figure><blockquote><em>Death (that ever-present event/condition) is not well-represented or ‘generally present’ in the design of public infrastructure, digital or physical or otherwise. Most people’s present infrastructural relationship with death manifests in the form of footnotes, legalese, buried settings menu options, and other similarly sidelined representations. As further ecological instability sets off increasingly vast die-offs, infrastructure will evolve to better present and make use of death.</em></blockquote><p>– Edouard Urcades via <a href="https://subpixel.space/entries/premonition/">https://subpixel.space/entries/premonition/</a></p><p><strong>Oct 26, 2020 — We now have a full working demo below. Please let us know what you think!</strong></p><h4>Live Demo (on MATIC network)</h4><p><a href="http://memorial.network/">http://memorial.network/</a></p><h4>How to connect to MATIC network</h4><p>To get a memorial and try for yourself, please update your Metamask to point to the Matic Mumbai network:</p><ul><li>Configure Metamask and click on Network -&gt; Custom RPC, then enter the following:</li></ul><p>– Network Name: Mumbai Matic<br>– RPC URL: <a href="https://rpc-mumbai.matic.today/">https://rpc-mumbai.matic.today</a><br>– ChainID: 80001<br>– Symbol: MATIC<br>– Block Explorer URL: <a href="https://mumbai-explorer.matic.today/">https://mumbai-explorer.matic.today</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*1hh7n7bBgbIeOoWK.png" /></figure><ul><li>Then please go to the Matic faucet site (<a href="https://faucet.matic.network/">https://faucet.matic.network/</a>), then select <em>MATIC Token</em> and <em>Mumbai</em> to give yourself some test tokens. 0.01 will be plenty to get you started!</li></ul><h4><strong>Demo Video</strong></h4><p><a href="https://youtu.be/CcAaVFI-mj4">https://youtu.be/CcAaVFI-mj4</a> (6:35)<br>(0:00) — Genesis<br>(0:41) — Demo<br>(1:45) — Getting a Memorial on Matic<br>(3:56) — Uploading media to your Memorial<br>(5:05) — Governance aspect of the project</p><h4>Screenshots</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*t-4ZE91zPoYrI2x7.jpg" /></figure><p><em>homepage</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iXasHWYnCrdeC-Ph.png" /></figure><p><em>level detail</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mS_5D3wR381Q56Ut.jpg" /></figure><p><em>memorial prototype</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jEp3d_tvrcxX2_iZ.jpg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eLxEpjnlhoteJBhV.jpg" /></figure><p><em>memorial activation</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*htT2tESQcnyF2tr-.jpg" /></figure><p><em>media upload to memorial</em></p><h4>Contracts</h4><p>ERC-721 MEM NFT Contract<br><a href="https://mumbai-explorer.matic.today/address/0x0bc52d5cf4ca0ce83bf9caffa07446c9f5740dc6">https://mumbai-explorer.matic.today/address/0x0bc52d5cf4ca0ce83bf9caffa07446c9f5740dc6</a><br>ERC-20 MEM Token Contract<br><a href="https://mumbai-explorer.matic.today/address/0x9d48fe75dbdc2ef5fca78eea85252d2bef5eb399">https://mumbai-explorer.matic.today/address/0x9d48fe75dbdc2ef5fca78eea85252d2bef5eb399</a><br>Memorial Activation Contract<br><a href="https://mumbai-explorer.matic.today/address/0x00878301852F13A83A32e0D99436C3222997d709">https://mumbai-explorer.matic.today/address/0x00878301852F13A83A32e0D99436C3222997d709</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61f440627b98" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ocean Hackathon Journal #3]]></title>
            <link>https://tommychan.medium.com/ocean-hackathon-journal-3-5edbb4ce3e09?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/5edbb4ce3e09</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ocean-protocol]]></category>
            <category><![CDATA[hackathons]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Wed, 15 Jan 2020 19:22:30 GMT</pubDate>
            <atom:updated>2020-01-16T16:30:32.362Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this multipart series, I will attempt to document all the things related to building the project submission for the </em><a href="https://docs.oceanprotocol.com/concepts/introduction/"><em>Ocean Protocol</em></a><em> Challenge</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8uQmec84VF5-8Kas.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*NViZl2AIgZ4GasQS" /></figure><h3><strong>A Quick Recap</strong></h3><p>If you missed parts 1 + 2, here are the links to it:</p><ul><li><a href="https://medium.com/@tommychan/ocean-hackathon-journal-1-1cb4b37bcab6">Ocean Hackathon Journal #1</a></li><li><a href="https://medium.com/@tommychan/ocean-hackathon-journal-2-bd03629e24c7">Ocean Hackathon Journal #2</a></li></ul><h3>The Final Product</h3><p>I was able to finish the Chrome extension by incorporating it to automatically pop out on Kaggle and Google Dataset search website. We submitted to the Google Chrome Webstore for review (they said it will take up to 30 days to complete). For a demo of how it looks like, please check out the demo video below!</p><p>If you would like to download the extension and give it a try, please download this zip file, then extract it to a location. Then open Chrome, and navigate to chrome://extensions, turn on <strong>Developer Mode</strong>, and click on <strong>Load Unpacked Extension</strong> to load it into your browser!</p><p><a href="https://s3-us-west-2.amazonaws.com/acf-uploads/ocean-discover-1.0.2.zip">https://s3-us-west-2.amazonaws.com/acf-uploads/ocean-discover-1.0.2.zip</a></p><h3>Final Screenshots</h3><figure><img alt="Chrome Discovery automatically showing up when a user searches for a search term on Google Dataset Search" src="https://cdn-images-1.medium.com/max/1024/1*s2JrtopH-PueQoEs-X7VjQ.png" /></figure><figure><img alt="Chrome Discovery automatically showing up when a user searches for a search term on Kaggle" src="https://cdn-images-1.medium.com/max/1024/1*H_t0v4vws2WPa36Js8ar6g.png" /></figure><p>Demo Video</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fr9O2j0hW2U0%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dr9O2j0hW2U0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fr9O2j0hW2U0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8c4657aea8cfdb5f98cb810da7f5f18d/href">https://medium.com/media/8c4657aea8cfdb5f98cb810da7f5f18d/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5edbb4ce3e09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ocean Hackathon Journal #2]]></title>
            <link>https://tommychan.medium.com/ocean-hackathon-journal-2-bd03629e24c7?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/bd03629e24c7</guid>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[ocean-protocol]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Tue, 24 Dec 2019 05:41:01 GMT</pubDate>
            <atom:updated>2020-01-16T16:30:12.444Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this multipart series, I will attempt to document all the things related to building the project submission for the Ocean Protocol Challenge</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*r7wo30mcMpN3hiG_.png" /></figure><h3>A Quick Note</h3><p>This is an update to the last article regarding the idea of a Chrome extension that enables automatic searching on <a href="https://docs.oceanprotocol.com/concepts/introduction/">Ocean protocol</a> powered<a href="https://docs.oceanprotocol.com/concepts/architecture/"> data marketplaces</a> whenever someone is searching for a data set they need for their purpose. To read more about the motivation of this, please click below:</p><p><a href="https://medium.com/@tommychan/ocean-hackathon-journal-1-1cb4b37bcab6">Ocean Hackathon Journal #1</a></p><h3>Progress Since the Last Update</h3><p>The Chrome extension development is in full swing. In this update I will describe some of the progress made so far and also provide some screenshots how it looks (exciting!)</p><p>The idea that the data scientist shouldn’t have to go to multiple data sources to search for datasets is the core premium of why I started to build this Chrome extension. Similarly to the <a href="https://chrome.google.com/webstore/detail/amazon-assistant-for-chro/pbjikboenpfhbbejgkoklgkhjpfogcam?hl=en">Amazon</a> or the <a href="https://chrome.google.com/webstore/detail/honey/bmnlcjabgnpnenekpadlanbbkooimhnj?hl=en">Honey</a> extension, this Chrome extension should sit in the background, looking for deals and discounts for you whenever you are browsing for a product online. Instead of hunting of discounts however, Ocean Discovery Chrome extension will connect to Ocean powered data marketplaces to look for datasets that the user is searching for while on Dataset source sites.</p><h3>Bootstrapping Growth For Ocean Protocol</h3><p>Airbnb started their growth by using Craigslist and promoting their Airbnb listings on the popular classified site when they started (which contributed to their early success). By embedding the search functionality into sites that currently provide datasets, the largest 2 being <a href="https://toolbox.google.com/datasetsearch">Google Dataset Search</a> and <a href="https://www.kaggle.com/">Kaggle</a>, the hope is that we can generate growth the same way for Ocean within the data science community.</p><h3>Progress report</h3><p>The first thing I did was create the info page when someone clicks on the Chrome extension so that I can provide some information as to how to activate the extension. I’m happy to announce that this is done:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*sGRYxrRSlru3skLj5ZN0cg.png" /><figcaption>The introduction screen for the Chrome extension</figcaption></figure><p>The idea for the extension is that it will integrate with <strong>all of the data marketplaces pertaining to machine learning data sets when they come online</strong>. Currently it only has one marketplace (Commons Marketplace) but the idea is the OCEAN will host many more marketplaces since they are just the protocol and can have many implementors. For a quick overview of the key concepts, have a look over here: <a href="https://docs.oceanprotocol.com/concepts/terminology/">https://docs.oceanprotocol.com/concepts/terminology/</a></p><p>I’m excited to announce that I’ve finished the integration with the Aquarius server to get the metadata from the Commons Marketplace. With this in place, it’s a matter of querying the Aquarius API for the information regarding the search terms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*To9yqROni4zHc2iMWlPS9g.png" /><figcaption>Sample response from the Aquarius API for the Commons marketplace</figcaption></figure><p>So far I’m happy with the progress and I’m hoping to continue the momentum next week — hopefully the stuff turkey and my stomach acids won’t get in my way as Christmas is around the corner :p</p><h3>Update</h3><p>For the final article in the series, please click below:</p><p><a href="https://medium.com/@tommychan/ocean-hackathon-journal-3-5edbb4ce3e09">Ocean Hackathon Journal #3</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd03629e24c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ocean Hackathon Journal #1]]></title>
            <link>https://tommychan.medium.com/ocean-hackathon-journal-1-1cb4b37bcab6?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cb4b37bcab6</guid>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[hackathons]]></category>
            <category><![CDATA[ocean-protocol]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Sun, 22 Dec 2019 05:37:39 GMT</pubDate>
            <atom:updated>2020-01-16T16:29:26.764Z</atom:updated>
            <content:encoded><![CDATA[<p><em>In this multipart series, I will attempt to document all the things related to building the project submission for the Ocean Protocol Challenge</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*MkI6uyj6mHLwk7DG.png" /></figure><h3>Introduction</h3><p>I just recently heard of the <a href="https://oceanprotocol.com/">Ocean Protocol</a> Hackathon on Devpost. As a blockchain enthusiast I’m always on the look out for innovative projects. I will admit, prior to hearing about the hackathon on Devpost, I didn’t know about Ocean. After I read through the whitepaper and the core concepts, I’m glad this project and hackathon exists. I was talking to a friend who is also a data scientist who used to work at Google over dinner one day, and one of our friends asked if Google would ever go away. It was explained to me that Google would not go away any time soon and the reason of that is because of the unfair advantage of all of the data they have about their users. It means that their models are that much better — it means that they can feed their models and gain insight that no other company can. I’m glad that Ocean exists to potentially disrupt this — data is really the next frontier in technology as it is a basis for Machine Learning from the data collection / resource side.</p><h3>Conception of the idea for the Ocean Protocol Hackathon</h3><p>As a data scientist, part of the issue is that you need to have a good quality data set. However, the source of the data currently, as it stands, is very fragmented. It exists on <a href="https://towardsdatascience.com/top-sources-for-machine-learning-datasets-bb6d0dc3378b">various different sites and sources</a> and it takes a lot of time to search for good quality data sets.</p><p>The other potential issue is that as the Ocean protocol becomes more and more popular and there will exist multiple <a href="https://docs.oceanprotocol.com/concepts/components/">data marketplaces</a>, and therefore one could see how a tool to help with the discovery of data sets can help data scientists and the community.</p><h3>The Idea / Solution</h3><p>For building this solution to help with data discovery, I looked to a few popular Chrome extensions for inspiration. For example, one of my favorite extensions is the Amazon extension. One of the more awesome features is the ability to show you the Amazon price while you’re shopping on the web and not just on Amazon:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/1*bMDL5BM9CIQEI8Il9OgBVA.png" /><figcaption>One of my favorite Chrome extensions — it shows you the Amazon price when you’re shopping on other sites</figcaption></figure><p>So I had an idea — what if there was a Chrome extension that automatically displays any related datasets while a user is on one of the data source websites? This would allow data scientists to automatically see the data sets available on the Ocean protocol while browsing sites that provide data sets. It would automatically pop up whenever a user is searching for a data set and display the results (if any) from any Ocean protocol metadata datasets.</p><h3>The Build Plan</h3><p>The idea is to build a Chrome extension that will activate on certain websites — websites specifically that data scientists go to find data sources. In addition, when a user is on an Ocean protocol enabled marketplace website and performs a search, it will also search other Ocean protocol enabled websites and return the results automatically.</p><p>The initial version of the Chrome extension will include a list of the sites that will auto populate the search on and a list of all the marketplaces that it searches on. As more marketplaces come online, that list will update.</p><p>Because all the marketplaces are implemented with Aquarius for the metadata (<a href="https://github.com/oceanprotocol/aquarius">https://github.com/oceanprotocol/aquarius</a>), we can ensure that the data looks unified for all of the data marketplaces as they come online. Thus we will code the response based on the API of Aquarius.</p><h3>Stay Tuned</h3><p>Please stay tuned for another update as I code this baby over some Red Bulls ;)</p><h3>Update</h3><p>For part 2 of the series, please click below:</p><p><a href="https://medium.com/@tommychan/ocean-hackathon-journal-2-bd03629e24c7">Ocean Hackathon Journal #2</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cb4b37bcab6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Experience with the KIN blockchain]]></title>
            <link>https://tommychan.medium.com/experience-with-the-kin-blockchain-a40df29f5207?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/a40df29f5207</guid>
            <category><![CDATA[kin]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Mon, 14 Oct 2019 17:23:27 GMT</pubDate>
            <atom:updated>2019-10-17T17:32:47.720Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*pszw45-RswNZCszqrYOLiw.png" /></figure><h3>Introduction</h3><p>Blockchain technology and cryptocurrencies will change the future of banking, finance, payments and many other sectors. Many initial early adopters of cryptocurrencies have tried to learn by purchasing crypto. However, buying and trading crypto can be risky as the market is volatile and this is a brand new asset class. There’s also a lot of noise online about crypto and it can be hard to determine which sources of info are legitimate and trustworthy. Newcomers to crypto risk losing money if they don’t have a good gateway in and the industry risks losing adoption if most people have a bad initial experience using crypto.</p><p>This is why we built Altcoin Fantasy. We are a trusted educational platform that uses gamification to drive continuous learning, engagement and to keep people coming back. We teach people about crypto and crypto trading through fantasy trading competitions where they compete against other people worldwide to win real crypto prizes. We’ve combined the excitement, thrill and fun of fantasy sports, drawing upon the huge fan base, with crypto trading and rewards. It’s completely free to use and there’s no risk of losing money. There’s only gains and no losses in the Altcoin Fantasy world. We launched in 2018 and have helped over 150k users onboard to the world of cryptocurrencies.</p><h3>What is the KIN ecosystem?</h3><p>Kin is a blockchain project that aims to create mass adoption via growing an ecosystem of applications that reward users to perform certain actions and allows users to use Kin as in app currency for various games and apps.</p><h3>How we leverage KIN at Altcoin Fantasy</h3><p>With the KIN integration, we added the ability for players to challenge other players to a duel using KIN to drive social engagement and the adoption of KIN. We added a daily free KIN reward redemption that players could redeem. Using the daily free KIN (100 KIN), they could then challenge another player to a 1 vs 1 battle where the winner would take the entire entry fee of 200 KIN as the prize pool if they were the winner. Participants have 12 hours to make the best trades and the player with the highest gains in their portfolio at the end of the competition wins.</p><p>In addition, we also allow users to tip one another if they like the performance of the user or if they like the choice of the trades the user have made.</p><p>Currently we act as the custodian for the tokens during a contest, and we award to the winner the tokens after the contest ends.</p><h3>Our experience with KIN</h3><p>The developer experience has been nothing short but excellent. There was more than adequate documentation (unlike a lot of other blockchain projects). The transaction model of KIN and the federated whitelist approach were some key takeaways. We launched a version of our app with the KIN integration earlier this week and we’ve seen over 1500 transactions done by our users thus far, so we’ve excited to see what the long term results are like.</p><p>KIN also offers developers a programme where they can get KIN tokens called the KRE. The KRE is a programme that we’re interested in moving forward with. We plan to use the proceeds of the KRE to engage our users to come back daily by distributing free daily KIN tokens. We also want to encourage more education and awareness and will be doing some fun educational quizzes which we will reward users with KIN for participating in them and learning about different projects/concepts in the blockchain/crypto space.</p><p>Download our app now and start your onboarding journey to crypto! <a href="https://play.google.com/store/apps/dev?id=7945832009254917927&amp;hl=en">https://play.google.com/store/apps/dev?id=7945832009254917927&amp;hl=en</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a40df29f5207" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interfacing with the Kin Android SDK using Kotlin]]></title>
            <link>https://tommychan.medium.com/interfacing-with-the-kin-android-sdk-using-kotlin-988e7fe716cd?source=rss-e7c0f498f7a4------2</link>
            <guid isPermaLink="false">https://medium.com/p/988e7fe716cd</guid>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Tommy Chan]]></dc:creator>
            <pubDate>Mon, 14 Oct 2019 06:27:38 GMT</pubDate>
            <atom:updated>2019-11-04T17:49:12.581Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>For those of you who don’t Kin, Kin is a token project that aims to create an ecosystem where the users and the app creators engage in a new way to grow and monetize the digital community. As a developer, it’s meaningful to have additional revenue sources other than from ads and in app purchases. By incorporating the Kin Android SDK, app developers can encourage the usage of the Kin token and in return get rewarded for doing so. For those of you that want to learn more about the rewards system, please go to <a href="https://www.kin.org/kre">https://www.kin.org/kre</a></p><p>We recently integrated our app with the Kin SDK for the 2019 Kin Crypto Challenge and thought we would share our experience.</p><p>The purpose of this article is to explain how one can interface with the Kin Android SDK to perform the various functions. Kin developers do a good job on describing the set up and usage of the SDK in Java — however Kotlin is the defacto language that Google wants their developers to use going forward, so this tutorial will go over how one would use Kotlin to interface with the SDK</p><p>This tutorial assumes you have read through Kin’s tutorials. Luc at Kin has written an in depth tutorial on how to build an Android app from the ground up, including the source code, at <a href="https://medium.com/kinblog/tagged/app-development">https://medium.com/kinblog/tagged/app-development</a>.</p><p>I will mainly describe the changes we needed to make which differ from the tutorial in order to support Kotlin.</p><h3>The Main Client Functions</h3><p>In our application, there are 2 main use cases that we use— get balance, and send a payment to another wallet. I will describe how we use these functions using Kotlin.</p><h4>Querying balance</h4><p>One of the major benefits that Kotlin provides is being able to natively pass in closures. One could argue that in Java we can pass in objects that has a callback method. That’s true — however, from a readability perspective, Kotlin comes ahead.</p><p>For example, take a look at the following example on how easy it is to query the balance and display it in the app:</p><pre>getAndUpdateBalance <strong>{<br>  </strong>points_text.<em>text </em>= <strong>it</strong>.toString()<br><strong>}</strong></pre><p>In this case, we pass in a closure to the getAndUpdateBalance and when the SDK is done query the blockchain, we just use the variable it to reference the result (which is a BigDecimal).</p><p>Kotlin for Android adds some syntactic sugar as well, so you can set the text of a TextView super easily (instead of calling findViewById(R.id.points_text), we just use points_text.</p><p>So what does the function getAndUpdateBalance look like? It looks like this:</p><pre><strong>protected fun </strong>getAndUpdateBalance(onDone: (BigDecimal) -&gt; Unit) {<br>  <strong>try </strong>{<br>    <strong>if </strong>(!<strong>kinClient</strong>.hasAccount()) {<br>      onboardAndGetAccountInfo(<strong>kinClient</strong>.addAccount(), onDone)<br>    } <strong>else </strong>{<br>      getAccountInfo(<strong>kinClient</strong>.getAccount(0), onDone)<br>    }<br>  } <strong>catch </strong>(e: CreateAccountException) {<br>    e.printStackTrace()<br>  }<br>}</pre><p>The above logic encapsulates the creation of the blockchain account, which is a different procedure than if you already have an account. This method encapsulates the logic so the call doesn’t have to worry about how the account is created.</p><p>For brevity I won’t get into the methods of onboardAndGetAccountInfo and getAccountInfo, but essentially they call the SDK and get the relevant information. However, what is interesting is that the function calls the onDone closure and it passes in the value that it retrieved (in this case a BigDecimal).</p><h4>Whitelisting Transactions</h4><p>The other operation that we needed to do was to pay for a challenge, and this involves first calling our backend server to whitelist (or sign) a transaction, then the client gets the payload from the server, and calls the SDK with that payload to commit the transaction to the blockchain. After the transaction is committed, we send the tx_id back to the server to verify that the spending has happened. As you can see, one can imagine that this is quite asynchronous and the Java way requires creating a few callback classes. That works, but it feels a bit clunky.</p><p>How might one implement this in Kotlin?</p><pre>whitelistTx(<strong>CONTEST_COST</strong>) <strong>{ </strong>txId, uuid <strong>-&gt;</strong><br>  <strong>service</strong>.kinAcceptChallenge(KinAcceptBody(id, txId, uuid)).enqueue(<strong>object </strong>: Callback&lt;JoinContestResponse&gt; {<br>    <strong>override fun </strong>onResponse(call: Call&lt;JoinContestResponse&gt;, response: Response&lt;JoinContestResponse&gt;) {<br>      handleResponse(response, <strong>{}</strong>) <strong>{<br></strong>        success(R.string.<em>successfully_accepted_challenge</em>)<br>        <strong>val </strong>intent = Intent(<strong>this</strong>, ContestActivity::<strong>class</strong>.<em>java</em>)<br>        <strong>val </strong>body = response.body()<br>        intent.putExtra(ContestActivity.IntentParams.<strong>USER_CONTEST_ID</strong>, body?.<strong>user_contest_id</strong>)<br>        startActivity(intent);<br>      <strong>}<br>    </strong>}<br><br>    <strong>override fun </strong>onFailure(call: Call&lt;JoinContestResponse&gt;, t: Throwable) {<br>      failed(getString(R.string.<em>error_generic</em>))<br>    }<br>  })<br><strong>}</strong></pre><p>This example seems a little bit more complicated, but the logic is essentially the same. We first call whitelistTx which builds a transaction on the Kin SDK, and then sends it to our backend server. The backend server returns tx_envelope and an uuid at this point. Then the client uses the tx_envelope to interface with the Kin SDK. If this is successful, it will call our closure above, which then calls service.kinAcceptChallenge while passing in the tx_id and the uuid. The reasons we need to pass in a uuid to the backend server is to ensure that we mark that initial envelop request as done. If not, users can just keep calling the endpoint without any repercussions (see Luc’s article about why this is important: <a href="https://medium.com/kinblog/kin-android-development-tutorial-part-9-secure-communication-between-backend-and-app-for-32d467a54a64">https://medium.com/kinblog/kin-android-development-tutorial-part-9-secure-communication-between-backend-and-app-for-32d467a54a64</a>)</p><p>The body of the whitelistTx method:</p><pre><strong>protected fun </strong>whitelistTx(amount: Double, onSuccess: (String, String) -&gt; Unit?) {<br>  <strong>val </strong>account = <strong>kinClient</strong>.getAccount(0)<br>  <strong>val </strong>buildTransactionRequest = account.buildTransaction(BuildConfig.<em>KIN_PUB_ADDR</em>, BigDecimal(amount.toString()), 0)<br>  buildTransactionRequest.run(<strong>object </strong>: ResultCallback&lt;Transaction&gt; {<br>    <strong>override fun </strong>onResult(transaction: Transaction) {<br>      <strong>service</strong>.kinWhitelistTx(KinWhitelistTxBody(transaction.<em>whitelistableTransaction</em>.<em>networkPassphrase</em>, transaction.<em>whitelistableTransaction</em>.<em>transactionPayload</em>, amount, account.<em>publicAddress</em>!!)).enqueue(<strong>object </strong>: Callback&lt;WhitelistTxResponse&gt; {<br>        <strong>override fun </strong>onResponse(call: Call&lt;WhitelistTxResponse&gt;, entity: Response&lt;WhitelistTxResponse&gt;) {<br>          handleResponse(entity, <strong>{}</strong>) <strong>{<br>            val </strong>body = entity.body()<br>            account.sendWhitelistTransaction(body.<strong>tx_envelope</strong>).run(<strong>object </strong>: ResultCallback&lt;TransactionId&gt; {<br>              <strong>override fun </strong>onResult(result: TransactionId?) {<br>                onSuccess(result?.id(), body?.<strong>uuid</strong>!!)<br>              }<br>              <strong>override fun </strong>onError(e: java.lang.Exception?) {<br>                Crashlytics.logException(e)<br>                failed(<strong>&quot;Unable to execute transaction. Please ensure you have enough Kin in your account to perform this action.&quot;</strong>)<br>              }<br>            })<br>          <strong>}<br>        </strong>}<br>      })<br>    }<br>  })<br>}</pre><p>Here we interlace calling our backend server and calling the SDK (to whitelist the transaction) and encapsulate this in closures which are called when the server or the SDK is done processing.</p><p>Now if you’re the type of person that prioritize readability over anything else, one can end up writing the code above to something like:</p><pre><strong>protected fun </strong>whitelistTx(amount: Double, onSuccess: (String, String) -&gt; Unit?) {<br>  buildTx(amount) <strong>{ </strong>passPhrase, payload <strong>-&gt;<br>    </strong>backendWhitelistTx(passPhrase, payload, amount) <strong>{ </strong>uuid, envelope <strong>-&gt;<br>      </strong>createWhitelistedTx(envelope) <strong>{ </strong>txId, uuid<br>        onSuccess(txId, uuid)<br>      <strong>}<br>    }<br>  }<br></strong>}</pre><p>I hope this convinces you that writing in Kotlin is much easier in terms to readability and that translates to better code maintainability!</p><h3>BONUS: Dependency Injection</h3><p>In the Android SDK tutorials, the KinClient object is instantiated in the Application class. While is this is a fine approach, the better approach could be to use dependency injection (aka DI) to inject the KinClient which then ensures your application is using the same instance. While under development we discovered a memory leak issue and that was due to the fact that we had multiple instance of the KinClient. By using DI, you can be guaranteed that instance you get is the same singleton instance. There are a few frameworks for DI for Kotlin, but my favorite is a library call Kodein. Kodein works with Android apps and setting up the KinClient that can be injected throughout the app is as easy as declaring this on your Application object:</p><pre><em>bind</em>&lt;KinClient&gt;() with <em>singleton </em><strong>{ </strong>KinClient(<em>instance</em>(), Environment.<em>PRODUCTION</em>, <strong>&quot;&lt;your app id&gt;&quot;</strong>) <strong>}</strong></pre><p>And then use it in your Activity, simply declare a variable like this inside your Activity:</p><pre><strong>protected val kinClient</strong>: KinClient <strong>by </strong><em>instance</em>() </pre><p>Wow was that easy or what? Now the kinClient can be used. No instantiation, nothing. To learn more about Kodein, please visit <a href="https://github.com/Kodein-Framework/Kodein-DI">https://github.com/Kodein-Framework/Kodein-DI</a></p><p>So that’s a wrap! I hope you learned something today. If you want to see the app in action, please visit <a href="https://play.google.com/store/apps/details?id=com.altcoinfantasy.altcoinfantasy&amp;hl=en_US">https://play.google.com/store/apps/details?id=com.altcoinfantasy.altcoinfantasy&amp;hl=en_US</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=988e7fe716cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>