<?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 Cyrille on Medium]]></title>
        <description><![CDATA[Stories by Cyrille on Medium]]></description>
        <link>https://medium.com/@cyri113?source=rss-be00b7b3f8e5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*I_Rr6-Mye9hKlEPvD1KVqw.png</url>
            <title>Stories by Cyrille on Medium</title>
            <link>https://medium.com/@cyri113?source=rss-be00b7b3f8e5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 02:36:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cyri113/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[Cross-chain Interoperability: what does it mean for the average DeFi user]]></title>
            <link>https://medium.com/@cyri113/cross-chain-interoperability-what-does-it-mean-for-the-average-defi-user-e7797f5f6396?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7797f5f6396</guid>
            <category><![CDATA[crosschain]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[defi]]></category>
            <category><![CDATA[interoperability]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Wed, 24 May 2023 16:40:05 GMT</pubDate>
            <atom:updated>2023-05-24T16:40:05.508Z</atom:updated>
            <content:encoded><![CDATA[<p>In the rapidly evolving landscape of decentralized finance (DeFi), one term that has gained significant attention is <strong>cross-chain interoperability</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YPzxT3LvTEU3SB6B" /><figcaption>Photo by <a href="https://unsplash.com/@theshubhamdhage?utm_source=medium&amp;utm_medium=referral">Shubham Dhage</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Today, I listened to a <a href="https://twitter.com/i/spaces/1vOxwMaDylEGB?s=20">Blueshift Twitter Spaces AMA</a>. The <a href="https://blueshift.fi/">Blueshift</a> Team alongside the <a href="https://www.dcspark.io/">dcSparks</a> (<a href="https://www.milkomeda.com/">Milkomeda</a>, <a href="https://flint-wallet.com/">Flint</a>, etc.) discussed their updates and cross-chain L2. I invite you to go back in and listen to it.</p><p>Following the AMA, I thought it would be useful to write an article discussing how cross-chain interoperability was going to impact the average DeFi user.</p><h3>Interoperability</h3><p>Interoperability refers to the ability of different blockchain networks, platforms, and protocols to seamlessly communicate, interact, and share data with each other. It is a concept that holds immense potential for the average DeFi user and has the power to revolutionize the way we engage with decentralized finance.</p><p>At its core, interoperability breaks down the barriers that exist between various blockchain ecosystems, enabling them to work together harmoniously. Currently, the DeFi space is highly fragmented, with different projects and platforms operating on separate blockchains or using incompatible protocols. This fragmentation hampers the efficiency and usability of DeFi applications, limiting their reach and potential impact. Interoperability aims to bridge these gaps and create a unified DeFi ecosystem that offers seamless user experiences and expanded functionality.</p><p>For the average DeFi user, interoperability brings a multitude of benefits. Let’s explore some of the key advantages:</p><h4>Enhanced Access to Financial Services</h4><p>Interoperability opens the door to a broader range of DeFi products and services. Users are no longer limited to a single blockchain or platform but can access a wider array of decentralized applications (dApps), lending platforms, decentralized exchanges (DEXs), and other DeFi services across different networks. This expanded access increases choice and empowers users to find the solutions that best suit their needs.</p><h4>Cross-Chain Asset Transfers</h4><p>One of the most significant advantages of interoperability is the ability to transfer assets seamlessly between different blockchains. Currently, transferring tokens from one blockchain to another can be complex, time-consuming, and costly. Interoperability solutions, such as cross-chain bridges and protocols, simplify this process, allowing users to move their assets across chains with ease. This not only improves liquidity but also enables users to capitalize on opportunities across multiple DeFi ecosystems.</p><h4>Enhanced Liquidity and Market Efficiency</h4><p>Interoperability facilitates the creation of liquidity pools that span multiple blockchains. By combining liquidity from various sources, interoperable DeFi platforms can offer deeper and more liquid markets, which leads to tighter spreads, better pricing, and improved overall market efficiency. This benefits the average DeFi user by providing access to more competitive trading opportunities and reducing slippage.</p><h4>Collaboration and Innovation</h4><p>Interoperability encourages collaboration and innovation within the DeFi space. By enabling projects to integrate and build upon each other’s work, interoperable platforms foster a culture of cooperation and idea sharing. This can lead to developing new and groundbreaking DeFi solutions that were previously impossible in isolated ecosystems. The average DeFi user stands to benefit from these advancements, as they gain access to more sophisticated, secure, and user-friendly applications.</p><h4>Risk Diversification</h4><p>DeFi users often face risks associated with a single blockchain or platform. Interoperability provides an avenue for risk diversification by allowing users to spread their assets and activities across multiple chains. In the event of an issue or exploit on one chain, users can mitigate their losses by holding assets on other chains. This promotes a more resilient and secure DeFi ecosystem.</p><h3>Example Use Case</h3><p>Imagine a user named Alex who stakes MATIC on a Polygon protocol. They discover Blueshift, a platform enabling cross-chain interoperability. Blueshift offers a higher APY for staking MATIC on Algorand. Alex bridges their MATIC to Algorand through Blueshift, increasing their earnings potential and benefiting from cross-chain liquidity and market efficiency. With Blueshift’s interoperability, Alex diversifies their strategy, accesses higher yields, and expands their DeFi portfolio across multiple chains.</p><h3>Conclusion</h3><p>While interoperability presents numerous opportunities for the average DeFi user, it is not without its challenges. Technical complexities, security considerations, and standardization efforts are all factors that need to be addressed to ensure seamless interoperability across different networks. However, projects such as <a href="https://blueshift.fi/">Blueshift</a> and <a href="https://www.milkomeda.com/">Milkomeda</a> are actively working on and deploying solutions, and we are already witnessing significant progress in this area.</p><p>As the DeFi space continues to evolve, interoperability will play a crucial role in shaping its future. By breaking down barriers and fostering collaboration, it empowers the average DeFi user with expanded choices, enhanced liquidity, and increased access to innovative financial services. Interoperability is a key enabler of the decentralized finance revolution, and its benefits are poised to transform the way we interact with and participate in the world of DeFi.</p><h3>About Me</h3><p>I’m Cyrille. I build web2 and web3 products and teams. Depending on the project, I operate as a CTO, product manager, developer, advisor, or investor.</p><p>Follow me on <a href="http://twitter.com/cyri113">Twitter</a> and join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7797f5f6396" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web3: The importance of community in DAO]]></title>
            <link>https://medium.com/@cyri113/web3-the-importance-of-community-in-dao-98862699a7af?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/98862699a7af</guid>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[dao]]></category>
            <category><![CDATA[community]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Fri, 14 Apr 2023 13:00:31 GMT</pubDate>
            <atom:updated>2023-04-14T13:00:31.013Z</atom:updated>
            <content:encoded><![CDATA[<p>The rise of decentralized autonomous organizations (DAOs) is one of the most exciting developments in web3. DAOs are communities that use blockchain technology for governance, where decision-making is distributed among members of the DAO rather than being controlled by a central authority.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-gMzqC12HxoAF92-" /><figcaption>Photo by <a href="https://unsplash.com/@guerrillabuzz?utm_source=medium&amp;utm_medium=referral">GuerrillaBuzz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Essentially, they are digital cooperatives where everyone has a say in the organization’s direction.</p><p>This is an introductory article that describes the key pillars that are essential for both traditional organizations and DAOs to thrive and be successful.</p><h3>The Pillars</h3><p>To thrive and be successful, both traditional organizations and DAOs require certain key pillars: communication, trust, purpose, and engagement.</p><h4>Communication</h4><p>Communication is essential for members to share their thoughts, ideas, and feedback openly and effectively. In a traditional organization, communication often flows from the top down, with leadership dictating the company’s direction and decisions, while in a DAO, communication tends to be more horizontal and decentralized, with decision-making power being distributed among members.</p><h4>Trust</h4><p>Trust is crucial in both types of organizations, with employees or members needing to have confidence in one another and the organization’s leadership. Trust in a traditional organization is often built through formalized procedures and hierarchies, while in a DAO, transparency, accountability, and inclusivity are the key factors that foster trust.</p><h4>Purpose</h4><p>A shared sense of purpose is also essential for both traditional organizations and DAOs. In a traditional organization, the sense of purpose is often dictated by the leadership team, while in a DAO, members have an equal say in the organization’s direction and goals, with the sense of purpose often built through a shared set of values and principles agreed upon by the members.</p><h4>Engagement</h4><p>Finally, engagement is key in both types of organizations. Members need to be encouraged and supported to actively contribute, collaborate, and participate in the community’s growth and development. Engagement in a traditional organization is often built through formalized procedures and incentives, while in a DAO, engagement is often built through a shared sense of ownership and commitment among its members.</p><p>In the coming weeks, I hope to dive deeper into each of these topics, comparing how DAOs and traditional organizations operate and providing ideas and tools to help improve or build a DAO.</p><p>Are you a member of a DAO? I would love to get your thoughts on what makes a successful DAO. Reach out to me on <a href="https://twitter.com/cyri113">Twitter</a>, <a href="https://discordapp.com/users/cr3a1#3713">Discord</a>, or <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=98862699a7af" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Deno Tutorial: Parsing CLI arguments using the yargs library (and without)]]></title>
            <link>https://medium.com/@cyri113/deno-tutorial-parsing-cli-arguments-using-the-yargs-library-and-without-aa8a1bd69a7e?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa8a1bd69a7e</guid>
            <category><![CDATA[yargs]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[deno]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Tue, 11 Apr 2023 11:34:52 GMT</pubDate>
            <atom:updated>2023-04-11T11:34:52.779Z</atom:updated>
            <content:encoded><![CDATA[<p>This tutorial shows you how to parse CLI arguments in a <a href="https://deno.land/">Deno</a> project using the <a href="https://github.com/yargs/yargs">yargs library</a> and also a simpler alternative.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Sygm7Y0FMwI9GSlKtY8gfA.png" /></figure><h3>About Me</h3><p>As a tech creator, I build web2 and web3 products for various industries. I’m experienced in financial services, natural resources, medical tech, and blockchain. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="https://twitter.com/cyri113">Twitter</a> or join my <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a> to brainstorm and build together.</p><h3>Deno</h3><p><a href="https://deno.land/">Deno</a> is a runtime for <a href="https://www.javascript.com/">JavaScript</a> and <a href="https://www.typescriptlang.org/">TypeScript</a> that enables developers to build server-side applications with ease. With Deno, developers can overcome the challenge of managing dependencies and security vulnerabilities that often plague traditional <a href="https://nodejs.org/">Node.js</a> applications. For example, Deno’s built-in security features allow developers to write and execute code in a safe environment without worrying about malicious code execution. This makes it an excellent tool for building secure and scalable applications quickly and efficiently.</p><p>Overall, Deno is an exciting new tool for developers that has the potential to revolutionize the way we build and deploy applications.</p><p><a href="https://deno.land/">Deno</a> is used by companies such as <a href="https://slack.com/">Slack</a>, <a href="https://www.netlify.com/">Netlify</a>, <a href="https://github.com/">Github</a>, and <a href="https://supabase.com/">Supabase</a>.</p><h3>Yargs</h3><p><a href="https://github.com/yargs/yargs">Yargs</a> is a powerful and user-friendly command-line parser for Node.js, making it easy for developers to build complex CLI applications. With Yargs, developers can overcome the challenge of writing and managing their own parser for command-line arguments, options, and subcommands. The library provides a wide range of features and customization options, including support for commands with different arguments, options with aliases and defaults, and automatically generated help documentation. For example, developers can use Yargs to build a command-line interface for their application that includes multiple subcommands, each with its own options and arguments, without having to worry about the complexity of parsing and validating user input. Overall, Yargs is a must-have library for any developer building CLI applications, as it greatly simplifies parsing and managing command-line input.</p><h3>Topic Covered</h3><ul><li>Setting up a Deno project</li><li>Using the yargs library</li><li>Using Deno.args</li></ul><h3>Setting up a Deno project</h3><p>I recommend you install Deno by following the <a href="https://deno.land/manual@v1.32.3/getting_started/installation">Deno Installation Guide</a>.</p><p>When it comes to the environment, I use <a href="https://code.visualstudio.com/">Visual Studio Code</a>. There is an official extension for <a href="https://code.visualstudio.com/">Visual Studio Code</a> called <a href="https://marketplace.visualstudio.com/items?itemName=denoland.vscode-deno">vscode_deno</a>. It will connect to the language server built into the Deno CLI when installed.</p><p>Once installed, create the file .vscode/settings.json in your directory.</p><pre>{<br>  &quot;deno.enable&quot;: true<br>}</pre><p>For our example, this will suffice, but if you want more information can be found in the <a href="https://deno.land/manual@v1.32.3/references/vscode_deno">Using Visual Studio Code</a> section of the Deno manual.</p><h3>Using the yargs library</h3><p>Our application will take an input argument from the CLI. We will call this argument walletAddress and modify our file, adding the yargs library.</p><p>Let&#39;s start by creating a file src/index.ts</p><pre>console.log(&#39;Hello, world!&#39;)</pre><p>Now, if we run the command:</p><pre>deno run src/index.ts<br>Hello, world!</pre><p>That is a great first step, our typescript application is running. No extra compilation or commands are required, go Deno!</p><p>The way <a href="https://deno.land/manual@v1.32.3/basics/modules">libraries are imported in Deno</a> is similar, but different to regular Node.js projects. We will make use of the Deno CDN to import the yargs library.</p><pre>// We run a remote import of yargs from deno.land<br>import yargs from &#39;https://deno.land/x/yargs/deno.ts&#39;<br>import { Arguments } from &#39;https://deno.land/x/yargs/deno-types.ts&#39;<br><br>const { walletAddress } = yargs(Deno.args)<br>    .command(&#39;* &lt;walletAddress&gt;&#39;, &#39;Inspect a EVM compatible address&#39;, (yargs: any) =&gt; {<br>        return yargs.positional(&#39;walletAddress&#39;, {<br>            describe: &#39;EVM compatible address&#39;,<br>            type: &#39;string&#39;<br>        })<br>    })<br>    .parse()<br><br>console.log(walletAddress)</pre><p>Using yargs we create a command, since it is the default command we use the * character.</p><p>We then add &lt;walletAddress&gt; using &lt; and &gt; signaling that this is required (not optional). We provide a positional for walletAddress and describe it. In our case, initially yargs was converting our walletAddress into a number, in order to avoid this, I force walletAddress to be of type string.</p><p>Finally, we parse the argument. If we run the command, we get:</p><pre>deno run --allow-read src/index.ts 0x6f3a7715e7bF019dFf39798CD649374a1E3855be<br>0x6f3a7715e7bF019dFf39798CD649374a1E3855be</pre><p>Congratulations, you are now reading the walletAddress argument.</p><p>Note: adding --allow-read gives Deno permission to read variables on your computer, if you don’t add this, you will be asked for permission on every command used.</p><h3>Using Deno.args</h3><p>Using the yargs library is great when you need to handle complex inputs. In our case, we are just getting one simple input. Deno comes with an in-built way, Deno.args, for dealing with arguments.</p><p>In our case, we can simplify our file to:</p><pre>const [walletAddress] = Deno.args<br>console.log(walletAddress)</pre><p>This will generate the same output:</p><pre>deno run --allow-read src/index.ts 0x6f3a7715e7bF019dFf39798CD649374a1E3855be<br>0x6f3a7715e7bF019dFf39798CD649374a1E3855be</pre><p>While this is simpler, it also provides less help and error management.</p><p>I hope you enjoyed this tutorial on parsing arguments when running Deno.</p><p>If this article was helpful, join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>! It is a space to discuss new ideas, build projects, and troubleshoot code and business challenges.</p><p>I build web2 and web3 products for a range of industries. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="http://twitter.com/cyri113">Twitter</a>.</p><p>#Deno #Yargs #NodeJs #Typescript</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa8a1bd69a7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Web3 Tutorial: On-chain data using the Ankr API]]></title>
            <link>https://medium.com/@cyri113/web3-tutorial-on-chain-data-using-the-ankr-api-2a645eef8b63?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a645eef8b63</guid>
            <category><![CDATA[web3-development]]></category>
            <category><![CDATA[ankr]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain-development]]></category>
            <category><![CDATA[on-chain-data]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Mon, 10 Apr 2023 10:15:29 GMT</pubDate>
            <atom:updated>2023-04-10T10:21:59.720Z</atom:updated>
            <content:encoded><![CDATA[<p>Unlock the Power of on-chain data with Ankr API: A Step-by-Step Tutorial to Access On-Chain and Cross-Chain Data! Learn how to check your account balance across multiple chains with our beginner-friendly guide.</p><p>Through Ankr, we are able to easily access data from EVM-compatible chains such as Ethereum, Polygon, BNB Smart Chain, Fantom, Avalanche, Arbitrum, and Syscoin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*c1AWxS40x4a3ZhwZ11KLgA.png" /></figure><h3>About Me</h3><p>As a tech creator, I build web2 and web3 products for a range of industries. I’m experienced in financial services, natural resources, medical tech, and blockchain. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="https://twitter.com/cyri113">Twitter</a> or join my <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a> to brainstorm and build together.</p><h3>Topics Covered</h3><ul><li>Create a Next.js app</li><li>Install the <a href="https://www.ankr.com/docs/advanced-api/react-hooks/">Ankr React Hooks</a></li><li>Building Our Component</li><li>Next Steps</li></ul><h3>Tutorial</h3><h4>Creating a Next.js app</h4><p>Let’s create a Next.js app using their scaffold. We will also remove the contents of the global CSS file so that we are not bothered by their CSS.</p><pre>npx create-next-app@latest app --typescript<br>&gt; /src/styles/global.css # clears the contents of the file</pre><h4>Install the <a href="https://www.ankr.com/docs/advanced-api/react-hooks/">Ankr React Hooks</a></h4><p>We will now add the Ankr React Hooks library.</p><pre>yarn add ankr-react</pre><h4>Building Our Component</h4><p>Let’s create a folder /src/pages/account and a file [walletAddress].tsx</p><pre>mkdir src/pages/account<br>touch &quot;src/pages/account/[walletAddress].tsx&quot;</pre><p>We will use the following address in our example.</p><p><a href="https://etherscan.io/address/0x2efb50e952580f4ff32d8d2122853432bbf2e204">0x2eFB50e952580f4ff32D8d2122853432bbF2E204</a></p><p>So our URL path will be:</p><p><a href="http://localhost:3000/account/0x2eFB50e952580f4ff32D8d2122853432bbF2E204">localhost:3000/account/0x2eFB50e952580f4ff32D8d2122853432bbF2E204</a></p><p>Next.js uses <a href="https://nextjs.org/docs/routing/dynamic-routes">Dynamic Routes</a>, which allows us to access the walletAddress argument. Let’s edit our new file /src/pages/account/[walletAddress].tsx</p><pre>import { useRouter } from &quot;next/router&quot;<br><br>export default function AccountBase() {<br><br>    const { query: { walletAddress } } = useRouter()<br><br>    return (<br>        &lt;&gt;<br>            &lt;h1&gt;Wallet Address: {walletAddress}&lt;/h1&gt;<br>        &lt;/&gt;<br>    )<br>}</pre><p>The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C7VODeBuz-I5j5xoXvSxUA.png" /></figure><p>Now, let’s add our react hook that will get the (cross-chain) balances for the address:</p><pre>import { useAccountBalance } from &quot;ankr-react&quot;<br>import { useRouter } from &quot;next/router&quot;<br><br>interface AccountBalancesProps {<br>    walletAddress: string<br>}<br><br>function AccountWallet({ walletAddress }: AccountBalancesProps) {<br>    const { data, error, isLoading } = useAccountBalance({ walletAddress })<br><br>    if (isLoading) {<br>        return &lt;p&gt;Loading...&lt;/p&gt;<br>    } else if (error) {<br>        return &lt;code&gt;{JSON.stringify(error)}&lt;/code&gt;<br>    } else if (data) {<br>        return &lt;code&gt;{JSON.stringify(data)}&lt;/code&gt;<br>    } else {<br>        return &lt;p&gt;Something unexpected happened.&lt;/p&gt;<br>    }<br><br>}<br><br>export default function AccountBase() {<br><br>    const { query: { walletAddress } } = useRouter()<br><br>    if (typeof walletAddress === &#39;string&#39;) {<br>        return &lt;AccountWallet walletAddress={walletAddress} /&gt;<br>    } else {<br>        return &lt;p&gt;No wallet address detected.&lt;/p&gt;<br>    }<br><br>}</pre><p>We will create a sub-component called AccountWallet which takes the walletAddress as an argument. Using typescript, we force it to only accept a string format. In the AccountBase, we create the AccountWallet only if the walletAddress is a string. If it is not detected, we will return a message stating that no wallet address was detected.</p><p>In the AccountWallet component, we will use the useAccountBalance Ankr React hook. At a minimum, it requires walletAddress argument. This will return cross-chain data on the wallet address balance. You can check out the <a href="https://www.ankr.com/docs/advanced-api/query-methods/">Ankr API documentation</a> if you need more details.</p><p>For our example, we use JSON.stringify(data) to convert the JSON data into a string and display the result. I also added some basic ways of handling loading and errors.</p><p>The result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s9IPzHuPhwyz0hTRle8Rpw.png" /></figure><p>This was a small introduction to the power of the Ankr API and how to use it in a React application. The Ankr API allows us to go even further by providing us easy access to transaction history, something which is challenging if you are querying the blockchain directly.</p><p>If this article was helpful, join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>! It is a space to discuss new ideas, build projects, and troubleshoot code and business challenges.</p><p>I build web2 and web3 products for a range of industries. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="http://twitter.com/cyri113">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a645eef8b63" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 2 — User Authentication made easy with Supabase + Next.js]]></title>
            <link>https://medium.com/@cyri113/part-2-user-authentication-made-easy-with-supabase-next-js-cff3e3f2b274?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/cff3e3f2b274</guid>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <category><![CDATA[authentication]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Tue, 04 Apr 2023 16:04:50 GMT</pubDate>
            <atom:updated>2023-04-04T16:09:42.299Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 2 — User Authentication made easy with Supabase + Next.js</h3><p>We’ll show you just how simple it is to get started with Supabase and take your app’s authentication to the next level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbeIdpKlw9TQ68Yue5wlvg.png" /><figcaption>User Authentication with Next.js + Supabase</figcaption></figure><p>Join me on a journey to create a dynamic Next.js web app that will easily run background jobs for Node.js. We’ll be using a powerful combo of <a href="https://nextjs.org/">Next.js</a>, <a href="https://www.inngest.com/">Inngest</a>, <a href="https://supabase.com/">Supabase</a>, and <a href="https://vercel.com/">Vercel</a> to bring your vision to life. Stick around and let’s get started!</p><p>Previous articles from this series:</p><ul><li><a href="https://medium.com/@cyri113/background-jobs-for-node-js-using-next-js-inngest-supabase-and-vercel-e5148d094e3f">Background Jobs for Node.js using Next.js, Inngest, Supabase, and Vercel</a></li><li><a href="https://medium.com/@cyri113/part-1-configuring-and-testing-a-supabase-database-table-and-policies-be677be03ae">Part 1 — Configuring and testing a supabase database table and policies</a></li></ul><h3>About Me</h3><p>As a tech creator, I build web2 and web3 products for a range of industries. I’m experienced in financial services, natural resources, medical tech, and blockchain. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="https://twitter.com/cyri113">Twitter</a> or join my <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a> to brainstorm and build together.</p><h3>Topics Covered</h3><ul><li>Creating a Next.js app</li><li>Housekeeping</li><li>Create .env.local file</li><li>Add supabase sessions</li><li>Creating an authentication wrapper</li></ul><h3>Prerequisites</h3><ul><li><a href="https://medium.com/@cyri113/part-1-configuring-and-testing-a-supabase-database-table-and-policies-be677be03ae">Part 1 — Configuring and testing a supabase database table and policies</a></li></ul><h3>Creating a Next.js app</h3><pre>npx create-next-app@latest app --typescript</pre><p>Give your app a name, and agree to all the default configs.</p><p>Housekeeping</p><h3>Housekeeping</h3><p>Once completed, go ahead and</p><ol><li>Delete the <strong><em>code</em></strong> inside /src/styles/global.css</li><li>Delete the file/src/styles/Home.module.css</li><li>Update the /src/pages/index.tsx with the following</li></ol><pre>import Head from &#39;next/head&#39;<br><br>export default function Home() {<br>  return (<br>    &lt;&gt;<br>      &lt;Head&gt;<br>        &lt;title&gt;Background Jobs&lt;/title&gt;<br>        &lt;meta name=&quot;description&quot; content=&quot;Background Jobs: Next.js + Supabase + Inngest + Vercel&quot; /&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; /&gt;<br>        &lt;link rel=&quot;icon&quot; href=&quot;/favicon.ico&quot; /&gt;<br>      &lt;/Head&gt;<br>      &lt;main&gt;Hello world!&lt;/main&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><h3>Create .env.local file</h3><p>Create the .env.local file and add the following:</p><pre>NEXT_PUBLIC_SUPABASE_URL=http://localhost:54321<br>NEXT_PUBLIC_SUPABASE_ANON_KEY=eyJhb...</pre><h3>Add supabase sessions</h3><p>Let’s create authentication for users. Add supabase helper libraries.</p><pre>yarn add @supabase/supabase-js @supabase/auth-helpers-react @supabase/auth-helpers-nextjs @supabase/auth-ui-react</pre><p>Update/src/pages/_app.tsx with the following code:</p><pre>import &#39;@/styles/globals.css&#39;<br>import type { AppProps } from &#39;next/app&#39;<br>import { createBrowserSupabaseClient } from &#39;@supabase/auth-helpers-nextjs&#39;<br>import { SessionContextProvider } from &#39;@supabase/auth-helpers-react&#39;<br>import { useState } from &#39;react&#39;<br><br>export default function App({ Component, pageProps }: AppProps) {<br>  const [supabase] = useState(() =&gt; createBrowserSupabaseClient())<br>  return (<br>    &lt;SessionContextProvider supabaseClient={supabase} initialSession={pageProps.initialSession}&gt;<br>      &lt;Component {...pageProps} /&gt;<br>    &lt;/SessionContextProvider&gt;<br>  )<br>}</pre><h3>Creating an authentication wrapper</h3><p>Create a file /src/components/auth/AuthWrapper.tsx</p><pre>import { useSession, useSupabaseClient } from &quot;@supabase/auth-helpers-react&quot;<br>import { Auth } from &#39;@supabase/auth-ui-react&#39;<br>import { ThemeSupa } from &quot;@supabase/auth-ui-shared&quot;<br><br>interface AuthWrapperProps {<br>    children: JSX.Element | JSX.Element[]<br>}<br><br>export default function AuthWrapper({ children }: AuthWrapperProps) {<br>  const session = useSession()<br>  const supabase = useSupabaseClient()<br>  <br>  if (session) {<br>    return &lt;&gt;{children}&lt;/&gt;<br>  }<br>  <br>  return (<br>    &lt;&gt;<br>        &lt;Auth supabaseClient={supabase} appearance={{ theme: ThemeSupa }} /&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>The wrapper checks if a session exists, if it does, it returns the children, else it returns the authentication component.</p><p>Update /src/pages/index.tsx</p><pre>import AuthWrapper from &#39;@/components/auth/AuthWrapper&#39;<br>import Head from &#39;next/head&#39;<br><br>export default function Home() {<br>  return (<br>    &lt;&gt;<br>      &lt;Head&gt;<br>        &lt;title&gt;Background Jobs&lt;/title&gt;<br>        &lt;meta name=&quot;description&quot; content=&quot;Background Jobs: Next.js + Supabase + Inngest + Vercel&quot; /&gt;<br>        &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot; /&gt;<br>        &lt;link rel=&quot;icon&quot; href=&quot;/favicon.ico&quot; /&gt;<br>      &lt;/Head&gt;<br>      &lt;main&gt;<br>        &lt;AuthWrapper&gt;<br>          &lt;h1&gt;Authenticated!&lt;/h1&gt;<br>        &lt;/AuthWrapper&gt;<br>      &lt;/main&gt;<br>    &lt;/&gt;<br>  )<br>}</pre><p>Congratulations! You have built a web app that supports authentication powered by Supabase.</p><p><a href="https://github.com/onmychain/background-jobs-inngest-supabase-nextjs-vercel/commit/0436efac10c425c0d288327ba11922b23be7cabf">Code</a>.</p><p>This was part 2 of a <a href="https://medium.com/@cyri113/background-jobs-for-node-js-using-next-js-inngest-supabase-and-vercel-e5148d094e3f">series of articles</a> that will discuss how to use <a href="https://nextjs.org/">Next.js</a>, <a href="https://www.inngest.com/">Inngest</a>, <a href="https://supabase.com/">Supabase</a>, and <a href="https://vercel.com/">Vercel</a> to build a serverless application that runs background jobs.</p><p>In our next session, we will build out our views for our application. Stay tuned!</p><p>If this article was helpful, join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>! It is a space to discuss new ideas, build projects, and troubleshoot code and business challenges.</p><p>I build web2 and web3 products for a range of industries. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="http://twitter.com/cyri113">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cff3e3f2b274" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Part 1 — Configuring and testing a supabase database table and policies]]></title>
            <link>https://medium.com/@cyri113/part-1-configuring-and-testing-a-supabase-database-table-and-policies-be677be03ae?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/be677be03ae</guid>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Tue, 04 Apr 2023 11:38:05 GMT</pubDate>
            <atom:updated>2023-04-04T12:02:31.004Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 1 — Configuring and testing a supabase database table and policies</h3><p>Learn how to set up a Supabase database like a pro! This tutorial is the perfect starting point for mastering the basics, including creating tables, policies, and test cases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TBuytOKogmgNg8I0Jy20AQ.png" /></figure><p>Join me on a journey to create a dynamic Next.js web app that will easily run background jobs for Node.js. We’ll be using a powerful combo of <a href="https://nextjs.org/">Next.js</a>, <a href="https://www.inngest.com/">Inngest</a>, <a href="https://supabase.com/">Supabase</a>, and <a href="https://vercel.com/">Vercel</a> to bring your vision to life. Stick around and let’s get started!</p><h3>About Me</h3><p>As a tech creator, I build web2 and web3 products for a range of industries. I’m experienced in financial services, natural resources, medical tech, and blockchain. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="https://twitter.com/cyri113">Twitter</a> or join my <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a> to brainstorm and build together.</p><h3>Supabase</h3><p>Supabase is an open-source, cloud-based platform for building scalable and secure applications. It simplifies database management, authentication, and APIs with its intuitive interface and pre-built components, including real-time subscription, webhooks, and user management. Supabase’s real-time capabilities enable lightning-fast reactions to database changes, and it seamlessly integrates with popular frameworks and libraries like React, Vue.js, and Next.js. With Supabase, developers can build modern, scalable, and secure applications quickly and efficiently.</p><h3>Topics Covered</h3><ul><li>Configuring Supabase for local development</li><li>Configuring a database table on Supabase</li><li>Testing a database table on Supabase</li><li>Configuring four basic policies on Supabase</li><li>Testing database policies on Supabase</li></ul><h3>Configuring Supabase for local development</h3><p>Running Supabase locally is easy to set up and will enable you to develop and manage your persistence layers (database and storage) in record time.</p><p>First, you will need to create an account on supabase and generate an access token at <a href="https://app.supabase.com/account/tokens">https://app.supabase.com/account/tokens</a>.</p><p>You will also need to have <a href="https://www.docker.com/">docker</a> installed.</p><pre>yarn init<br>yarn add --dev supabase<br>npx supabase login<br>npx supabase init<br>npx supabase start</pre><p>Note: to shutdown supabase, use npx supabase stop</p><p>Once it is started, you should have the following in the Terminal:</p><pre>Started supabase local development setup.<br><br>API URL: http://localhost:54321<br>DB URL: postgresql://postgres:postgres@localhost:54322/postgres<br>Studio URL: http://localhost:54323<br>Inbucket URL: http://localhost:54324<br>JWT secret: super-secret-jwt-token-with-at-least-32-characters-long<br>anon key: eyJhb...<br>service_role key: eyJhb...</pre><h3>Configuring a database table on Supabase</h3><p>We are going to create a table called <strong>images</strong>. Our table will consist of the following attributes:</p><p><em>id</em><strong> </strong>— we will use a UUID for this, I prefer them over integer ids. An id will automatically be generated each time a row is added.</p><p><em>original_path</em> — varchar of the path where the original image is stored.</p><p><em>thumbnail_path</em> — varchar of the path where the thumbnail image is stored.</p><p><em>user_id</em> — a reference to the owner of the row. The user_id will automatically be added at creation.</p><p>Let’s go to the Table Editor at <a href="http://localhost:54323/project/default/editor">http://localhost:54323/project/default/editor</a></p><p>Create a new table with the following inputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*C_0yfDbMORQS0Hd34TwB6A.png" /><figcaption>Supabase table: example configuration</figcaption></figure><p>For the user_id, we will use a foreign key relation. Click on the icon to the right of the name field, and configure the following inputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/441/1*SWZyWy6qpFPP-otTJVR0cw.png" /><figcaption>Supabase Table: configuring user as a foreign key</figcaption></figure><p>Congratulations, you have created your first table in Supabase! Now it’s time to create some policies!</p><h3>Testing a database table on Supabase</h3><p>Create a new file /supabase/tests/database/images.test.sql in the supabase folder and add the following code:</p><pre>begin;<br>select plan(7); -- only one statement to run<br><br>select has_table(&#39;images&#39;);<br><br>select has_column(&#39;images&#39;, &#39;id&#39;);<br>select has_column(&#39;images&#39;, &#39;created_at&#39;);<br>select has_column(&#39;images&#39;, &#39;original_path&#39;);<br>select has_column(&#39;images&#39;, &#39;thumbnail_path&#39;);<br>select has_column(&#39;images&#39;, &#39;user_id&#39;);<br><br>select col_is_pk(&#39;images&#39;, &#39;id&#39;);<br><br>select * from finish();<br>rollback;</pre><p>Run the tests with the command</p><pre>npx supabase test db</pre><p>Expected result:</p><pre>All tests successful.<br>Files=1, Tests=7,  0 wallclock secs ( 0.01 usr  0.00 sys +  0.01 cusr  0.00 csys =  0.02 CPU)<br>Result: PASS</pre><h3>Configuring four basic policies on Supabase</h3><p>We will configure the following four policies for our table:</p><ul><li>Enable read access for all users</li><li>Enable insert for authenticated users only</li><li>Enable update for users based on user id</li><li>Enable delete for users based on user id</li></ul><p>Head over to <a href="http://localhost:54323/project/default/auth/policies">http://localhost:54323/project/default/auth/policies</a> and you should see a reference to our <strong>images</strong> table. Click on the <em>New Policy</em> button on the right side.</p><h4>1. Enable read access for all users</h4><p>Create a new policy and enter the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WUmoU259MHT5Dz51CU5Ihg.png" /><figcaption>Supabase Policy: Enable read access to everyone</figcaption></figure><p>The corresponding SQL statement should be:</p><pre>CREATE POLICY &quot;Enable read access for all users&quot; ON &quot;public&quot;.&quot;images&quot;<br>AS PERMISSIVE FOR SELECT<br>TO public<br>USING (true)</pre><h4>2. Enable insert for authenticated users only</h4><p>Create a new policy and enter the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HvOBah4bcSpqwBmMiijThw.png" /><figcaption>Supabase Policy: Enable insert access for authenticated users only</figcaption></figure><p>The corresponding SQL statement should be:</p><pre>CREATE POLICY &quot;Enable insert for authenticated users only&quot; ON &quot;public&quot;.&quot;images&quot;<br>AS PERMISSIVE FOR INSERT<br>TO authenticated<br><br>WITH CHECK (true)</pre><h4>3. Enable update for users based on user id</h4><p>Create a new policy and enter the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R_PdwbFWf3Y1y3Cdrt25Tw.png" /></figure><p>The corresponding SQL statement should be:</p><pre>CREATE POLICY &quot;Enable update for users based on user id&quot; ON &quot;public&quot;.&quot;images&quot;<br>AS PERMISSIVE FOR UPDATE<br>TO public<br>USING (auth.uid() = user_id)<br>WITH CHECK (auth.uid() = user_id)</pre><h4>4. Enable delete for users based on their user id</h4><p>Create a new policy and enter the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzoEI8cdBx_6oE06e1FoQA.png" /></figure><p>The corresponding SQL statement should be:</p><pre>CREATE POLICY &quot;Enable delete for users based on user id&quot; ON &quot;public&quot;.&quot;images&quot;<br>AS PERMISSIVE FOR DELETE<br>TO public<br>USING (auth.uid() = user_id)</pre><p>Congratulations! You have set up four basic policies for your table. Now let’s test them :)</p><h3>Testing database policies on Supabase</h3><p>Create a new file /supabase/tests/database/images.policies.test.sql in the supabase folder and add the following code:</p><pre>begin;<br>select plan( 1 );<br><br>select policies_are(<br>  &#39;images&#39;,<br>  ARRAY [<br>    &#39;Enable read access for all users&#39;,<br>    &#39;Enable insert for authenticated users only&#39;,<br>    &#39;Enable update for users based on user id&#39;,<br>    &#39;Enable delete for users based on user id&#39;<br>  ]<br>);<br><br>select * from finish();<br>rollback;</pre><p>Run the tests with the command</p><pre>npx supabase test db</pre><p>Expected result:</p><pre>All tests successful.<br>Files=2, Tests=8,  0 wallclock secs ( 0.00 usr  0.00 sys +  0.02 cusr  0.00 csys =  0.02 CPU)<br>Result: PASS</pre><h3>Final Tip</h3><p>Before committing any code, make sure you have a .gitignore file that ignores the node_modules folder.</p><p>The <a href="https://github.com/onmychain/background-jobs-inngest-supabase-nextjs-vercel/commit/aa33c806b83ec032d9732627a8009d4f21670a9e">code if here</a>.</p><p>This was the first part of a <a href="https://medium.com/@cyri113/background-jobs-for-node-js-using-next-js-inngest-supabase-and-vercel-e5148d094e3f">series of articles</a> that will discuss how to use <a href="https://nextjs.org/">Next.js</a>, <a href="https://www.inngest.com/">Inngest</a>, <a href="https://supabase.com/">Supabase</a>, and <a href="https://vercel.com/">Vercel</a> to build a serverless application that runs background jobs.</p><p>In our next session, we will build a Next.js app that uses Supabase to authenticate users. Stay tuned!</p><p>If this article was helpful, join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>! It is a space to discuss new ideas, build projects, and troubleshoot code and business challenges.</p><p>I build web2 and web3 products for a range of industries. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="http://twitter.com/cyri113">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be677be03ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Background Jobs for Node.js using Next.js, Inngest, Supabase, and Vercel]]></title>
            <link>https://medium.com/@cyri113/background-jobs-for-node-js-using-next-js-inngest-supabase-and-vercel-e5148d094e3f?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5148d094e3f</guid>
            <category><![CDATA[nextjs]]></category>
            <category><![CDATA[supabase]]></category>
            <category><![CDATA[inngest]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[vercel]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Mon, 03 Apr 2023 15:01:45 GMT</pubDate>
            <atom:updated>2023-04-04T16:10:54.015Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we’ll walk through building a <a href="https://nextjs.org/">Next.js</a> web app powered by <a href="https://supabase.com/">Supabase</a>, a powerful database and storage solution, and running background jobs using <a href="https://www.inngest.com/">Inngest</a>. We’ll also cover how to deploy your app to <a href="https://vercel.com/">Vercel</a>, a popular serverless platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B3hPHkAEbFFjNjbzyi9iQg.png" /></figure><p>By the end of this tutorial, you’ll have a fully functioning web app that can handle complex data operations and automate background tasks. So let’s get started!</p><h3>About Me</h3><p>As a tech creator, I build web2 and web3 products for a range of industries. I’m experienced in financial services, natural resources, medical tech, and blockchain. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="https://twitter.com/cyri113">Twitter</a> or join my <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a> to brainstorm and build together.</p><h3>Background jobs</h3><p>Background jobs are asynchronous tasks that are executed in the background without disrupting the main thread or blocking the user interface. They are commonly used by developers to improve the user experience of their applications, as well as to handle resource-intensive tasks that would otherwise slow down the application’s performance.</p><p>Here are a few reasons why developers should use background jobs in their applications:</p><ol><li>Improved application responsiveness: By executing tasks in the background, developers can prevent their applications from becoming unresponsive or freezing when executing long-running tasks. This allows users to continue using the application without interruption.</li><li>Better scalability: Background jobs can be distributed across multiple servers or instances, which enables applications to scale up to handle increased demand without negatively impacting performance.</li><li>Reduced server load: Running resource-intensive tasks in the background can reduce the load on the application server, allowing it to handle more requests and improve overall performance.</li></ol><p>Examples of jobs that should be run as a background jobs:</p><ol><li>Image processing: When an application needs to process large image files, it can be time-consuming and resource-intensive. By running image processing tasks in the background, the application can continue to respond to user requests while the images are being processed.</li><li>Email notifications: Sending email notifications can take a few seconds or longer, especially when sending large numbers of messages. By running email notification tasks in the background, the application can continue to handle user requests while notifications are being sent.</li></ol><h3>Overview</h3><p>We will build a web app allowing users to upload + store images. When an image is uploaded, we will run a background job to create a thumbnail version of that image.</p><p>The series will be broken up into several tutorials:</p><ol><li><a href="https://medium.com/@cyri113/part-1-configuring-and-testing-a-supabase-database-table-and-policies-be677be03ae">Part 1 — Configuring and testing a supabase database table and policies</a></li><li><a href="https://medium.com/@cyri113/part-2-user-authentication-made-easy-with-supabase-next-js-cff3e3f2b274">Part 2 — User Authentication made easy with Supabase + Next.js</a></li></ol><h3>Stack</h3><ul><li><a href="https://vercel.com/">Vercel</a> is a platform as a service company.</li><li><a href="https://nextjs.org/">Next.js</a> is a web development framework.</li><li><a href="https://www.inngest.com/">Inngest</a> is a serverless background job as a service.</li><li><a href="https://supabase.com/">Supabase</a> is a database as a service.</li></ul><p><a href="https://github.com/onmychain/background-jobs-inngest-supabase-nextjs-vercel">Full code repo</a>.</p><p>If this article was helpful, join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>! It is a space to discuss new ideas, build projects, and troubleshoot code and business challenges.</p><p>I build web2 and web3 products for a range of industries. I’m a founding member of multiple companies, operating as CTO, product manager, and developer. I use Medium as a way to teach about technology and discuss business challenges beyond tech.</p><p>Follow me on <a href="http://twitter.com/cyri113">Twitter</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5148d094e3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Open Letter: droplets NFT project]]></title>
            <link>https://medium.com/@cyri113/open-letter-droplets-nft-project-e3cac1b92caf?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e3cac1b92caf</guid>
            <category><![CDATA[nft]]></category>
            <category><![CDATA[open-letter]]></category>
            <category><![CDATA[process]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[startup]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 19:25:53 GMT</pubDate>
            <atom:updated>2023-03-15T19:25:53.407Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*G9KBJT1Gi5Iolx2iYwPthg.png" /><figcaption>droplet NFT design concept</figcaption></figure><p>Hey, hey, hey, future droplets community!</p><p>Are you ready to join us on an exciting web3 adventure? We’ve got a project that’s all about exploration, learning, teaching, and most importantly, having fun!</p><p>Our team has been busy writing contracts and building our dapp, and we want to share all the juicy details with you! We want to create something special that’s open to everyone.</p><p>So, what are droplets, you ask? Well, it’s an NFT collection, and users can mint basic NFTs and add traits like eyes, color, and more! And get this — as the traits evolve, you can make your NFTs evolve too! And that’s not all, we’re keeping the use of NFTs open to the community. Think of it as an open API, and our community can build whatever you want on top of it! Let’s see where we can go!</p><p>We’re in phase 1 of the project, and we’re already buzzing with excitement! We’re working on the 2D design concepts, building socials, a landing page, and our dapp!</p><p>But we’re not stopping there! We need your help! We’ve got some amazing ideas for community initiatives, and we’re looking for support. We want to create 3D droplets, a droplet DAO, a space for community-designed traits (think design-to-earn), and even game integrations!</p><p>We’re even thinking about building partnerships with some fantastic brands! How would your droplets look with some Ray-Ban Aviators, Nike Air Force Ones, or a Rolex Submariner?</p><p>So, what are you waiting for? If you like the concept, <a href="https://t.me/+9sp7vMkWBsY5MTk0">join our telegram</a>!</p><p>If you want to contribute and be a part of this epic journey, drop us a message!</p><p>Let’s create something special, Droplets community!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e3cac1b92caf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity Tutorial: Swap Token Fees for ETH]]></title>
            <link>https://coinsbench.com/solidity-tutorial-swap-token-fees-for-eth-f0e27ee0b979?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f0e27ee0b979</guid>
            <category><![CDATA[uniswap]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[token]]></category>
            <category><![CDATA[pancakeswap]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Wed, 15 Mar 2023 10:35:53 GMT</pubDate>
            <atom:updated>2023-03-17T18:33:02.981Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we will build an ERC-20 contract that collects ETH fees on transfers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*R9UCiYHXUEc1WQ0C" /><figcaption>Photo by <a href="https://unsplash.com/@moneyphotos?utm_source=medium&amp;utm_medium=referral">regularguy.eth</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>Many ERC-20 projects rely on token transfers to build up funds for the project. These funds can then be used to pay developers, marketing initiatives, etc.</p><p>Unfortunately, when we collect a fee, that fee is in the ERC-20 token. This makes it difficult to use for outside initiatives.</p><p>In order to minimize this, we can swap the fee collected for ETH within the same transfer. This tutorial will show you how this is done.</p><h3>Test Cases</h3><p>This tutorial will have several test cases:</p><ol><li>Before trading is enabled, transfer fees should be disabled. This allows the project team to configure the contract prior to launch.</li><li>If the sender is the contract itself, it should not apply fees. When we collect fees, we are transferring the tokens to the contract itself. Therefore, when we swap tokens for ETH, the sender is the contract itself. There is no point in applying fees on fees. In order to write an individual test case for this, we would need to have the ability to connect as the token contract, which we don’t. The only way we have to test this is to check on a sell order that the token contract has a balance of zero after.</li><li>We should apply fees on buy orders (when the sender is the pair address), but we should not swap them. Ideally, I would like to, but I tried for hours and kept facing anUniswapV2: TRANSFER_FAILED error. If someone can explain why let me know!</li><li>We should apply fees on sell orders and transfers, and swap any tokens in the contract balance for ETH, sending them to the fee receiver.</li></ol><pre>import { loadFixture } from &quot;@nomicfoundation/hardhat-network-helpers&quot;<br>import { expect } from &quot;chai&quot;<br>import { constants } from &quot;ethers&quot;<br>import { ethers, UniswapV2Deployer } from &quot;hardhat&quot;<br><br>interface Fixture {<br>    token: any<br>    deployer: any<br>    account: any<br>    feeReceiver: any<br>    factory: any<br>    router: any<br>    weth9: any<br>    pair: any<br>}<br><br>function eth(amount: number) {<br>    return ethers.utils.parseEther(amount.toString())<br>}<br><br>describe(&quot;AdvancedDEXToken&quot;, function () {<br><br>    async function deploy() {<br>        const [deployer, account, feeReceiver] = await ethers.getSigners()<br><br>        // deploy the uniswap v2 protocol<br>        const { router, factory, weth9 } = await UniswapV2Deployer.deploy(deployer);<br><br>        // deploy our token<br>        const Token = await ethers.getContractFactory(&quot;AdvancedDEXToken&quot;)<br>        const token = await Token.deploy(feeReceiver.address, router.address)<br>        await token.deployed()<br><br>        // approve the spending<br>        await weth9.approve(router.address, constants.MaxUint256)<br>        await token.approve(router.address, constants.MaxUint256)<br><br>        // add liquidity<br>        await router.addLiquidityETH(<br>            token.address,<br>            eth(500),<br>            eth(500),<br>            eth(10),<br>            deployer.address,<br>            constants.MaxUint256,<br>            { value: eth(10) }<br>        )<br><br>        // get pair address<br>        const pair = await factory.getPair(token.address, weth9.address)<br><br>        return { token, deployer, account, feeReceiver, factory, router, weth9, pair }<br>    }<br><br>    describe(&quot;disabled&quot;, function () {<br>        it(&quot;should not apply fees&quot;, async function () {<br>            const { token, deployer, account } = await loadFixture(deploy)<br>            const amount = eth(100)<br>            await expect(token.transfer(account.address, eth(100))).to.changeTokenBalances(<br>                token,<br>                [deployer, account],<br>                [amount.mul(-1), amount]<br>            )<br>        })<br>    })<br><br>    describe(&quot;enabled&quot;, function () {<br><br>        let fixture: Fixture<br><br>        beforeEach(async function () {<br>            fixture = await loadFixture(deploy)<br>            await fixture.token.enableTrading()<br>        })<br><br>        describe(&quot;self transfer&quot;, function () {<br>            it(&quot;should not apply fees if token contract is transfering&quot;, async function () {<br>                const { token, router, weth9, deployer } = fixture<br>                await router.swapExactTokensForETHSupportingFeeOnTransferTokens(<br>                    eth(100),<br>                    1,<br>                    [token.address, weth9.address],<br>                    deployer.address,<br>                    constants.MaxUint256,<br>                )<br>                expect(await token.balanceOf(token.address)).to.eq(0)<br>            })<br>        })<br><br>        describe(&quot;buy&quot;, function () {<br>            it(&quot;should apply fees&quot;, async function () {<br>                const { router, weth9, token, deployer, feeReceiver, pair } = fixture<br>                await expect(router.swapETHForExactTokens(<br>                    eth(100),<br>                    [weth9.address, token.address],<br>                    deployer.address,<br>                    constants.MaxUint256,<br>                    { value: eth(1000) }<br>                )).to.changeTokenBalances(token,<br>                    [deployer, token, pair, feeReceiver],<br>                    [eth(95), eth(5), eth(100).mul(-1), 0]<br>                )<br>            })<br>            it(&quot;should not swap for ETH&quot;, async function () {<br>                const { router, weth9, token, deployer, feeReceiver } = fixture<br>                await expect(router.swapETHForExactTokens(<br>                    eth(100),<br>                    [weth9.address, token.address],<br>                    deployer.address,<br>                    constants.MaxUint256,<br>                    { value: eth(1000) }<br>                )).to.changeEtherBalance(feeReceiver, 0)<br>            })<br>        })<br><br>        describe(&quot;sell&quot;, function () {<br>            it(&quot;should apply fees&quot;, async function () {<br>                const { router, weth9, token, deployer, feeReceiver, pair } = fixture<br>                // it is difficult to get a test to work here<br>                // we are taking the fee, but we include it in<br>                // the swap for ETH, thereby adding it to the pair<br>                await expect(router.swapExactTokensForETHSupportingFeeOnTransferTokens(<br>                    eth(100),<br>                    1,<br>                    [token.address, weth9.address],<br>                    deployer.address,<br>                    constants.MaxUint256,<br>                )).to.changeTokenBalances(token, [deployer, feeReceiver, pair], [eth(100).mul(-1), 0, eth(100)])<br>            })<br>            it(&quot;should swap for ETH&quot;, async function () {<br>                const { router, weth9, token, deployer, feeReceiver } = fixture<br>                const bBalance = await ethers.provider.getBalance(feeReceiver.address)<br>                await router.swapExactTokensForETHSupportingFeeOnTransferTokens(<br>                    eth(100),<br>                    1,<br>                    [token.address, weth9.address],<br>                    deployer.address,<br>                    constants.MaxUint256,<br>                )<br>                const aBalance = await ethers.provider.getBalance(feeReceiver.address)<br>                expect(aBalance).to.be.greaterThan(bBalance)<br>            })<br>        })<br>    })<br>})</pre><h3>Code</h3><p>Now, there is a trap here, we could end up with an infinite transfer loop. because when we are calling the _transfer function in our contract, we are calling the router swapExactTokensForETHSupportingFeeOnTransferTokens function, which in turn calls our _transfer function. That would be expensive, run out of gas, and revert. A painful and costly experience.</p><p>Therefore, we need a variable to express the state of a transfer. Then we should only call our router if that state is active. This is where we welcome the OpenZeppelin ReentrancyGuard contract. It consists of a modifier that wraps any function you assign it to. Upon entry into the function, it sets a state, and upon exit, it sets it back. This means that while that state is active, it will not run that function again.</p><pre>// SPDX-License-Identifier: MIT<br>pragma solidity ^0.8.9;<br><br>import &quot;hardhat/console.sol&quot;;<br>import &quot;@openzeppelin/contracts/utils/Address.sol&quot;;<br>import &quot;@openzeppelin/contracts/token/ERC20/ERC20.sol&quot;;<br>import &quot;@openzeppelin/contracts/security/ReentrancyGuard.sol&quot;;<br>import &quot;@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol&quot;;<br>import &quot;@uniswap/v2-periphery/contracts/interfaces/IUniswapV2Router02.sol&quot;;<br><br>contract AdvancedDEXToken is ERC20, ReentrancyGuard {<br>    using Address for address payable;<br><br>    address private immutable _feeReceiver;<br>    IUniswapV2Router02 private immutable _router;<br>    address private immutable _weth9;<br>    address private immutable _pair;<br>    bool private _trading = false;<br><br>    constructor(<br>        address feeReceiver_<br>        , address router_<br>        // , address factory_<br>    ) ERC20(&quot;AdvancedDEXToken&quot;, &quot;ADT&quot;) {<br>        _mint(msg.sender, 1000 * 10 ** decimals());<br>        _feeReceiver = feeReceiver_;<br>        _router = IUniswapV2Router02(router_);<br>        _weth9 = _router.WETH();<br>        _pair = IUniswapV2Factory(_router.factory()).createPair(address(this), _weth9);<br>    }<br><br>    function enableTrading() external {<br>        _trading = true;<br>    }<br><br>    function _transfer(<br>        address sender_,<br>        address recipient_,<br>        uint256 amount_<br>    ) internal virtual override {<br>        if (sender_ == address(this) || !_trading) {<br>            super._transfer(sender_, recipient_, amount_);<br>        } else {<br>            uint fee = (amount_ / 100) * 5; // 5% fee<br>            uint amt = amount_ - fee;<br>            <br>            super._transfer(sender_, address(this), fee);<br><br>            if (sender_ != _pair) {<br>                _distributeFee();<br>            }<br><br>            super._transfer(sender_, recipient_, amt);<br>        }<br>    }<br><br>    function _distributeFee() internal nonReentrant {<br>        uint amount = balanceOf(address(this));<br>        if (amount &gt;= 0) {<br>            _swapTokensForETH(amount);<br>        }<br>    }<br><br>    function _swapTokensForETH(uint256 amount_) internal {<br>        address[] memory path = new address[](2);<br>        path[0] = address(this);<br>        path[1] = _weth9;<br>        _approve(address(this), address(_router), amount_);<br>        _router.swapExactTokensForETHSupportingFeeOnTransferTokens(<br>            amount_,<br>            0,<br>            path,<br>            _feeReceiver,<br>            block.timestamp<br>        );<br>    }<br>}</pre><p>The <a href="https://github.com/onmychain/smart-contracts">code for this tutorial can be found on GitHub</a>.</p><p>If this article was helpful, join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>! It is a web3 space to discuss ideas, build projects and help troubleshoot code.</p><p>I’m a multidisciplinary founder, project manager, solidity + react developer, husband, and family+friends cook.</p><p>Got a project idea? Reach out to me on <a href="http://twitter.com/cyri113">Twitter</a> or join the <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f0e27ee0b979" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/solidity-tutorial-swap-token-fees-for-eth-f0e27ee0b979">Solidity Tutorial: Swap Token Fees for ETH</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Solidity Tutorial: automated testing token swaps (Uniswap / Pancakeswap)]]></title>
            <link>https://coinsbench.com/solidity-tutorial-automated-testing-token-swaps-uniswap-pancakeswap-e7b4724bbc06?source=rss-be00b7b3f8e5------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7b4724bbc06</guid>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[pancakeswap]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[uniswap]]></category>
            <dc:creator><![CDATA[Cyrille]]></dc:creator>
            <pubDate>Tue, 14 Mar 2023 15:00:44 GMT</pubDate>
            <atom:updated>2023-03-17T18:33:10.730Z</atom:updated>
            <content:encoded><![CDATA[<p>In this tutorial, we will deploy the whole <a href="https://docs.uniswap.org/contracts/v2/overview">Uniswap V2 protocol</a> to a Hardhat test environment. This will allow us to create automated tests to validate how our contract interacts with a liquidity pool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1rmVp9l5FmYswQFJrp2Bqw.jpeg" /></figure><h3>Introduction</h3><p>Decentralized exchanges (DEXs) have gained significant popularity in the past few years due to their ability to provide users with greater control over their assets, increased transparency, and reduced reliance on centralized intermediaries. While <a href="https://uniswap.org/">Uniswap</a> has moved to V3, DEXs such as <a href="https://pancakeswap.finance/">Pancakeswap</a> still use a fork of Uniswap V2. It is one of the most widely used DEX protocols that enable users to swap ERC20 tokens in a trustless, permissionless, and non-custodial way. In this tutorial, we will walk you through the process of deploying the Uniswap V2 protocol to a Hardhat test environment, allowing you to create automated tests that can validate how your contract interacts with a liquidity pool. By the end of this tutorial, you will have a solid understanding of how to deploy and interact with Uniswap V3, which can help you build more secure and efficient decentralized applications.</p><h3>Setting up the environment</h3><p>Follow the <a href="https://hardhat.org/tutorial">Hardhat Tutorial</a> in order to get the environment set up. We will be using a Typescript project.</p><p>Add the @openzeppelin/contracts library:</p><pre>yarn add --dev @openzeppelin/contracts</pre><p>Add the @uniswap/hardhat-v3-deploy library:</p><pre>yarn add --dev @onmychain/hardhat-uniswap-v2-deploy-plugin</pre><p>Import the library into your hardhat.config.ts file.</p><pre>import &quot;@onmychain/hardhat-uniswap-v2-deploy-plugin&quot;;<br>// ...</pre><p>Great stuff! We are all set up. Now, what will we be building?</p><h3>Overview</h3><p>What we are going to do is to build a token that includes a 5% tax. We will call this token SimpleDEXTax.sol and is based on the <a href="https://medium.com/coinmonks/solidity-tutorial-simple-tax-token-fd08bf90f351">SimpleTax contract we created in a previous tutorial</a>.</p><p>If we were to add liquidity to the SimpleTax contract, it would work, but our transfers would run into a problem. Because we are interacting with a liquidity pool, we are interacting with a contract. We need to understand how a swap works.</p><h3>How Swaps Work</h3><p>When we create a liquidity pool, we add a pair of tokens. One of these is our token, and the other is (in most cases) Ethereum (ETH).</p><p>When we <strong>BUY</strong> our token, we send ETH to the liquidity pool, and in return, the pool sends tokens to our address.</p><p>When we <strong>SELL</strong> our token, we send tokens to the liquidity pool, and in return, the pool sends us ETH.</p><p>It is important to understand that the transfer of tokens from sender to recipient occurs within the token contract. It is simply changing balances.</p><p>We can deduce that a <strong>BUY</strong> is occurring when tokens are transferred from the liquidity pool address to any address.</p><p>We deduce that a <strong>SELL</strong> is occurring when tokens are transferred to the liquidity pool address from any address.</p><p>Therefore it is important that our contract know the address of the liquidity pool it is associated with.</p><p>When we swap, we call the _transfer function. This is where we will calculate the tax and send tokens to the appropriate wallets.</p><h3>Test Cases</h3><p>Below we have defined test cases for our buy and sell use cases. We will also add a third use case which is that when we have a simple transfer i.e. from one wallet to the other, no tax should be applied.</p><ul><li>should tax on buy</li><li>should tax on sell</li><li>should not tax on a simple transfer</li></ul><p>We expect that on the buy and sell action, a percentage of the tokens are sent to a fund address. The downside of this strategy is that you are accumulating tokens, instead of ETH. Therefore, most projects automatically swap the tokens accumulated in the tax fund for ETH.</p><h3>Code</h3><h4>Test cases</h4><pre>import { loadFixture } from &quot;@nomicfoundation/hardhat-network-helpers&quot;<br>import { expect } from &quot;chai&quot;<br>import { constants } from &quot;ethers&quot;<br>import { ethers, UniswapV2Deployer } from &quot;hardhat&quot;<br><br>function eth(amount: number) {<br>    return ethers.utils.parseEther(amount.toString())<br>}<br><br>describe(&quot;SimpleDEXTax&quot;, function () {<br>    <br>    async function deploy() {<br>        const [deployer, fund, target] = await ethers.getSigners()<br><br>        // deploy the uniswap v2 protocol<br>        const { factory, router, weth9 } = await UniswapV2Deployer.deploy(deployer);<br><br>        // deploy our token<br>        const Token = await ethers.getContractFactory(&quot;SimpleDEXTax&quot;)<br>        const token = await Token.deploy(fund.address, factory.address, weth9.address)<br>        await token.deployed()<br><br>        // get our pair<br>        const pair = new ethers.Contract(await token.pair(), UniswapV2Deployer.Interface.IUniswapV2Pair.abi)<br><br>        // approve the spending<br>        await weth9.approve(router.address, eth(1000))<br>        await token.approve(router.address, eth(1000))<br><br>        // add liquidity<br>        await router.addLiquidityETH(<br>            token.address,<br>            eth(500),<br>            eth(500),<br>            eth(10),<br>            deployer.address,<br>            constants.MaxUint256,<br>            { value: eth(10) }<br>        )<br> <br>        return { token, deployer, fund, target, factory, router, weth9, pair }<br>    }<br><br>    describe(&quot;transfer&quot;, function () {<br>        it(&quot;should tax on buy&quot;, async function () {<br>            const { router, weth9, token, deployer, fund, pair } = await loadFixture(deploy)<br>            await expect(router.swapETHForExactTokens(<br>                eth(100),<br>                [weth9.address, token.address],<br>                deployer.address,<br>                constants.MaxUint256,<br>                { value: eth(1000) }<br>            )).to.changeTokenBalances(token, [deployer, fund, pair], [eth(95), eth(5), eth(100).mul(-1)])<br>        })<br>        it(&quot;should tax on sell&quot;, async function () {<br>            const { router, weth9, token, deployer, fund, pair } = await loadFixture(deploy)<br>            // since we have a fee, we must call SupportingFeeOnTransferTokens<br>            await expect(router.swapExactTokensForETHSupportingFeeOnTransferTokens(<br>                eth(100),<br>                1,<br>                [token.address, weth9.address],<br>                deployer.address,<br>                constants.MaxUint256,<br>            )).to.changeTokenBalances(token, [deployer, fund, pair], [eth(100).mul(-1), eth(5), eth(95)])<br>        })<br>        it(&quot;shouldn&#39;t tax on transfer&quot;, async function () { <br>            const { token, deployer, fund, target } = await loadFixture(deploy)<br>            await expect(token.transfer(target.address, eth(100))).to.changeTokenBalances(<br>                token,<br>                [deployer, fund, target],<br>                [eth(100).mul(-1), 0, eth(100)]<br>            )<br>        })<br>    })<br>})</pre><h4>Solidity Code</h4><pre>// SPDX-License-Identifier: MIT<br>pragma solidity ^0.8.9;<br><br>import &quot;@openzeppelin/contracts/token/ERC20/ERC20.sol&quot;;<br>import &quot;@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol&quot;;<br><br>contract SimpleDEXTax is ERC20 {<br><br>    address public immutable fund;<br>    address public immutable pair;<br><br>    constructor(address fund_, address factory_, address weth9_) ERC20(&quot;SimpleDEXTax&quot;, &quot;SDT&quot;) {<br>        _mint(msg.sender, 1000 * 10 ** decimals());<br>        fund = fund_;<br>        // create a pair<br>        pair = IUniswapV2Factory(factory_).createPair(address(this), address(weth9_));<br>    }<br><br>    // checks whether the transfer is a swap<br>    function _isSwap(address sender_, address recipient_) internal view returns (bool result) {<br>        if (sender_ == pair || recipient_ == pair) {<br>            result = true;<br>        }<br>    }<br><br>    function _transfer(<br>        address sender,<br>        address recipient,<br>        uint256 amount<br>    ) internal virtual override {<br>        uint tax = (amount / 100) * 5; // 5% tax<br><br>        if (_isSwap(sender, recipient)) {    <br>            super._transfer(sender, recipient, amount - tax);<br>            super._transfer(sender, fund, tax);<br>        } else {<br>            super._transfer(sender, recipient, amount);<br>        }<br><br>    }<br>}</pre><h4>Swapping Tokens for ETH</h4><p>Let’s say that you do want to sell the tax straight away for ETH. What would you need to do? We will make a <a href="https://medium.com/@cyri113/solidity-tutorial-swap-token-fees-for-eth-f0e27ee0b979">separate tutorial</a> for this as it holds more complexity in order to get it right!</p><p>The <a href="https://github.com/onmychain/smart-contracts">code for this tutorial can be found on GitHub</a>.</p><p>If this article was helpful, join our <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>! It is a web3 space to discuss ideas, build projects and help troubleshoot code.</p><p>I’m a multidisciplinary founder, project manager, solidity + react developer, husband, and family+friends cook.</p><p>Got a project idea? Reach out to me on <a href="http://twitter.com/cyri113">Twitter</a> or join the <a href="https://t.me/+DvRkarkKP6ZhMzM0">Telegram group</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7b4724bbc06" width="1" height="1" alt=""><hr><p><a href="https://coinsbench.com/solidity-tutorial-automated-testing-token-swaps-uniswap-pancakeswap-e7b4724bbc06">Solidity Tutorial: automated testing token swaps (Uniswap / Pancakeswap)</a> was originally published in <a href="https://coinsbench.com/">CoinsBench</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>