<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: a_mature_dev</title>
    <description>The latest articles on DEV Community by a_mature_dev (@a_mature_dev).</description>
    <link>https://dev.to/a_mature_dev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F160873%2F2c818f72-f305-414a-9986-c19955353200.png</url>
      <title>DEV Community: a_mature_dev</title>
      <link>https://dev.to/a_mature_dev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/a_mature_dev"/>
    <language>en</language>
    <item>
      <title>Web3: Should I use Infura / Alchemy or Run a Node?</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Sat, 14 May 2022 00:23:45 +0000</pubDate>
      <link>https://dev.to/buildbear/web3-should-i-use-infura-alchemy-or-run-a-node-3cjj</link>
      <guid>https://dev.to/buildbear/web3-should-i-use-infura-alchemy-or-run-a-node-3cjj</guid>
      <description>&lt;p&gt;&lt;strong&gt;Quick Recap on Web3&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Unless you have been living under a rock, you would have come across the term Web3, through a blog post, news articles, or some other source. Trust me, Web3 has been shaking the internet as it exists today.&lt;/p&gt;

&lt;p&gt;Web3 is the culmination of a vision of serverless internet, the &lt;strong&gt;decentralized web&lt;/strong&gt;. An internet where users are in control of their own data, identity, and destiny.&lt;/p&gt;

&lt;p&gt;The Web3 stack looks something like that&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Network Layer&lt;/strong&gt; — aka Blockchain, the backend&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Interaction Layer&lt;/strong&gt; — aka Node providers, the AWSes of the blockchain world&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;*&lt;em&gt;Decentralized Applications *&lt;/em&gt;— Customer interfaces to access Web 3.0, the “apps”&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This article focuses on the Interaction Layer, specifically in relation to EVM based Blockchains.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Reason:&lt;/em&gt; Cause you are starting out on the Web3 development cycle and you need to know as why is the layer 1important, who provides that service, do I need it, etc etc&lt;/p&gt;

&lt;p&gt;There are 2 approaches to work with the interaction layer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Using third-party service providers: Eg: Infura, Alchemy, QuickNode, OR&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Running your own node client: Eg, Geth&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you would have already guessed, there are pros and cons to both the options. 90% of the dapp development happens using the option 2; but without much analysis into this subject.&lt;/p&gt;

&lt;p&gt;The objective of this article is to let you know of the pros and cons and then to help you make a decision on should follow the herd or break free.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;OPTION 1: Using A Node Service Provider&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;As the name suggests Node service provider runs node clients behind the scenes for you so that you don’t have to. Each of its clients can then participate in “using” the node (obviously, it is shared). Heard economies of scale?!?, yes that is what comes into play over here now.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;These service providers typically provide an API key that you can use to communicate with the node. Yes, all your provider.getBalance(0x) and others comes here.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using these nodes is usually a plug and play through their SDK&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There are various node providers out there like Alchemy, Infura, QuickNode offering these services.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To understand it in a better manner, the following table consists of some of the most popular node providers and their features.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6m8UHR7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2732/1%2Ahqu-ikgBnnSlKU6wdKPRxQ.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6m8UHR7H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/2732/1%2Ahqu-ikgBnnSlKU6wdKPRxQ.png" alt="Node Service Providers" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For more information, check out this &lt;a href="https://ethereum.org/en/developers/docs/nodes-and-clients/nodes-as-a-service/#popular-node-services"&gt;page&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros of Using the above mentioned service providers&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Easy to Use; just plug and play using their own SDK or other Web3 JS libraries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instant Availability&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Back-up options available (should one node fail, the other comes up)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Technical Support Team available&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No hassle of maintaining the Node Software; risks associated with Nodes&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fractionalized Costing {more on this later}&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Third-party reliance (isn’t that exactly opposite to what blockchain ethos is all about)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cost (may be, may be not?)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;OPTION 2 :Running Your Own Node.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By running our own Node we mean that your server stores the entire blockchain. You may choose whether your Node should validate every block of data before adding it to the blockchain (yes yes, we are talking about mining, proof of work when it comes to Ethereum Blockchain).&lt;/p&gt;

&lt;p&gt;Although, running own node can be considered good practice but is not recommended due to its cost and time taken for the installation process.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A &lt;strong&gt;Full Node sync&lt;/strong&gt; can take around a &lt;strong&gt;month&lt;/strong&gt; &lt;strong&gt;or two&lt;/strong&gt; for downloading the whole blockchain&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;Light Node sync&lt;/strong&gt; can take up to several &lt;strong&gt;weeks&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There exist multiple clients on the internet that allow you to run their own Node based on various programming languages like Go, Rust, Typescript, etc.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Some client examples&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J1OvH4IK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3840/1%2A4SQbtc1TcDZcunO-1CdTlA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J1OvH4IK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://cdn-images-1.medium.com/max/3840/1%2A4SQbtc1TcDZcunO-1CdTlA.png" alt="Ethereum Node Clients" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros of Using the above mentioned service providers&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You are the master of your own destiny. No more, API keys, No more purchase a plan, API Call limits, etc&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Cons&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Costs&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Maintenance&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Lets talk about the Costs (financial and then the time costs)
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Costs of using 3rd party service providers
&lt;/h3&gt;

&lt;p&gt;Providers like Infura and Alchemy provide a free tier to use their services. Obviously, there are limits to the number of API calls that you can make under the “Free Tier”. Currently, Infura permits 100,000 requests per day in the free tier, while Alchemy permits 300 Million requests.&lt;/p&gt;

&lt;p&gt;Of course, the above-mentioned numbers are not small numbers, should be doing any form of initial stage development; testing; tutorials etc. But as soon as you go live with the a DAPP, which will easily bust the above limits, you are sitting with costs from Infura / Alchemy.&lt;/p&gt;

&lt;p&gt;According to some recent records, on average, &lt;strong&gt;Uniswap&lt;/strong&gt; sends around &lt;strong&gt;30 million requests&lt;/strong&gt;, &lt;strong&gt;Akropolis&lt;/strong&gt; sends &lt;strong&gt;2 million requests&lt;/strong&gt; whereas, &lt;strong&gt;Sushiswap&lt;/strong&gt; sends around &lt;strong&gt;25 million requests per day&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now there is a lot of structuring involved. For eg, if we are designing a DAPP, we do not make our API endpoints public and hence, when our users connect to our DAPP, their wallet connects to a service provider. Hence, do not fret the above numbers straight away.&lt;/p&gt;

&lt;p&gt;However, on average, we have witnessed that if you are maintaining a backend to analyse your smart contract data, performance and various other factors, you are definitely looking at ~&lt;strong&gt;$200 costs per month&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Costs of running your own node
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Aspect 1: Financial (the easily measurable factor)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Hardware requirements to run your own node:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;At least 2TB of SDD (yes, we are forward looking and are planning to run the full node)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;4GB Ram (oh common, don’t be cheap with a 2GB ram now)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Connected to the internet 24*7&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Intel NUC, 7th gen or higher (x86 processor)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On an average, based on the above requirements, we understand that it costs roughly &lt;strong&gt;~600$ a month&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Aspect 2: Manpower Costs&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It would typically require one of your engineers to least spend 30 mins each day just to monitor the performance of the node; we are also expecting a here and there break-down and hence, more time involvement. This will cost us ~24 hours a month, ie, ~ &lt;strong&gt;$1,200 per month.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Running our own node can cost you an estimated cost of &lt;strong&gt;$22K / year&lt;/strong&gt;, compared to an estimated cost of &lt;strong&gt;$2,400 / year&lt;/strong&gt; on account of using 3rd party service providers.&lt;/p&gt;

&lt;p&gt;Using a service provider can ease out the process and cut the whole time-consuming instructions. Nonetheless, reliability and some other factors do make the case for running your own node worth considering.&lt;/p&gt;

&lt;p&gt;There you go! Now you have the pros and cons. It is, probably, now obvious why majority of the dapp developers in the world choose 3rd party service providers.&lt;/p&gt;

&lt;p&gt;However, you need to understand that both of the approaches play a major role individually, and it only you who can determine which approach suits you best.&lt;/p&gt;

&lt;p&gt;We would love to know your thoughts; we are open to learn and hence if you think we have missed out anything; more than happy to know.&lt;/p&gt;

&lt;p&gt;Authors (open to feedback): &lt;a href="https://medium.com/u/9cd26cbd96b9?source=post_page-----5311a13d173--------------------------------"&gt;Amateur-Dev&lt;/a&gt; and &lt;a href="https://medium.com/u/130345445971?source=post_page-----5311a13d173--------------------------------"&gt;Pari Tomar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>codenewbie</category>
      <category>ethereum</category>
    </item>
    <item>
      <title>Upgrade your Smart Contract Deployment Script; impress the shi.t out!</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Thu, 12 May 2022 06:21:10 +0000</pubDate>
      <link>https://dev.to/buildbear/upgrade-your-smart-contract-deployment-script-impress-the-shit-out-389e</link>
      <guid>https://dev.to/buildbear/upgrade-your-smart-contract-deployment-script-impress-the-shit-out-389e</guid>
      <description>&lt;p&gt;This write-up takes into account our two earlier write-up: &lt;a href="https://medium.com/uv-labs/creating-and-deploying-your-first-smart-contract-466b4d4784e2"&gt;Part 1&lt;/a&gt; and &lt;a href="https://medium.com/uv-labs/dude-i-just-deployed-my-own-nft-wt-f-9ef91c778af"&gt;Part 2&lt;/a&gt;; wherein we have been learning about deployment of smart contracts.&lt;/p&gt;

&lt;p&gt;This particular write-up is with the intention of demonstrating a better way for deployment of smart contracts. You can look at this new way of deployment of smart contracts, as an optional strategy; however, if you are shaping your career to become a professional smart contract developer — then I would recommend you to keep this is as a MUST Learn practice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RECAP&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Till now, we have been deploying smart contracts, using a simple script in our: &lt;code&gt;/scripts&lt;/code&gt; folder. Our script to deploy our last NFT Smart Contract was as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { ethers } = require("hardhat");async function main() {
    const NFT = await ethers.getContractFactory("NFT");
    const deployedNFT = await NFT.deploy();
    console.log(`Contract deployed to address:          ${deployedNFT.address}`)
}main()
.then(() =&amp;gt; process.exit(0))
.catch((error) =&amp;gt; {
    console.error(error);
    process.exit(1);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Time to UPGRADE!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;First&lt;/em&gt;&lt;/strong&gt;: We are going to install hardhat-deploy from here. Depending on what you use, it will be either npm install or yarn add.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Second&lt;/em&gt;&lt;/strong&gt;: Add require('hardhat-deploy') to our file hardhat-config.js&lt;/p&gt;

&lt;p&gt;Our updated config file will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
require('dotenv').config();
require('@nomiclabs/hardhat-ethers');
require('hardhat-deploy'); // &amp;lt;--- This is the new additionconst {API_URL, PRIVATE_KEY} = process.env;
....
....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;em&gt;Third&lt;/em&gt;&lt;/strong&gt;: Create a new folder deploy in the root of the project and add the following file to it. Note the name of the file. It is critical.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// location of the file: ./deploy/00_deploy_NFT.jsconst func = async function (hre) {
  const { getNamedAccounts, deployments } = hre;
  const { deployer } = await getNamedAccounts();
  const { deploy } = deployments;
  await deploy("NFT", {
    from: deployer,
    log: true,
  });
}func.tags = ["NFT"];module.exports = func;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your folder structure should look like this after the addition of the above file:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aYdzRGqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/900/1%2ADGEtKzyzZrZOROJMvhg51Q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aYdzRGqx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/900/1%2ADGEtKzyzZrZOROJMvhg51Q.png" alt="Folder Structure" width="450" height="652"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Voilà&lt;/em&gt;&lt;/strong&gt;! You have upgraded yourself 🥳🥳🥳🥳🥳&lt;/p&gt;

&lt;p&gt;Let’s see the magic of what we have done.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Open a terminal in the location of the folder and run the command: npx hardhat node —-no-deploy This will spin-off a hardhat node with a number of accounts that are to be used for the purpose of deployments&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open a new terminal in the same location of the folder and now run the following command: &lt;code&gt;npx hardhat deploy —-network localhost&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If all is done successfully, you should see the following in your terminal:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;deploying "NFT" (tx: 0x5c8faff64acb214523566f9fa0d1168159c0c380d71cc5486828e34aff085a19)...: deployed at 0x5FbDB2315678afecb367f032d93F642f64180aa3 with 2525550 gas
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AND, you will see a new folder in your directory structure with the name deployments. Something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dGcQLFju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/912/1%2Ak0tZzdHZEln7sOq2cu8fUg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dGcQLFju--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/912/1%2Ak0tZzdHZEln7sOq2cu8fUg.png" alt="Folder Structure" width="456" height="772"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dig into the files in the &lt;code&gt;deployments&lt;/code&gt; folder and you will notice that it has saved the address to which the contract has been deployed, along with the other details. The details saved in the deployments folder are per chain to which the contracts are deployed.&lt;/p&gt;

&lt;p&gt;We ran another command in our terminal &lt;code&gt;npx hardhat deploy --network mumbai-matic&lt;/code&gt; to deploy our contract to the Mumbai Matic test network. Our directory structure afterwards was as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--N1dBDRzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/912/1%2A3OlDXE8UgPCz2rJaizfeUA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--N1dBDRzM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://miro.medium.com/max/912/1%2A3OlDXE8UgPCz2rJaizfeUA.png" alt="Folder Structure" width="456" height="740"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you will notice, we now have a new folder with the name mumbai-matic and also have the details saved in that directory.&lt;/p&gt;

&lt;p&gt;There you go!!! You are now a better version of a blockchain developer.&lt;/p&gt;

&lt;p&gt;We hope you like what we are doing over here. If you do, please do clap 👏 at the end of the article and yes, do share with your friends.&lt;/p&gt;

&lt;p&gt;Also note: You can download and run the same code that we will using in our tutorial (aka tuts) from here 👉 &lt;a href="https://github.com/UV-Labs/Tutorials"&gt;Github repository&lt;/a&gt;. If you like out stuff, give us a star 🌟 on Github too.&lt;/p&gt;

&lt;p&gt;Happy Coding!!!&lt;/p&gt;

&lt;p&gt;Authors (open to feedback): 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/u/9cd26cbd96b9?source=post_page-----5311a13d173-----------------------------------"&gt;Amateur-Dev&lt;/a&gt; and &lt;a href="https://medium.com/u/130345445971?source=post_page-----5311a13d173-----------------------------------"&gt;Pari Tomar&lt;/a&gt;&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>codenewbie</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Mint 100s of NFTs in just 5 MINUTES using ERC1155 😊😊</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Tue, 10 May 2022 13:27:18 +0000</pubDate>
      <link>https://dev.to/buildbear/mint-100s-of-nfts-in-just-5-minutes-using-erc1155-3dk1</link>
      <guid>https://dev.to/buildbear/mint-100s-of-nfts-in-just-5-minutes-using-erc1155-3dk1</guid>
      <description>&lt;p&gt;In one of our previous articles, we minted our own NFT where we used the ERC721 contract, which INDEED was an awesome experience for us!  Link to that article: 👉 &lt;a href="https://medium.com/uv-labs/dude-i-just-deployed-my-own-nft-wt-f-9ef91c778af"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now! We will challenge it to make it more fun and faster! &lt;/p&gt;

&lt;p&gt;In this article, we will use the &lt;strong&gt;ERC-1155&lt;/strong&gt; standard in order to mint our NFT. &lt;/p&gt;

&lt;p&gt;Not only this, we will also try to mint our NFTs in less than 5 minutes. &lt;/p&gt;




&lt;p&gt;You might be wondering, why use the ERC-1155 for minting our NFTs instead of the standard ERC-721, right?&lt;/p&gt;

&lt;p&gt;There are some &lt;strong&gt;key differences&lt;/strong&gt; that should address this question:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One&lt;/strong&gt; &lt;strong&gt;Smart Contract for all&lt;/strong&gt;: ERC-721 standard produces NFTs solely and forces developers to create a smart contract for each new token.  On the other hand, ERC-1155 allows developers to develop a single smart contract that can be used to mint either &lt;strong&gt;fungible tokens&lt;/strong&gt; or &lt;strong&gt;NFTs. Yes, this means, multiple of each of these tokens under one contract.&lt;/strong&gt;  It has the ability to support multiple states on the same address and contract.  In simpler words, this means you can make in-game payments using a fungible token on that address and simultaneously transfer unique NFT assets as well.&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Efficiency:&lt;/strong&gt; ERC-721 allows a single operation for each transaction. It is expensive and time-consuming.  Whereas, ERC-1155 allows multiple operations in a single transaction. Therefore, the transactions are cheaper and more efficient.&lt;/p&gt;

&lt;p&gt;Unlike ERC-721, which utilizes significant space, ERC-1155 uses less storage space on a blockchain network. This is because ERC-1155 has the features of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Batch Transfer:&lt;/em&gt; Transfer multiple assets in a single call.&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;Batch Approval:&lt;/em&gt; Approve all tokens to an address&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This results in less space consumption on the blockchain network. &lt;/p&gt;




&lt;p&gt;Now that we have seen some of the benefits of ERC-1155, let’s begin 🏃🏻&lt;/p&gt;

&lt;h3&gt;
  
  
  *&lt;strong&gt;&lt;em&gt;Tools we will be using&lt;/em&gt;&lt;/strong&gt;*🛠️
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Remix IDE:&lt;/strong&gt; It is a powerful open-source tool that helps you write Solidity contracts straight from the browse and speeds-up the whole development process.   Though, in our opinion, this should be in no-manner your go-to strategy for working on projects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IPFS&lt;/strong&gt;: IPFS is a distributed system for storing and accessing files, websites, applications, and data. We will be using Pinata client to interact with IPFS. &lt;strong&gt;Pinata&lt;/strong&gt; gives users the ability to upload, manage, and share their content whenever, wherever, and, with whomever they want&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MetaMask&lt;/strong&gt;: MetaMask is a chrome wallet that lets us interact with the blockchain. We will need our wallet details from Metamask. You have many other options, but we are just sticking to this for ease.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please note, you will have to connect your Metamask to the Mumbai Matic Testnet network for the purpose of this Tuts. Read 👉 &lt;em&gt;&lt;a href="https://blog.polysynth.com/how-to-connect-polygon-testnet-to-metamask-wallet-472bca410d64"&gt;this&lt;/a&gt;&lt;/em&gt; so that you are connected to Mumbai Matic Testnet. Once that is done, you should fetch test tokens; for that head 👉 &lt;em&gt;&lt;a href="https://faucet.polygon.technology/"&gt;here&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;🏋️&lt;em&gt;Now let’s get to the fun part&lt;/em&gt; 🏋️‍♀️&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Write our Smart Contract
&lt;/h2&gt;

&lt;p&gt;In order to write our smart contract, we are going to use Remix IDE to mint our NFTs faster than ever before! 🚅&lt;/p&gt;

&lt;p&gt;Therefore, if you are new to Remix IDE we highly recommend you to go through &lt;a href="https://www.youtube.com/watch?v=bZKVfXmzRDw"&gt;this&lt;/a&gt; video.&lt;/p&gt;

&lt;p&gt;First of all, we are going to create a solidity file where we’ll be defining our contract and mint some Game of Thrones’ characters’ NFTs. 😮&lt;/p&gt;

&lt;p&gt;Therefore, we are going to name our file as &lt;code&gt;GameofThrones.sol&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Second, we will import the &lt;em&gt;ERC-1155&lt;/em&gt; contract from &lt;em&gt;Openzeppelin&lt;/em&gt; to use its functions in our contract. &lt;/p&gt;

&lt;p&gt;Third, we will define our smart contract to mint our NFT that also inherits from &lt;em&gt;Openzeppelin’s ERC1155 contract.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Your code should look similar to this 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: MIT&lt;/span&gt;
&lt;span class="nx"&gt;pragma&lt;/span&gt; &lt;span class="nx"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;^&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;contract&lt;/span&gt; &lt;span class="nx"&gt;GameofThrones&lt;/span&gt; &lt;span class="nx"&gt;is&lt;/span&gt; &lt;span class="nx"&gt;ERC1155&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we are going to specify some names and IDs for the NFTs, which we could use further for testing references. &lt;/p&gt;

&lt;p&gt;For example, here we have assigned the IDs to the various character named variables. &lt;/p&gt;

&lt;p&gt;By this we could say that the NFT with the ID 1 is JonSnow and so on.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;constant&lt;/span&gt; &lt;span class="nx"&gt;JonSnow&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;constant&lt;/span&gt; &lt;span class="nx"&gt;CerseiLannister&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;constant&lt;/span&gt; &lt;span class="nx"&gt;DaenerysTargaryen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;constant&lt;/span&gt; &lt;span class="nx"&gt;NightKing&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;constant&lt;/span&gt; &lt;span class="nx"&gt;TyrionLannister&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;constant&lt;/span&gt; &lt;span class="nx"&gt;AryaStark&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, we will define the constructor where we are going to use the &lt;strong&gt;&lt;em&gt;_mint&lt;/em&gt;&lt;/strong&gt; function from the ERC1155 contract in order to mint our NFT.&lt;/p&gt;

&lt;p&gt;Inside the _&lt;em&gt;mint&lt;/em&gt; function, we are going to define some values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The sender’s address&lt;/li&gt;
&lt;li&gt;The tokens that we’re going to mint&lt;/li&gt;
&lt;li&gt;The amount of tokens we want to mint&lt;/li&gt;
&lt;li&gt;And the data of the token&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And there’s one interesting thing, we have already uploaded our NFT Metadata to the IPFS to save our time. &lt;/p&gt;

&lt;p&gt;IPFS is decentralized storage. And here we have used the Pinata IPFS which gives users the ability to store their data. &lt;/p&gt;

&lt;p&gt;This is the &lt;a href="https://gateway.pinata.cloud/ipfs/QmXLdCoTPVZ8Vf5PrEZR1awPKR8PvxmyEakaR5ummPCPnh"&gt;folder&lt;/a&gt; storing the Metadata that we’re going to use for our NFTs. Therefore, here we have 6 different Metadata for the respective NFTs.&lt;/p&gt;

&lt;p&gt;If you’re new to Pinata, we recommend you go through our previous &lt;a href="https://medium.com/uv-labs/dude-i-just-deployed-my-own-nft-wt-f-9ef91c778af"&gt;article&lt;/a&gt; based on NFT, where we have covered how to upload the metadata of your NFT on Pinata IPFS. &lt;/p&gt;

&lt;p&gt;Your constructor should look similar to this 👇&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="nx"&gt;ERC1155&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://gateway.pinata.cloud/ipfs/QmXLdCoTPVZ8Vf5PrEZR1awPKR8PvxmyEakaR5ummPCPnh/{id}.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;_mint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;JonSnow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;_mint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;CerseiLannister&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;_mint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;DaenerysTargaryen&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;_mint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;NightKing&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;_mint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;TyrionLannister&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;_mint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;AryaStark&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that for Game of Thrones characters, all the characters are fungible tokens instead of the &lt;strong&gt;NightKing&lt;/strong&gt; token, which is a non-fungible token as we minted only one of it. &lt;/p&gt;

&lt;p&gt;The ERC1155 contract includes the optional extension &lt;em&gt;IERC1155MetaDataURI.&lt;/em&gt; That’s where the URI function comes from: we will use it to retrieve the metadata URI. &lt;/p&gt;

&lt;p&gt;Thus, if we replace the &lt;strong&gt;&lt;em&gt;id&lt;/em&gt;&lt;/strong&gt; with token ID 1 inside the MetadataURI we provided, we could get the metadata of the first NFT. &lt;/p&gt;

&lt;p&gt;Result would look similar to this 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dDdUK95H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2awd7vy6pv3edimvqir2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dDdUK95H--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2awd7vy6pv3edimvqir2.png" alt="Pinata" width="800" height="451"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But OpenSea does not understand the way we encoded the &lt;em&gt;id&lt;/em&gt; inside the MetadataURI. &lt;/p&gt;

&lt;p&gt;Therefore we have to overwrite the URI function so it works a bit differently. And in order to do that, we are going to need some helper functions to work with the strings. &lt;/p&gt;

&lt;p&gt;Therefore, we will import the Strings contract from Openzeppelin’s contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then add the following code inside your contract:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nx"&gt;uri&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;_tokenId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nx"&gt;override&lt;/span&gt; &lt;span class="kr"&gt;public&lt;/span&gt; &lt;span class="nx"&gt;view&lt;/span&gt; &lt;span class="nx"&gt;returns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt; &lt;span class="nx"&gt;memory&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nx"&gt;abi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;encodePacked&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://gateway.pinata.cloud/ipfs/QmXLdCoTPVZ8Vf5PrEZR1awPKR8PvxmyEakaR5ummPCPnh/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="nx"&gt;Strings&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;toString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_tokenId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
                &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;.json&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So here, we are writing our own implementation of the URI function and we want to take the token ID and then we want to concatenate the base URL and the required token ID (which is an integer) into the string. &lt;/p&gt;

&lt;p&gt;By doing this, we will have our ERC-1155 contract ready to deploy!! 😃&lt;/p&gt;

&lt;p&gt;Your smart contract should look like this👇 &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1A63AZwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6tdnqwku5yo4m3gcd0gt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1A63AZwE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6tdnqwku5yo4m3gcd0gt.png" alt="Smart Contract" width="800" height="642"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Therefore, now it's TIME to deploy our contract and view our NFTs on Opensea.  🤯&lt;/p&gt;

&lt;p&gt;For your ease, you can use this ➡️ &lt;a href="https://remix.ethereum.org/#url=https://github.com/UV-Labs/Tutorials/blob/main/GameofThronesNFT/GameofThrones.sol&amp;amp;optimize=false&amp;amp;runs=200&amp;amp;evmVersion=null&amp;amp;version=soljson-v0.8.7+commit.e28d00a7.js"&gt;link&lt;/a&gt; 🔗 to directly load this contract in remix on your browser.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Deploy the Smart Contract on Mumbai Matic Testnet
&lt;/h2&gt;

&lt;p&gt;Opensea supports various networks like Rinkeby, Mumbai Matic, etc. Thus, we’re going to use the Mumbai Matic Test network to mint our NFTs.&lt;/p&gt;

&lt;p&gt;We will follow some steps to deploy our contract:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To deploy the contract, we’re going to use the Metamask wallet on the  Mumbai Matic test network, so that once the contract is deployed, Opensea can grab it easily.&lt;/li&gt;
&lt;li&gt;Switch to Mumbai Matic Test Network in your Metamask wallet and make sure you have some test Matic to perform the transaction. If you don’t have test Matic go 👉 &lt;em&gt;&lt;a href="https://faucet.polygon.technology/"&gt;here&lt;/a&gt;&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--OVE7U26M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljbynrnw3znan1svad6e.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--OVE7U26M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ljbynrnw3znan1svad6e.png" alt="Metamask Screenshot" width="357" height="595"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then, update the Remix IDE environment to &lt;strong&gt;Injected Web3&lt;/strong&gt; which you could find under the &lt;em&gt;Deploy &amp;amp; Run Transactions&lt;/em&gt; section.&lt;/li&gt;
&lt;li&gt;Once done, you can see that the account address shown in the Remix IDE is similar to your Metamask account.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EIAEv6Q8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysan4cxgscv4tuh8elz7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EIAEv6Q8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysan4cxgscv4tuh8elz7.png" alt="Remix Wallets" width="405" height="758"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Pick the contract which you want to deploy. In our case, we have the &lt;em&gt;GameofThrones.sol&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Now, once you’ll hit the Deploy button, you can see a Metamask window pop-up that asks us to confirm our transaction.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hit the confirm button to mint our NFT on Opensea. &lt;/p&gt;

&lt;p&gt;And there you gooo!!&lt;/p&gt;

&lt;p&gt;You have minted your own NFTs. 😲😲😲&lt;/p&gt;

&lt;p&gt;Without wasting any time, we will use this link to see our minted NFT on Opensea &lt;/p&gt;

&lt;p&gt;&lt;code&gt;https://testnets.opensea.io/&amp;lt;your-account-address&amp;gt;?tab=created&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;You can see mine &lt;a href="https://testnets.opensea.io/paritomar"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Showcase your NFTs to your friends and don’t forget to tag us on Twitter at &lt;a href="https://twitter.com/uv_labs"&gt;@uv_labs&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We will surely retweet your NFT 🥳&lt;/p&gt;

&lt;p&gt;And don’t worry, if you get any error messages, you can ask us too by tagging us on Twitter.&lt;/p&gt;

&lt;p&gt;Do give us a star, clap if you liked our work.&lt;/p&gt;

&lt;p&gt;Authors (open to feedback): 👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/u/9cd26cbd96b9?source=post_page-----5311a13d173-----------------------------------"&gt;Amateur-Dev&lt;/a&gt; and &lt;a href="https://medium.com/u/130345445971?source=post_page-----5311a13d173-----------------------------------"&gt;Pari Tomar&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Learn to execute Flash Swaps ⚡on Uniswap by yourself</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Wed, 04 May 2022 16:04:01 +0000</pubDate>
      <link>https://dev.to/buildbear/executing-flash-swaps-on-uniswap-6ch</link>
      <guid>https://dev.to/buildbear/executing-flash-swaps-on-uniswap-6ch</guid>
      <description>&lt;p&gt;In the &lt;a href="https://medium.com/uv-labs/uniswap-testing-1d88ca523bf0"&gt;previous&lt;/a&gt; article, we understood how we can implement a swap between tokens using Uniswap. &lt;/p&gt;

&lt;p&gt;In this article, we will be moving one level ahead by exploring &lt;strong&gt;Flash Swap by coding a flash swap&lt;/strong&gt; contract and run tests on it! &lt;/p&gt;

&lt;p&gt;&lt;em&gt;We highly recommend you go through the previous article before.&lt;/em&gt; &lt;/p&gt;

&lt;h3&gt;
  
  
  What is a Flash Loan?
&lt;/h3&gt;

&lt;p&gt;Unlike Traditional Loans, in Flash Loans, funds are borrowed and returned in &lt;strong&gt;one transaction&lt;/strong&gt;.  This is a MUST. &lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Defi,&lt;/strong&gt; traders (usually through bots) keep looking out for arbitrage opportunities to gain benefits by trading between platforms supplying different prices for the same asset. &lt;/p&gt;

&lt;p&gt;This is where the Flash Loans comes into the picture (albeit usually). &lt;/p&gt;

&lt;p&gt;With the help of &lt;strong&gt;Flash Loan&lt;/strong&gt;, traders can borrow a large sum of money to execute an arbitrage trade.&lt;/p&gt;

&lt;h3&gt;
  
  
  How does Flash Loan Arbitrage work?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gY3YUoww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b12d8wlr9yag4n8nh4i7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gY3YUoww--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b12d8wlr9yag4n8nh4i7.png" alt="Example" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Consider a situation, where Ethan buys a book for $10 from the Bookstore and then sells that book to Jennifer for $20. In this situation, Ethan buys a book using his money and then straight away doubles it by selling it to Jennifer.&lt;/p&gt;

&lt;p&gt;This is exactly how trading arbitrage works. &lt;/p&gt;

&lt;p&gt;But unlike Ethan, who used his own money for buying the book from the bookstore, here we could simply use Flash Loans to borrow $10 and then execute a trade, similar to selling the book and then repay the loan (yes, all in 1 single transaction). &lt;/p&gt;

&lt;p&gt;Lets dive in coding our own Flash swap contract and test it out!! 😎&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a project and install dependencies
&lt;/h2&gt;

&lt;p&gt;Use the following commands on your CLI to initialize your project.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;mkdir&lt;/span&gt; &lt;span class="nx"&gt;Flash_swap&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;cd&lt;/span&gt; &lt;span class="nx"&gt;Flash_swap&lt;/span&gt;
&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;init&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, install the required dependencies that we’ll be using for the project. &lt;/p&gt;

&lt;p&gt;Use the command provided below and run it on your CLI to install them.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;npm&lt;/span&gt; &lt;span class="nx"&gt;install&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;save&lt;/span&gt; &lt;span class="nx"&gt;hardhat&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;nomiclabs&lt;/span&gt;&lt;span class="sr"&gt;/hardhat-ethers @nomiclabs/&lt;/span&gt;&lt;span class="nx"&gt;hardhat&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;waffle&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;uniswap&lt;/span&gt;&lt;span class="sr"&gt;/v2-core dotenv hardhat cha&lt;/span&gt;&lt;span class="err"&gt;i
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Initialize your Hardhat Project
&lt;/h2&gt;

&lt;p&gt;Run the command &lt;code&gt;npx hardhat&lt;/code&gt; on your CLI and create an empty hardhat config file, since we’re going to build everything from scratch. &lt;/p&gt;

&lt;p&gt;Customize your hardhat config:&lt;/p&gt;

&lt;p&gt;Because we are going to fork the mainnet to test the Flashswap. Therefore, your hardhat config should look something similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sGFbreaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7yajo4oo472p4kj7929.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sGFbreaG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u7yajo4oo472p4kj7929.png" alt="CodeBlock" width="800" height="599"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: Replace the &lt;code&gt;&amp;lt;key&amp;gt;&lt;/code&gt; component of the URL with your personal &lt;a href="https://www.alchemy.com/"&gt;Alchemy&lt;/a&gt; API key.&lt;/p&gt;

&lt;p&gt;Also, if you’re new to mainnet forking, read our &lt;a href="https://medium.com/uv-labs/fork-the-f-ing-ethereum-blockchain-transfer-tokens-from-vitaliks-account-46d408f7356c"&gt;article&lt;/a&gt; based on it and then follow along with this article. &lt;/p&gt;

&lt;h2&gt;
  
  
  3. Write a smart contract for Flash swap
&lt;/h2&gt;

&lt;p&gt;Create directories for contracts and tests for better code organisation.&lt;/p&gt;

&lt;p&gt;Use the following code in your CLI.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;mkdir&lt;/span&gt; &lt;span class="nx"&gt;contracts&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nx"&gt;mkdir&lt;/span&gt; &lt;span class="nx"&gt;tests&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In order to write the flash swap contract, create a file inside the contracts directory and name it &lt;code&gt;flashswap.sol&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Writing the smart contract:&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First, import the interfaces required and create a contract named as &lt;code&gt;flashSwap&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We will import &lt;strong&gt;Uniswap’s interface&lt;/strong&gt; to use its functions. You can get the interface using this &lt;a href="https://github.com/UV-Labs/Tutorials/blob/main/Flash_swap/contracts/interfaces/Uniswap.sol"&gt;link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We have also imported &lt;strong&gt;IUniswapV2Callee&lt;/strong&gt; interface. Uniswap will call this function when we execute the flash swap.  Technically this is the callback function that Uniswap will call.&lt;/p&gt;

&lt;p&gt;It should look similar to this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jaA2yP0b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf4u0t8na1ljifi50sa8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jaA2yP0b--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tf4u0t8na1ljifi50sa8.png" alt="CodeBlock" width="800" height="612"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we create our contract &lt;strong&gt;flashSwap&lt;/strong&gt; which inherits from &lt;strong&gt;IUniswapV2Callee&lt;/strong&gt;.  Solidity supports inheritance between smart contracts, where multiple contracts can be inherited into a single contract. The contract from which other contracts inherit features is known as a base contract, while the contract which inherits the features is called a derived contract.&lt;/p&gt;

&lt;p&gt;This contract will have 2 functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;testFlashSwap()&lt;/strong&gt;: This is the function we will use to call to trigger the flash swap transaction.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;uniswapV2Call():&lt;/strong&gt; This is the function that the Uniswap calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--7ajeDBzi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6xko9loyzzp4npe2oye.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--7ajeDBzi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m6xko9loyzzp4npe2oye.png" alt="CodeBlock" width="800" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Writing the **testFlashSwap&lt;/em&gt;* function:*&lt;/p&gt;

&lt;p&gt;This function will take 2 parameters (A) the token that is to be borrowed from Uniswap {the address| and (B) the amount we want to borrow.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;First thing that we’ll do is, check that the pair contract for _&lt;em&gt;tokenBorrow&lt;/em&gt; and &lt;em&gt;WETH&lt;/em&gt; exists. We can do that by calling the &lt;em&gt;getPair&lt;/em&gt; function on &lt;em&gt;UniswapV2Factory
NOTE: In Uniswap v2, all token pairs are with WETH as one of the coin and hence, to check if a particular token is available on Uniswap, we simply check its availability with WETH.  More on what is WETH —&amp;gt;&lt;/em&gt; &lt;a href="https://weth.io/"&gt;https://weth.io/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="nx"&gt;pair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IUniswapV2Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UniswapV2Factory&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;getPair&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_tokenBorrow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;WETH&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pair&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!pair&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;{Please note, we have defined WETH as a variable in our contract already.  Please refer to our entire contract at the end}&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Inside the UniswapV2Pair, we have 2 tokens, &lt;strong&gt;token0,&lt;/strong&gt; and &lt;strong&gt;token1&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;We now will check if &lt;em&gt;_tokenBorrow&lt;/em&gt; is equal to &lt;em&gt;_token0&lt;/em&gt; or not. &lt;/p&gt;

&lt;p&gt;If the values are equal, then &lt;strong&gt;amount0Out&lt;/strong&gt; will be the _amount argument that we pass to the function, otherwise, it would be equal to zero. &lt;/p&gt;

&lt;p&gt;Similarly, we will check the same for _&lt;em&gt;token1.&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="nx"&gt;token0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IUniswapV2Pair&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;token0&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="nx"&gt;token1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IUniswapV2Pair&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;token1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;amount0Out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_tokenBorrow&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;token0&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;uint256&lt;/span&gt; &lt;span class="nx"&gt;amount1Out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;_tokenBorrow&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;token1&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As a result, either you’ll have &lt;strong&gt;amount0Out&lt;/strong&gt; equal to _amount and &lt;strong&gt;amount1Out&lt;/strong&gt; equal to 0 or vice-versa. &lt;/p&gt;

&lt;p&gt;Then we pass these amount values in Uniswap’s swap function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;bytes&lt;/span&gt; &lt;span class="nx"&gt;memory&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;abi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_tokenBorrow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;_amount&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;IUniswapV2Pair&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;swap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;amount0Out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amount1Out&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you’ll notice, this is the exact same function that we call to perform a simple swap on Uniswap. Refer to our previous article over &lt;a href="https://medium.com/uv-labs/uniswap-testing-1d88ca523bf0"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The only difference is the last input. If it is empty, then Uniswap will try a simple swap execution. &lt;/p&gt;

&lt;p&gt;If it is not empty, that is it has any data, then it would trigger a &lt;strong&gt;flashswap.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To pass in the input, we will encode the &lt;em&gt;tokenBorrow&lt;/em&gt; and &lt;em&gt;amount&lt;/em&gt; as bytes and then pass it to the swap function. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;testFlashSwap&lt;/strong&gt; function should look similar to: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6Zbdg-XR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6a4lfcyj82o6flm3la3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6Zbdg-XR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j6a4lfcyj82o6flm3la3.png" alt="CodeBlock" width="800" height="491"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Let’s write the **uniswapV2Call:&lt;/em&gt;* 🤩*&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Basic housekeeping:&lt;/em&gt; Right now, anyone can access this function, therefore the first thing that we’re going to do is check that this function can only be called by the pair contract. 
And then, we’ll also check that the sender is equal to the pair contract.
For that, use the following code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="nx"&gt;token0&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IUniswapV2Pair&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;token0&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="nx"&gt;token1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IUniswapV2Pair&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;token1&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// call uniswapv2factory to getpair &lt;/span&gt;
&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="nx"&gt;pair&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;IUniswapV2Factory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;UniswapV2Factory&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;getPair&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;token0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;token1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="nx"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;!pair&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Decoding data:&lt;/em&gt; Then, we will decode the data that is passed to us by Uniswap, this is not a mandatory step, but encouraged to do so.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt; &lt;span class="nx"&gt;tokenBorrow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;uint&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;abi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;_data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Computing fee:&lt;/em&gt; Uniswap charges 0.3% for any form of swap. Using the following code, we are computing the fee that our contract will have to bear for undertaking the flashswap.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;uint&lt;/span&gt; &lt;span class="nx"&gt;fee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;997&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nx"&gt;uint&lt;/span&gt; &lt;span class="nx"&gt;amountToRepay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;amount&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;fee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;Repayment:&lt;/em&gt; Lastly, we have to pay Uniswap the borrowed token including the fee. It can be achieved by using the following code.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;IERC20&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tokenBorrow&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;amountToRepay&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That completes our &lt;strong&gt;uniswapV2Call&lt;/strong&gt; function, which would look similar to the following image: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0CwlYnZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a0cyxxwpq4t0jsvtqyf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0CwlYnZR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6a0cyxxwpq4t0jsvtqyf.png" alt="CodeBlock" width="800" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, our flashSwap contract is complete, and should be similar to this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0PsKaVTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dstldd9yhk5m2zq5a2q9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0PsKaVTO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dstldd9yhk5m2zq5a2q9.png" alt="CodeBlock" width="800" height="1299"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Let’s write some Test Script for our Contract
&lt;/h2&gt;

&lt;p&gt;First of all, we will import the necessary libraries, ERC20 abi, and will also create a basic structure of our test script. &lt;/p&gt;

&lt;p&gt;Use the following reference to get a better understanding: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZgZm-Th--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqequtxcihccymyqbhnb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3ZgZm-Th--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jqequtxcihccymyqbhnb.png" alt="CodeBlock" width="800" height="380"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Now, we will define the address of the contract which we’re going to impersonate and the USDC address.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We will also define the amount that we’re going to borrow.&lt;/p&gt;

&lt;p&gt;Use the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;USDCHolder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0x3f5CE5FBFe3E9af3971dD833D26bA9b5C936f0bE&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;USDCAddress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;borrowAmount&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1000000000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// since USDC is 6 decimals, this corresponds to 1000 USDC Coins&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Next, we will begin with the &lt;code&gt;before&lt;/code&gt; block use the contract we created and deploy it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="nx"&gt;before&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TestFlashSwapFactory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getContractFactory&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;flashSwap&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;TestFlashSwapContract&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;TestFlashSwapFactory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;deploy&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;TestFlashSwapContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;deployed&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally, we write our test script to check our Flash swap execution.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A: First, we will impersonate the account which we want to use:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;hre&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;network&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;provider&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;request&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
            &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hardhat_impersonateAccount&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="na"&gt;params&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;USDCHolder&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;impersonateSigner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getSigner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;USDCHolder&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;B: Then, we will define the USDC Contract&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;USDCContract&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;ethers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Contract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;USDCAddress&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;ERC20ABI&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;impersonateSigner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;C: We already knew that Uniswap charges a fee to implement a Flash Swap. Therefore, we will calculate the value of the fee.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;fee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(((&lt;/span&gt;&lt;span class="nx"&gt;borrowAmount&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;997&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;D: We need to understand that, since our contract just got deployed in the &lt;code&gt;before&lt;/code&gt; block, it does not have any Ether or any USDC. Then, once the flash loan is  implemented, the contract has to return the borrowed amount plus the fee. &lt;/p&gt;

&lt;p&gt;Therefore, we have to transfer the amount of the fee from the impersonated account to our contract, in order to complete the trade.  &lt;/p&gt;

&lt;p&gt;Therefore, we will use the following command to transfer the fee to the contract:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;USDCContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;impersonateSigner&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;transfer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TestFlashSwapContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;fee&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;D: Then, we will call the &lt;strong&gt;testFlashSwap&lt;/strong&gt; function which we have defined in our contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;TestFlashSwapContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;testFlashSwap&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;USDCContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;borrowAmount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;E: It’s time to check whether the Flashswap executed was correct or not. For that, we will check whether the balance of our contract, after the flashswap and the payment of the exact fee that we computed is 0, as it should be, or not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TestFlashSwapContractBalance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;USDCContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;balanceOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TestFlashSwapContract&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TestFlashSwapContractBalance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;eq&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;BigNumber&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))).&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;be&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your final test script should look like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YUSZR3Zj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pusik4sjjxztes4gqemt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YUSZR3Zj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pusik4sjjxztes4gqemt.png" alt="CodeBlock" width="800" height="684"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, run your test in your CLI using the command &lt;code&gt;npx hardhat test tests/flashswaptest&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The result should look like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gwKKpCtJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy1jrkseqr94k9t5f201.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gwKKpCtJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xy1jrkseqr94k9t5f201.png" alt="CodeBlock" width="800" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Voila&lt;/em&gt;&lt;/strong&gt; 🥳🥳🥳 ****&lt;em&gt;Our&lt;/em&gt; flashswap passed with flying colours 🤣 &lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;Flash swap allows you to borrow any ERC20 token on Uniswap and execute any code logic, as long as you repay the same token or any other token of the same value plus the fee &lt;strong&gt;in the same transaction&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Hope you like our efforts and try and run this by yourselfs. :)&lt;/p&gt;

&lt;p&gt;Of course! If you get any error, you can ask us by tagging &lt;a href="https://twitter.com/uv_labs"&gt;@uv_labs&lt;/a&gt; on Twitter.&lt;/p&gt;

&lt;p&gt;Again, all the code that we just ran through is over here 👉 &lt;a href="https://github.com/UV-Labs/Tutorials"&gt;Github repository&lt;/a&gt;. Do give us a star if you liked our work.&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Converting GitHub to your local IDE #Productivity</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Tue, 05 May 2020 07:35:42 +0000</pubDate>
      <link>https://dev.to/a_mature_dev/converting-github-to-your-local-ide-productivity-29c</link>
      <guid>https://dev.to/a_mature_dev/converting-github-to-your-local-ide-productivity-29c</guid>
      <description>&lt;p&gt;This is a cross-post so to say.  This is just putting out a blog post of the video that has been done up by LevelUp Tutorials over &lt;a href="https://youtu.be/0r2JwANUZwo"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Objective of this post&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;This is more like a productivity post.  I am a big-time sucker for productivity-improving tools.  Now, at present, I am running multiple development projects.  There is &lt;a href="http://zapper.fi"&gt;Zapper.fi&lt;/a&gt; (aka DeFiZap), then I have my day job, and lastly various side projects most of them related to blockchain stuff, to keep improving my knowledge base and stuff.&lt;/p&gt;

&lt;p&gt;So with that in place, I keep finding my help navigating through Github more often than not.   In this post, I am listing down the amazing tools that were (for me) discovered by &lt;a href="https://twitter.com/stolinski"&gt;Scott Tolinski&lt;/a&gt;.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You MUST note that each of these tools is chrome extensions which modify the manner in which you will be surfing &lt;a href="http://github.com"&gt;GitHub.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tool 1&lt;/em&gt;: GitHub Dark Theme&lt;/p&gt;

&lt;p&gt;Now this one needs no explanation; the name suffices to say what it does.  I love it, it just makes me so comfortable looking at the dark GitHub; somehow it adds to the 'feel home factor' (more on this feel below).  It is available over &lt;a href="https://chrome.google.com/webstore/detail/github-dark-theme/odkdlljoangmamjilkamahebpkgpeacp?hl=en"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tool 2&lt;/em&gt;: File Icon for GitHub and GitLab&lt;/p&gt;

&lt;p&gt;Again another super simple cool tool that needs no explanation.  Just look at the screenshot below (as they say, a picture says a 1000 words): &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EvbBc-Ga--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iof2e3kocbw8wu46whb7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EvbBc-Ga--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/iof2e3kocbw8wu46whb7.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It just makes the browsing experience so easy!&lt;/p&gt;

&lt;p&gt;This one is available over &lt;a href="https://chrome.google.com/webstore/detail/file-icon-for-github-and/ficfmibkjjnpogdcfhfokmihanoldbfe?hl=en"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tool 3&lt;/em&gt;: Enhanced GitHub&lt;/p&gt;

&lt;p&gt;Did you ever come across a thought "Oh man, I wish, I could just download this one file from this repo, rather than clone the entire repo" or like "oh man, I need to copy the contents of this file, damn, click raw and then select all and then copy"; "damn, I need something to make this easier for me".  Well, I think, I keep bumping into this request everyday and boom! Enhanced GitHub solves this!!&lt;/p&gt;

&lt;p&gt;One more screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FZI3dV_V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/KNRRv3ZbPX9CaSewQXxQCu2nEGWQVyYD4JD-w5268inO3vj79BGKyhkKLWSbhrrE4EinoRPOhE8%3Dw640-h400-e365" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FZI3dV_V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/KNRRv3ZbPX9CaSewQXxQCu2nEGWQVyYD4JD-w5268inO3vj79BGKyhkKLWSbhrrE4EinoRPOhE8%3Dw640-h400-e365" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;oh man, I cannot explain how much I love this tool! &lt;/p&gt;

&lt;p&gt;This one is available over &lt;a href="https://chrome.google.com/webstore/detail/enhanced-github/anlikcnbgdeidpacdbdljnabclhahhmd?hl=en"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tool 4&lt;/em&gt;: Octotree&lt;/p&gt;

&lt;p&gt;As this tool defines itself, it converts Github to &lt;em&gt;Github on steroids&lt;/em&gt;.  Boy-o-boy, this tool is so cool.  It practically converts my Github to like VSCode window.  Here take a look:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Kqab2G3q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/brPmG2MHTBE-eYZsMZWMYZOkE1_VgDRDXFkcTFqYIKSUvWiWzk7QScxruZ7NQ9aBo42m3l5soA%3Dw640-h400-e365" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Kqab2G3q--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://lh3.googleusercontent.com/brPmG2MHTBE-eYZsMZWMYZOkE1_VgDRDXFkcTFqYIKSUvWiWzk7QScxruZ7NQ9aBo42m3l5soA%3Dw640-h400-e365" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Damn bruh! Is that not sick!  I can browse through files like magic and have a mind map of what is happening where.  This crazy cool tool is available &lt;a href="https://chrome.google.com/webstore/detail/octotree/bkhaagjahfmjljalopjnoealnfndnagc?hl=en"&gt;here&lt;/a&gt;.  Looking at GitHub as if it is VSCode makes me feel home, makes me feel I have so much control over the code.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Tool 5&lt;/em&gt;: Sourcegraph&lt;/p&gt;

&lt;p&gt;Last in my list, but in no fashion the least is Sourcegraph. &lt;/p&gt;

&lt;p&gt;I am browsing through code and then there is a funny import or require, and I am like, ok, now what's written in that file; Sourcegraph just makes jumping to the relevant file so easy.  Again, similar to my VSCode experience; something again that makes me feel home.  &lt;/p&gt;

&lt;p&gt;The last screenshot that I would like to share: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fNO7xsIf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p50cmyxw09hzqcj7hvms.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fNO7xsIf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/p50cmyxw09hzqcj7hvms.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Crazy right! This marvelous magical tool is available over &lt;a href="https://chrome.google.com/webstore/detail/sourcegraph/dgjhfomjieaadpoljlnidmbgkdffpack?hl=en"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I hope you like all of the above and use it.  If you have any other cool tools to use, please comment out below.  As I mentioned above, I am into productivity tools; would love to use anything that supports by laziness ;)&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

&lt;p&gt;AD&lt;/p&gt;

</description>
      <category>github</category>
      <category>productivity</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Flash Loans | Make profit in almost 14 secs - if you are smart enough. People have already started doing it.</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Sun, 23 Feb 2020 07:00:38 +0000</pubDate>
      <link>https://dev.to/a_mature_dev/flash-loans-make-profit-in-almost-14-secs-if-you-are-smart-enough-people-have-already-started-doing-it-3hge</link>
      <guid>https://dev.to/a_mature_dev/flash-loans-make-profit-in-almost-14-secs-if-you-are-smart-enough-people-have-already-started-doing-it-3hge</guid>
      <description>&lt;p&gt;&lt;em&gt;Assumption&lt;/em&gt;:&lt;br&gt;
Another one of my quick notes =&amp;gt; I assume that you (the reader) understands Blockchain [Ethereum specifically], smart contracts and &lt;em&gt;DeFi&lt;/em&gt; (aka decentralised finance).  If not, this will be tough to follow and hence, advisable to dig about these first and come back over here.&lt;/p&gt;

&lt;h3&gt;
  
  
  DeFi - in one sentence (almost):
&lt;/h3&gt;

&lt;p&gt;Traditional financial system of (a) lending, (b) borrowing, (c) doing something with the borrowed money, (d) repaying loans - but only by and for &lt;strong&gt;blockchain assets&lt;/strong&gt;, through &lt;strong&gt;smart contracts&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Flash Loan?
&lt;/h2&gt;

&lt;p&gt;A loan (yes, like a very traditional loan) that is taken out and paid out in 1 blockchain transaction [typically in ~14 secs].&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Flash Loans?
&lt;/h2&gt;

&lt;p&gt;From the lenders' point of view: almost safe (my bet is 100%), principal and interest is received back instantly (well, ~14 secs and interest income.&lt;/p&gt;

&lt;p&gt;From the borrowers' point of view: Can borrow a very very high amount, as far as I know what I am doing, &lt;strong&gt;no collateral required&lt;/strong&gt;, &lt;strong&gt;no collateral required&lt;/strong&gt; (again!!!), instant.&lt;/p&gt;

&lt;h2&gt;
  
  
  How does it work?
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Blockchain Transaction:
&lt;/h4&gt;

&lt;p&gt;On the Ethereum blockchain, everything that happens is a transaction.  For eg:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If Alice sends Bob an Ether (aka ETH) it is a transaction.
&lt;/li&gt;
&lt;li&gt;If I write a smart contract that will the ETH that I give it and transfer it to Alice and Bob in two equal halves, it is &lt;strong&gt;a&lt;/strong&gt; transaction.
&lt;/li&gt;
&lt;li&gt;If a Smart Contract 

&lt;ul&gt;
&lt;li&gt;takes ETH, &lt;/li&gt;
&lt;li&gt;looks up the price of gold on the LSE, &lt;/li&gt;
&lt;li&gt;buys appropriate amount of Gold Tokens, &lt;/li&gt;
&lt;li&gt;holds it for 30 mins, &lt;/li&gt;
&lt;li&gt;relooks at the value of gold on LSE, &lt;/li&gt;
&lt;li&gt;sells the Gold Tokens, &lt;/li&gt;
&lt;li&gt;gives out the proceeds back to the user who deposited the ETH, &lt;/li&gt;
&lt;li&gt;after computing a brokerage and then transferring the brokerage to my account - 
it is also &lt;strong&gt;a&lt;/strong&gt; transaction (1 Single transaction).&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;of the above three examples, the last two can be a single transaction or can be broken into multiple transactions; they do not have to be 1 single transaction - it is the manner in which the transaction is defined and designed in a Smart Contract.&lt;/p&gt;

&lt;h4&gt;
  
  
  Flash Loan Capable Smart Contracts (the core of this entire article / blog post)
&lt;/h4&gt;

&lt;p&gt;So flash loan smart contracts are written up in a manner that anyone (literally anyone; Yes, any darn one!) can (for ease of understanding), submit a transaction which will require some amount to begin with (this is the loan / principal), do something, and pay back the loan (with some interest) at the end of the &lt;strong&gt;single&lt;/strong&gt; transaction.  &lt;/p&gt;

&lt;p&gt;More simply put, flash loan is an algorithm {loan algo}, to which I will submit my algorithm {my algo}, which will check that units that the loan algo gives (LHS) &lt;em&gt;is equal to&lt;/em&gt; the units that it gets back and the end of the execution of my algo (RHS).&lt;/p&gt;

&lt;h2&gt;
  
  
  Implications
&lt;/h2&gt;

&lt;p&gt;Now that you have some skeleton understanding of what a flash loan is and how it works - let us think and see some use cases / implications:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Eg Use Case&lt;/em&gt; You see a potential arbitrage opportunity &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;buy Stock A on local stock exchange in you local currency, &lt;/li&gt;
&lt;li&gt;transfer stock to a global custodian&lt;/li&gt;
&lt;li&gt;exchange stock units for its Global Depository Receipt (aka GDR)&lt;/li&gt;
&lt;li&gt;sell GDR in a foreign market&lt;/li&gt;
&lt;li&gt;convert foreign currency to local currency&lt;/li&gt;
&lt;li&gt;make arbitrage gains due to exchange rate difference
All executed in a matter of seconds!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;could you do this in a traditional financial world?&lt;/strong&gt;  &lt;em&gt;Answer:&lt;/em&gt; (if you are like me, a common man and not a highly rich dude and not much of an infrastructure required to execute the above): NO, you cannot.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;could you do this on the Ethereum blockchain?&lt;/strong&gt;  &lt;em&gt;Answer:&lt;/em&gt; (if you can write a smart contract): Hell YA! You can!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Any restrictions?&lt;/strong&gt;  &lt;em&gt;Answer:&lt;/em&gt; No&lt;br&gt;
&lt;strong&gt;Any KYC?&lt;/strong&gt;  &lt;em&gt;Answer:&lt;/em&gt; No&lt;br&gt;
&lt;strong&gt;Any limit on amount?&lt;/strong&gt;  &lt;em&gt;Answer:&lt;/em&gt; No (mostly)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;  &lt;em&gt;Answer:&lt;/em&gt; I can (you can)(anyone can) do transactions worth MILLIONS of USD!! make gains, faster than it would have take to load an average webpage.&lt;/p&gt;

&lt;p&gt;Eg REAL WORLD transactions: &lt;br&gt;
Eg 1: &lt;a href="https://etherscan.io/tx/0x762881b07feb63c436dee38edd4ff1f7a74c33091e534af56c9f7d49b5ecac15"&gt;Transaction 1 - click me!&lt;/a&gt;&lt;br&gt;
Eg 2: &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gIb20K-s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bf5teo9f4hk5kx704t7m.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gIb20K-s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/bf5teo9f4hk5kx704t7m.jpeg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Eg 3: &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4hwVryBT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6cgn4zshyvukln1plq5j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4hwVryBT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6cgn4zshyvukln1plq5j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I would like to know what your thoughts are on Flash Loans - are you &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lweiMFmn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.dribbble.com/users/7070/screenshots/3479734/aye-or-nay.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lweiMFmn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.dribbble.com/users/7070/screenshots/3479734/aye-or-nay.jpg" alt="Aye or Nay"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;My Opinion&lt;/em&gt;: &lt;strong&gt;WOW&lt;/strong&gt;, this is going to take the financial system to a whole new level!  I take this to be in the likes of the Apple iPhone to the mobile-phone universe: things will not be the same ever again!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Written with &lt;a href="https://stackedit.io/"&gt;StackEdit&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>blockchain</category>
      <category>ethereum</category>
      <category>smartcontracts</category>
    </item>
    <item>
      <title>ERC20 vs ERC777 | Quick Understanding and why ERC777 is not being used</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Sat, 15 Feb 2020 07:00:55 +0000</pubDate>
      <link>https://dev.to/a_mature_dev/erc20-vs-erc777-quick-understanding-and-why-erc777-is-not-being-used-4lle</link>
      <guid>https://dev.to/a_mature_dev/erc20-vs-erc777-quick-understanding-and-why-erc777-is-not-being-used-4lle</guid>
      <description>&lt;h1&gt;
  
  
  Why not ERC777?
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;&lt;em&gt;Assumption&lt;/em&gt;&lt;/em&gt;: This is one of my short and quick articles.  There is a assumption over here that you (the reader) is aware of Blockchain, Ethereum, Solidity and Tokens.  If you do not understand these terms this article will not be of much help to you.  You should dig-up these terms and possibly come back over here.&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;The Ethereum blockchain is filled with tons and tons of &lt;em&gt;&lt;em&gt;tokens&lt;/em&gt;&lt;/em&gt;.  Pretty much every &lt;em&gt;&lt;em&gt;fungible&lt;/em&gt;&lt;/em&gt; token is as per the ERC20 Standard (some of them may be ERC223, which is an extension of the ERC20 token standard).  &lt;/p&gt;

&lt;p&gt;I have been working with loads of such tokens at &lt;a href="//defizap.com"&gt;DeFiZap.com&lt;/a&gt;.  One of the biggest issue that an ERC20 Token has is that it lacks (of what I would call) hooks / event triggers.  Let me explain through an example below:&lt;/p&gt;

&lt;p&gt;If Alice were to send Ether to a Smart Contract, the Smart Contract will be made aware of this incoming Ether (through various functions).  This &lt;em&gt;&lt;em&gt;made aware&lt;/em&gt;&lt;/em&gt; nature of the Ether within the Ethereum blockchain is what I call, hooks / event triggers.&lt;/p&gt;

&lt;p&gt;However, if Alice were to send &lt;a href="https://coinmarketcap.com/currencies/multi-collateral-dai/"&gt;Dai&lt;/a&gt; to a Smart Contract; the Smart Contract will NOT be made aware of this transfer.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why not made aware?
&lt;/h3&gt;

&lt;p&gt;To understand why the Smart Contract will NOT be made aware, we will have to understand ONE of the CORE ideas of an ERC20 Token. The long story short version is that the word 'transfer' is actually the root cause (that is how I see it).  &lt;/p&gt;

&lt;p&gt;Essentially, an ERC20 Tokens does not literally move from one wallet address to another (or smart contract to smart contract); only the &lt;em&gt;&lt;em&gt;so-called&lt;/em&gt;&lt;/em&gt; owner of the ERC20 is changed inside the Smart Contract that is the issuer of the ERC20.  In simple sense, if someone in Monaco has allocated a Ferrari in my name, a transfer would just be like the Ferrari stays there, only the name of the owner of that Ferrari is changed from my name to (lets say) Spider-Man.  Now, sadly our dear Friendly Neighbourhood Spider-Man was not informed of this and thus, was NOT made aware.&lt;/p&gt;

&lt;h3&gt;
  
  
  So what is the issue with that?
&lt;/h3&gt;

&lt;p&gt;As is the case above, since Spider-Man did not know, he did not come to collect the car and drive it off to his own world.  Same way, if the Smart Contract or a Wallet is not aware that is owns the ERC20 Token it cannot do anything.&lt;/p&gt;

&lt;h3&gt;
  
  
  What would the Smart Contract do with it anyway?
&lt;/h3&gt;

&lt;p&gt;While there are tons of uses, one of the most common is to swap it for something else.  For eg, converting &lt;a href="https://coinmarketcap.com/currencies/multi-collateral-dai/"&gt;Dai&lt;/a&gt; to &lt;a href="https://medium.com/compound-finance/compound-multi-collateral-dai-57b803f86cc9"&gt;cDAI&lt;/a&gt;.  &lt;/p&gt;

&lt;h3&gt;
  
  
  HackyWay used currently?
&lt;/h3&gt;

&lt;p&gt;The way the above &lt;em&gt;&lt;em&gt;made aware&lt;/em&gt;&lt;/em&gt; is currently resolved is (a) allowing the cDAI Smart Contract to use the DAI that I own (through a function known as &lt;em&gt;&lt;em&gt;approve&lt;/em&gt;&lt;/em&gt;) and (b) informing cDAI (through a function call) that you are now approved to use my DAI, please take it, swap it and issue cDAI to me (and literally, to my name in your ownership register).  That means two (2) transactions.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is the issue?
&lt;/h3&gt;

&lt;p&gt;Bluntly, I do not like 2 transactions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why ERC777?
&lt;/h3&gt;

&lt;p&gt;Easy to guess, similar to ERC20, ERC777 is also a standard for developing tokens on the Ethereum Blockchain.  The standard has built in provisions for the &lt;em&gt;&lt;em&gt;made aware hooks&lt;/em&gt;&lt;/em&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adoptability
&lt;/h3&gt;

&lt;p&gt;Now, since the first time I read about ERC777 I fell in love with it.  I design Smart Contracts that deal with ERC20 and as of now, I have to keep asking my users to approve my smart contract address first and then call a function my smart contract that will do what they need to do.&lt;/p&gt;

&lt;p&gt;Hence, I was so much pushing for all token designers to look into ERC777 and use that standard.  The odd part is that the standard has been in out since 2017 and yet not 1 token in the market uses ERC777.  This made me wonder &lt;em&gt;&lt;em&gt;why&lt;/em&gt;&lt;/em&gt;, till obviously, I went ahead to work on my own ERC777.&lt;/p&gt;

&lt;h3&gt;
  
  
  Answer
&lt;/h3&gt;

&lt;p&gt;ERC777 is a larger and comprehensive scheme. One of the drawback of gaining the functionality of the hooks / event triggers is the manner in which the recipient smart contract is designed.  Essentially, the recipient smart contract (note!!!, it this drawback is only applicable to smart contracts and NOT to EOA wallets)need to have a function which will listen to such transfer.&lt;/p&gt;

&lt;p&gt;Sadly, the world has moved on and no-one in the legacy smart contract world ever designed their contracts with this functionality.  Now, since those contracts are not upgradable, they will never be in compliant with ERC777 standard.  Thus, with that said, we now know why no one is using the powerful, yet powerless ERC777 coin standard.&lt;/p&gt;

</description>
      <category>ethereum</category>
      <category>blockchain</category>
      <category>smartcontracts</category>
    </item>
    <item>
      <title>Defining Roles in Smart Contract</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Tue, 04 Feb 2020 04:48:15 +0000</pubDate>
      <link>https://dev.to/a_mature_dev/defining-roles-in-smart-contract-19l4</link>
      <guid>https://dev.to/a_mature_dev/defining-roles-in-smart-contract-19l4</guid>
      <description>&lt;p&gt;This is a quick and short article that I wanted to get out of my drafts.  There is a big presumption over here that you are aware of what blockchain and smart contract is.  If you are not aware of these concepts, I will have to request you to hunt these concepts down or put in a comment below and I will guide you through it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do we need Roles?
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Fact: Blockchain is like an immutable database.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Given this fact, if you are a dev who is into developing smart contracts specially for the ethereum world, then you are already aware that smart contracts are (by strict definition) not upgradable.  That is to say, once they are deployed they will stay there forever and you will not have the option to modify the code.&lt;/p&gt;

&lt;p&gt;With that in mind, Smart Contract developers design different methods in which some functions within the Smart Contracts are only available to certain wallet/public addresses.  &lt;/p&gt;

&lt;p&gt;This is mostly from a security point of view.&lt;/p&gt;

&lt;p&gt;EG: The most commonly used type of Smart Contract where only a few accounts are permitted to do certain actions are "Multi-Sig Wallets". &lt;/p&gt;

&lt;h2&gt;
  
  
  What are Roles?
&lt;/h2&gt;

&lt;p&gt;In the simplest terms, Roles are like what you would see in a movie/act/play/game.  Each wallet address is assigned a character and each character has a limited set of power or an advantage, depending on what and how you define that character in the Smart Contract.&lt;/p&gt;

&lt;h2&gt;
  
  
   How to do it?
&lt;/h2&gt;

&lt;p&gt;Without a doubt, you are free to define your own mechanisms to implement this; however, I find OpenZeppelin's &lt;a href="https://docs.openzeppelin.com/contracts/2.x/access-control#role-based-access-control"&gt;Roles based framework&lt;/a&gt; really useful for asap development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quick Code Example
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pragma solidity ^0.5.0;

import "@openzeppelin/contracts-ethereum-package/contracts/access/Roles.sol";

///@author amateurdev

contract TestingRoles  {
    using Roles for Roles.Role;

    // state variables
    Roles.Role private _adders;
    Roles.Role private _subtractors;

    uint16 public ini_number;

    constructor(address adder, address subtractor, uint16 _ini_number)
        public
    {
        ini_number = _ini_number;
        _adders.add(adder);
        _subctractors.add(subtractor);
    }

    function add(uint16 _number) public returns (uint256) {
        require(_adders.has(msg.sender), "It is not an adder");
        ini_number = ini_number + _number;
        return ini_number;
    }

    function sub(uint16 _number) public returns (uint256) {
        require(_subtractors.has(msg.sender), "It is not an subtractor");
        require(_number &amp;lt;= ini_number);
        ini_number = ini_number - _number;
        return ini_number;
    }

}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The above code is a real quick smart contract which will help you test out the power of the Open Zeppelin's Roles Library/Contract.&lt;/p&gt;

&lt;p&gt;Essentially, what we are doing is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;at the time of deployment of this contract&lt;/li&gt;
&lt;li&gt;defining two addresses (ideally should be different) one of which has the 'power' to add and the other one has the 'power' to subtract&lt;/li&gt;
&lt;li&gt;setting up an initial value of the test/dummy number&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Post the deployment, (obviously) only the adders will be able to add and only the subtractors will be able to reduce the number.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;I am not going into how to deploy it or test it, with the objective to not drag this article.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How is this helpful?
&lt;/h2&gt;

&lt;p&gt;(a) I cannot thank enough to &lt;a href="https://openzeppelin.com/"&gt;Open Zeppelin&lt;/a&gt; and their team for doing the basic groundwork. Using Open Zeppelin's infrastructure, the development time for Smart Contract is like half of what it would take otherwise.  Above is a quick example of that.&lt;/p&gt;

&lt;p&gt;(b) I keep facing situations where I have to develop Smart Contracts in which different parties are involved which have different vested interests.  Thus, using the above, I am able to define functions that can be used by the respective parties within their limitations.&lt;/p&gt;

</description>
      <category>solidity</category>
      <category>smartcontract</category>
      <category>blockchain</category>
    </item>
    <item>
      <title>What is the Libra Coin and Network. Quick Bullet pointers</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Wed, 18 Sep 2019 03:07:37 +0000</pubDate>
      <link>https://dev.to/a_mature_dev/what-is-the-libra-coin-and-network-quick-bullet-pointers-3f50</link>
      <guid>https://dev.to/a_mature_dev/what-is-the-libra-coin-and-network-quick-bullet-pointers-3f50</guid>
      <description>&lt;h2&gt;
  
  
  High-level overview
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Main Governing body is the &lt;em&gt;Council&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;Libra reserve is the membership fee that the entities have to pay to be a part of the council&lt;/li&gt;
&lt;li&gt;The reserve fee is US$10 million&lt;/li&gt;
&lt;li&gt;The reserve will be giving out interest return to the members&lt;/li&gt;
&lt;li&gt;Every1 in the organization/council must interact with the Libra blockchain using the Libra core software&lt;/li&gt;
&lt;li&gt;Libra Core software is open source&lt;/li&gt;
&lt;li&gt;The Council also has something known as an Advisory Board - these are external / no-conflict-of-interest educational institutions&lt;/li&gt;
&lt;li&gt;The Network will be maintained and run by a Validator Node - which initially will be formed by the first participants in the Council&lt;/li&gt;
&lt;li&gt;Libra Users will have a hexadecimal addresses&lt;/li&gt;
&lt;li&gt;Calibra - FB's digital wallet platform&lt;/li&gt;
&lt;li&gt;This will be used to submit the transaction to the network&lt;/li&gt;
&lt;li&gt;It will be integrated to all the FB products (eg Instagram)&lt;/li&gt;
&lt;li&gt;To make sure that Libra is Open Source, there is a likely hood that there will be other wallets as well&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Little Deeper Dive
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Libra Association and the Reserve
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;The documentation and the framework is still in discussion mode&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Stable Coin:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Backed by the membership fee collected

&lt;ul&gt;
&lt;li&gt;1 : 1 asset-backed ("Basket of Fiat Currencies")&lt;/li&gt;
&lt;li&gt;Most of the assets will be low volatility assets, eg, Government Debts&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;New Libra Coins will be minted on 1:1 deposit of fiat currencies by any user of the FB / Libra network [Question, how will the unstable currencies be valued to be able to mind LC]&lt;/li&gt;
&lt;li&gt;There will be very less direct interaction with the reserve; a portion of the LC from the reserves will be sold to Authorized Resellers&lt;/li&gt;
&lt;li&gt;The AR will then be one of the important points of functioning in the local market&lt;/li&gt;
&lt;li&gt;It is expected that the AR will be responsible for managing the compliance with local regulations &lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Regulatory
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Couple of Global regulatory organizations have expressed concerns&lt;/li&gt;
&lt;li&gt;India, China, and Germany have explicitly mentioned that they will NOT be permitting the use of LC within their geography&lt;/li&gt;
&lt;li&gt;China is apparently working on its on own cryptocurrency (&lt;em&gt;though is is surprising and not surprising for its own reason!!!&lt;/em&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Technical Part
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;Libra Core is written Rust&lt;/li&gt;
&lt;li&gt;Rust has garnered a lot of attention due to its speed&lt;/li&gt;
&lt;li&gt;Transactions will Gas for execution&lt;/li&gt;
&lt;li&gt;Transaction will have:

&lt;ul&gt;
&lt;li&gt;Sender Address&lt;/li&gt;
&lt;li&gt;Program (A Move Language Byte Code)&lt;/li&gt;
&lt;li&gt;Gas Price&lt;/li&gt;
&lt;li&gt;Maximum Gas Amount&lt;/li&gt;
&lt;li&gt;Sequence Number&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Proof of Stake&lt;/li&gt;
&lt;li&gt;Likely hood of having randomness in selecting a leader validator node&lt;/li&gt;
&lt;li&gt;LibraBFT:

&lt;ul&gt;
&lt;li&gt;All calls to the network will be through &lt;code&gt;Admission Control&lt;/code&gt;; which will be made available only through the Council&lt;/li&gt;
&lt;li&gt;Admission Control will accept 2 kinds of calls: &lt;code&gt;Query&lt;/code&gt; and &lt;code&gt;Transactions&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt; Move Programming Language

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;Unique Ownership&lt;/code&gt; Any resource within the network cannot be copied, it can only 'move' within the network&lt;/li&gt;
&lt;li&gt;`No 3rd Party "Modules" (loosely read Smart Contracts) will not be accepted immediately&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hope you liked this quick bullet point discussion.  Feel free to throw in any question that you may have on Libra Coin.  Personally, I am quite excited about it and would love for it to come to life.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Written with &lt;a href="https://stackedit.io/"&gt;StackEdit&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>libra</category>
      <category>crypto</category>
      <category>coin</category>
      <category>facebook</category>
    </item>
    <item>
      <title>Deploy your webpage in just *1 (ONE)* command</title>
      <dc:creator>a_mature_dev</dc:creator>
      <pubDate>Wed, 18 Sep 2019 03:00:51 +0000</pubDate>
      <link>https://dev.to/a_mature_dev/deploy-your-webpage-in-just-1-one-command-abo</link>
      <guid>https://dev.to/a_mature_dev/deploy-your-webpage-in-just-1-one-command-abo</guid>
      <description>&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;  Create an account on &lt;a href="https://zeit.co/"&gt;Zeit&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;  Install the &lt;code&gt;NOW&lt;/code&gt; npm package&lt;/li&gt;
&lt;li&gt;  Go to the repo that you want to deploy, in the terminal&lt;/li&gt;
&lt;li&gt;  Execute the command &lt;code&gt;now&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;  Vola!! You should be done.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3og0IAQG2BtR13joe4/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3og0IAQG2BtR13joe4/giphy.gif" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Background
&lt;/h2&gt;

&lt;p&gt;I started to learn to code sometime back.  Sticking to the traditions, my journey began with dipping my toes in HTML → CSS → JavaScript and beyond.  &lt;/p&gt;

&lt;p&gt;As many may agree, self-learning coding is a little tough.  While you need to be disciplined, the most painful is to know what to learn to code and when.  More often than not, I would find myself staring at a topic that I did not know anything about and then there I go in the &lt;em&gt;rabbit hole&lt;/em&gt;.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Deployment of Projects
&lt;/h2&gt;

&lt;p&gt;During this entire learning process, which is still on btw, the one thing that I wanted to be a pro at is the deployment of my projects. &lt;/p&gt;

&lt;p&gt;You can safely assume that I spent countless hours trying to nail it.  Long story short, after a lot and lot of time spent, the following helped me in seeing my projects come to life:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Github Pages (for static websites)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.heroku.com/"&gt;Heroku&lt;/a&gt; (for complicated NodeJS or Flask projects)

&lt;ul&gt;
&lt;li&gt;  First through the deployment of docker containers (as for some reason this felt the easiest), and then through&lt;/li&gt;
&lt;li&gt;  Heroku Git (Yes! It's very likely I went the reverse order from learning the complicated route first)&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, both the above routes (only from the perspective of deployment) have its own learning curve and trust me, as a new coder and super eager to see my project come to life on the internet, I was somewhere, irritated with the learning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to &lt;code&gt;ZEIT Now&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;I was playing out with &lt;a href="https://svelte.dev/"&gt;Svelte&lt;/a&gt; -  just the &lt;em&gt;hello world&lt;/em&gt; to begin with - and during this playing around, their documentation gave this command - to deploy your app follow the command &lt;code&gt;now&lt;/code&gt; and I was intrigued.  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;ZEIT Now is a cloud platform for static sites and serverless functions. It enables developers to host websites and web services that deploy instantly, scale automatically, and requires no supervision, all with no configuration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  So what is this one command to deploy
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;now&lt;/code&gt; - that is it to deploy your project.  However, minor steps to reach that stage are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  you need to have an account with zeit&lt;/li&gt;
&lt;li&gt;  in the terminal you need to have done &lt;code&gt;now login&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;once these 2 steps are done, you are all set&lt;/p&gt;

&lt;p&gt;Use the command &lt;code&gt;now&lt;/code&gt; in the terminal and it will prepare your site and make it live in almost 1 min.&lt;/p&gt;

&lt;h2&gt;
  
  
  Next Steps
&lt;/h2&gt;

&lt;p&gt;After this stage, I was tempted to getting my site a proper domain name and make it live as a production website.  Since Zeit gives you the option to buy a domain and connect it to your webpage.  I will be writing a separate blog on this topic; it is a bit more technical.&lt;/p&gt;

&lt;p&gt;Till then, have fun and keep coding!!&lt;/p&gt;

&lt;p&gt;Signing-off&lt;br&gt;
&lt;em&gt;Amateur-Dev&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Written with &lt;a href="https://stackedit.io/"&gt;StackEdit&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>webdev</category>
      <category>codenewbie</category>
      <category>deployment</category>
      <category>easy</category>
    </item>
  </channel>
</rss>
