<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ ethereum blockchain - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ ethereum blockchain - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 10:50:08 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/ethereum-blockchain/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Break into Ethereum, Crypto, and Web3 as a Developer ]]>
                </title>
                <description>
                    <![CDATA[ By Nader Dabit Lately, I've been talking about my move into the Web3, Ethereum, and crypto space since making the switch from a traditional web, mobile, and cloud background. Since making that move, a shocking number of people have reached out to me ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/breaking-into-ethereum-crypto-web3-as-a-developer/</link>
                <guid isPermaLink="false">66d460407df3a1f32ee7f86f</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Career Change ]]>
                    </category>
                
                    <category>
                        <![CDATA[ crypto ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ethereum blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web3 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 18 May 2021 21:04:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/05/break-into-blockchain-article.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Nader Dabit</p>
<p>Lately, I've been <a target="_blank" href="https://twitter.com/dabit3/status/1391171104757125122">talking</a> about <a target="_blank" href="https://twitter.com/dabit3/status/1379157277660299264">my move</a> into the <a target="_blank" href="https://ethereum.org/en/developers/docs/web2-vs-web3/">Web3</a>, Ethereum, and crypto space since making the switch from a traditional web, mobile, and cloud background.</p>
<p>Since making that move, a shocking number of people have reached out to me who are also thinking about doing the same. </p>
<p>It's really great to see so many other people interested in these fields. And if I'm being honest – it feels validating to know that so many others are also on the fence and are so deeply interested in the space as well.</p>
<p>As for me, I was nervous about making the career switch. Moving into a completely new area of specialization, with a technology I was still getting ramped up on, and a community I was not yet involved with, was a big leap. Especially compared to a very comfortable role with a FAANG company that paid really well (and a team that I really loved).</p>
<p>After over a month, I have zero regrets with the change. I'm also the happiest I've been in a long time, and am excited and energized about the things I have the opportunity to work on everyday.</p>
<p>I decided to write this post to give a blueprint for anyone looking to get into blockchain, crypto, Ethereum, and Web3 from a traditional development background. I can point people to this blog post the next time I get asked how to get into the space.</p>
<h3 id="heading-ill-break-this-article-up-into-a-few-main-parts">I'll break this article up into a few main parts:</h3>
<ol>
<li>Technologies and resources to learn</li>
<li>Tradeoffs and considerations</li>
<li>People to follow</li>
<li>Companies hiring and doing interesting stuff</li>
<li>General tips and landing a job</li>
</ol>
<p>Let's dive in.</p>
<h2 id="heading-technologies-and-resources-to-learn-about-ethereum-and-blockchain">Technologies and Resources to Learn About Ethereum and Blockchain</h2>
<p>What I'm most interested in is usually a function of where I predict technology will be in the near future and where I see the current momentum being. So that's what I will focus on here (and this is what I am doing personally).</p>
<p>To me, the most exciting parts of this space are decentralization, <a target="_blank" href="https://blog.coinbase.com/a-beginners-guide-to-decentralized-finance-defi-574c68ff43c4">DeFi</a>, <a target="_blank" href="https://docs.ethhub.io/ethereum-basics/governance/">governance</a> / <a target="_blank" href="https://www.investopedia.com/tech/what-dao/">DAOs</a>, and <a target="_blank" href="https://www.youtube.com/watch?v=j2rXJLW_93o">decentralized web infrastructure</a>.</p>
<p>Because of this, I'm focusing on both Ethereum development and Solidity. With the Solidity programming language ,you can program smart contracts for Ethereum as well as for many other <a target="_blank" href="https://chainid.network/">EVM compatible blockchains</a>. </p>
<p>As of this writing, Ethereum also has the powerful and important combination of momentum, developer mindshare, and existing production <a target="_blank" href="https://everest.link/">dapps</a>.</p>
<p>Ethereum is also currently moving to a new consensus mechanism, <a target="_blank" href="https://ethereum.org/en/developers/docs/consensus-mechanisms/pos/">proof of stake</a>. This addresses the environmental concerns I used to have about how cryptocurrency works at a core level.</p>
<p>Once you learn how everything works fundamentally, I encourage you to then check out other blockchains and projects outside of Ethereum and EVM. </p>
<p>This will give you a better understanding of the industry as a whole. It will also help you see if there are other projects that attract you or that you believe are better approaches to achieving the goal that is Web3. </p>
<p>Consider looking into <a target="_blank" href="https://solana.com/">Solana</a>, <a target="_blank" href="https://polkadot.network/">Polkadot</a>, <a target="_blank" href="https://near.org/">Near</a>, <a target="_blank" href="https://www.avax.network/">Avalanche</a> or <a target="_blank" href="https://cosmos.network/">Cosmos</a>.</p>
<p>To get started learning blockchain development with Ethereum and Solidity, I suggest you do the following:</p>
<h3 id="heading-1-read-the-ethereum-docs">1. Read the Ethereum docs</h3>
<p>Scan through the <a target="_blank" href="https://ethereum.org/en/developers/docs/">Ethereum docs</a>. Be sure to check out the section <a target="_blank" href="https://ethereum.org/en/developers/docs/intro-to-ethereum/">Intro to Ethereum</a> as well as anything else that catches your eye.</p>
<p>Also be sure to check out the <a target="_blank" href="https://ethereum.org/en/dapps/">dapp showcase</a> to get a good understanding of the successful apps being built and used in the current ecosystem.</p>
<h3 id="heading-2-read-the-solidity-documentation">2. Read the Solidity documentation</h3>
<p>The <a target="_blank" href="https://docs.soliditylang.org/en/v0.8.4/">Solidity docs</a> are a really good place to get started, especially <a target="_blank" href="https://docs.soliditylang.org/en/v0.8.4/solidity-by-example.html">solidity by example</a>. This gives you a few examples of popular smart contracts like voting, an auction, remote purchase, and micropayments.</p>
<p>You can copy and paste these contracts in the <a target="_blank" href="https://remix.ethereum.org/">Remix IDE</a> to start executing and modifying them to see how they work.</p>
<p>I also did a video walkthrough of the voting contract <a target="_blank" href="https://www.youtube.com/watch?v=GB3hiiNNDjk">here</a>.</p>
<h3 id="heading-3-get-comfortable-with-the-remix-ide">3. Get comfortable with the Remix IDE</h3>
<p>It's really easy to play around with and start building smart contracts without having to set up any type of development environment by using the <a target="_blank" href="https://remix.ethereum.org/">Remix IDE</a>. It's part of the <a target="_blank" href="https://remix-project.org/">Remix Project</a> which is funded by the <a target="_blank" href="https://ethereum.foundation/">Ethereum Foundation</a>.</p>
<p>This Remix IDE allows you to create, edit, and execute smart contracts directly from your browser. It offers a perfect environment for learning how solidity works. It's also great for building out various types of smart contracts and playing around with them as you are learning both solidity and how to interact with Ethereum</p>
<h3 id="heading-4-try-building-out-a-full-stack-dapp">4. Try building out a full stack dapp</h3>
<p>In addition to Solidity, the other parts of the the development stack include a local Ethereum environment like <a target="_blank" href="https://hardhat.org/">Hardhat</a> or <a target="_blank" href="https://www.trufflesuite.com/">Truffle</a>, a wallet like <a target="_blank" href="https://metamask.io/">Metamask</a>, as well as a client-side library that allows you to interact with the blockchain, like either <a target="_blank" href="https://docs.ethers.io/">Ethers.js</a> or <a target="_blank" href="https://web3js.readthedocs.io/">Web3.js</a>.</p>
<p>To understand how all of this all fits together, it's useful to build out a full stack dapp on this stack from scratch. You can set up the front end project as well as the local development environment and deploy, run, and interact with a smart contract on the blockchain.</p>
<p>Here are two introductory courses to get you going with this:</p>
<ol>
<li><a target="_blank" href="https://www.youtube.com/watch?v=xWFba_9QYmc">Ethereum Programming Tutorial - DeFi, Solidity, Truffle, Web3.js</a></li>
<li><a target="_blank" href="https://www.youtube.com/watch?v=a0osIaAOFSE">The Complete Guide to Full Stack Ethereum Development</a> (<a target="_blank" href="https://www.freecodecamp.org/news/full-stack-ethereum-development/">and here it is in article form, too</a>)</li>
</ol>
<h3 id="heading-5-consider-reading-these-books">5. Consider reading these books</h3>
<p>The space itself moves very quickly, so technical books often get out of date just as quickly. The fundamentals of what Web3 is, though, have not changed much at all. </p>
<p>There are a few really great books that helped me not only grasp the current state of everything, but that also helped open my eyes to the future possibilities and opportunities that lie within it.</p>
<h4 id="heading-token-economy-how-the-web3-reinvents-the-internet">Token Economy - How the Web3 reinvents the internet</h4>
<p>If you only read one of these books, this is the one I'd say is the most important. It is a masterful deep dive into all of the shortcomings of the web as we know it, what Web3 aims to be, how it will affect various parts of our lives as we know it, and what needs to happen for this vision to be realized.</p>
<p>You can view the book <a target="_blank" href="https://shermin.net/token-economy-book/">here</a>.</p>
<h4 id="heading-the-infinite-machine-how-an-army-of-crypto-hackers-is-building-the-next-internet-with-ethereum">The Infinite Machine - How an Army of Crypto-hackers Is Building the Next Internet with Ethereum</h4>
<p>This is the amazing story of how Ethereum came to be, walking you through the history of it all. It is a very thorough and entertaining account of the origin story of Ethereum, I highly recommend checking it out.</p>
<p>You can view the book <a target="_blank" href="https://www.harpercollins.com/products/the-infinite-machine-camila-russo?variant=32123333836834">here</a>.</p>
<h4 id="heading-new-village-power-back-to-people">New Village - Power Back to People</h4>
<p>This is a really cool story of how blockchain technologies and decentralization will affect the future of the world.</p>
<p>You can view the book <a target="_blank" href="https://www.amazon.com/New-Village-Power-Back-People-Blockchain/dp/1718045743">here</a></p>
<h4 id="heading-how-to-defi">How to DeFi</h4>
<p>As you can probably tell by the title, this book focuses on how you can start using DeFi today. It gives you a good understanding about how you can use it today as well as some applications of it that we will see at some time in the future.</p>
<p>You can view the book <a target="_blank" href="https://landing.coingecko.com/how-to-defi/">here</a></p>
<h4 id="heading-the-spatial-web">The Spatial Web</h4>
<p>The Spatial Web is a book that explores the future of the web and all of the implications, not only of Web3 and decentralization, but how everything will come together to enable things that we may have not yet considered. </p>
<p>It does a good job weighing the positive and negatives as well as ways that we may be able to address any negative outcomes of what is to come.</p>
<p>You can view the book <a target="_blank" href="https://www.goodreads.com/book/show/52816204-the-spatial-web">here</a></p>
<p>And here are a couple of solidity books:</p>
<ul>
<li><a target="_blank" href="https://www.oreilly.com/library/view/hands-on-smart-contract/9781492045250/">Hands-On Smart Contract Development with Solidity and Ethereum</a></li>
<li><a target="_blank" href="https://www.oreilly.com/library/view/mastering-ethereum/9781491971932/">Mastering Ethereum</a></li>
</ul>
<h3 id="heading-6-listen-to-these-podcasts">6. Listen to these podcasts</h3>
<p>Here are some good podcasts:</p>
<ul>
<li><a target="_blank" href="https://outlierventures.io/podcasts/">Founders of Web 3</a> – The people that are creating and building the next phase of the internet.</li>
<li><a target="_blank" href="http://podcast.banklesshq.com/">Bankless</a> – The Ultimate Guide to Crypto Finance</li>
<li><a target="_blank" href="https://podcast.ethhub.io/">Into the Ether</a> – Podcast about Ethereum</li>
<li><a target="_blank" href="https://player.fm/series/crypto-101">Crypto 101</a></li>
<li><a target="_blank" href="https://player.fm/series/epicenter-learn-about-crypto-blockchain-ethereum-bitcoin-and-distributed-technologies-41400">Epicenter</a> – Learn about Crypto, Blockchain, Ethereum, Bitcoin and Distributed Technologies</li>
</ul>
<h3 id="heading-7-watch-these-youtube-channels">7. Watch these YouTube channels</h3>
<ul>
<li><a target="_blank" href="https://www.youtube.com/channel/UCNOfzGXD_C9YMYmnefmPH0g">Ethereum Foundation</a></li>
<li><a target="_blank" href="https://www.youtube.com/channel/UCZM8XQjNOyG2ElPpEUtNasA">Eat the Blocks</a> – Short videos on blockchain development</li>
<li><a target="_blank" href="https://www.youtube.com/c/Finematics/videos">Finematics</a> – Sharing interesting DeFi videos</li>
<li><a target="_blank" href="https://www.youtube.com/channel/UCY0xL8V6NzzFcwzHCgB8orQ">Dapp University</a> – Videos in the Ethereum space</li>
<li><a target="_blank" href="https://www.youtube.com/c/BlockGeeks/featured">BlockGeeks</a> – General Blockchain Training</li>
<li><a target="_blank" href="https://www.youtube.com/channel/UCvCp6vKY5jDr87htKH6hgDA">The Daily Gwei</a></li>
<li><a target="_blank" href="https://www.youtube.com/channel/UC_HI2i2peo1A-STdG22GFsA">Austin Griffith</a></li>
</ul>
<p>I've also begun doing videos and tutorials on Ethereum and Solidity, so consider checking out <a target="_blank" href="https://www.youtube.com/channel/UC7mca3O0DmdSG2Cr80sOD7g">my YouTube</a> channel.</p>
<h2 id="heading-tradeoffs-and-considerations-of-switching-careers">Tradeoffs and Considerations of Switching Careers</h2>
<p>There are always things to consider when making a career transition, but especially when considering this space.</p>
<p>There are a lot of positives, but there are also unknowns as well as negatives. Let's talk about some of them.</p>
<h3 id="heading-its-nascent-tech">It's nascent tech</h3>
<p>While there are many existing dapps and companies already flourishing, this space is very much still coming into existence in many ways.</p>
<p>There are a lot of problems that we still need to solve, and there are no clear answers for many questions you'll have. The problems being solved are often complex, sometimes combining one or more aspects of distributed systems, game theory, cryptography, economics, social and political science, identity, psychology, and more.</p>
<p>Because of this, there are still things that we cannot yet build with the existing solutions that are available.</p>
<p>I personally think this is one of the more exciting things about all of it it, but it's not for everyone.</p>
<h3 id="heading-its-a-volatile-space">It's a volatile space</h3>
<p>Many of the projects are built around various types of tokens. The value of many of these tokens rises and falls dramatically, and you often see that people gain and lose excitement in the entire space based on these swings.</p>
<p>If you haven't fundamentally bought into the ideas behind decentralization itself, you may find these ups and downs mentally taxing.</p>
<h3 id="heading-its-full-of-speculation">It's full of speculation</h3>
<p>Because a lot of people only buy into certain tokens in a speculative way, it attracts some people who are in it only for the money.</p>
<p>You see things like scammers trying to get over on people and steal their money, endless talk about price swings from people who are speculating, and outright scam projects that often discredit the industry as a whole.</p>
<p>This is an annoying part of it and I don't really see it going away anytime soon.</p>
<h3 id="heading-this-thread">This thread</h3>
<p>I would also check out <a target="_blank" href="https://twitter.com/jonsyu/status/1389635626698297344">this Twitter thread</a>. Although I have not experienced all of these things, he is definitely shining a light on some of the things I have seen.</p>
<h2 id="heading-general-tips-and-how-to-land-a-blockchain-or-crypto-related-job">General Tips and How to Land a Blockchain or Crypto-Related Job</h2>
<p>There are many areas within the space that you can focus on and provide a positive impact on a team. I'd look into the different areas like governance, DeFi, NFTs, and decentralized web protocols to see what interests you the most and then focus on that.</p>
<p>There are a lot of opportunities and a lot of ways to stand out and get noticed. If you find an interesting project and would like to get involved, jump right into their community and ecosystem and start learning. Then see where you may be able to help out. Join their Discord or look at their GitHub issues to find ways that you can contribute.</p>
<p>This will give you an opportunity to meet people involved in the project and will open up discussions for potentially landing a role with them. In fact, it is very common for people within the teams to take notice of active community participants, they will then often reach out and try to recruit you without you even applying.</p>
<p>The pay is usually <a target="_blank" href="https://cryptocurrencyjobs.co/salaries/solidity-developer/">good</a>. Depending on where you are coming from, it could be more or less, but it's probably not going to be at the high levels of what you see at FAANG companies. </p>
<p>There is probably more potential upside. Most companies offer a combination of base pay + equity in the form of their digital token, so if you stick around and can help make the project successful and the value of the token goes up, you can often make more than what you would in many other areas.</p>
<h2 id="heading-people-to-follow-on-twitter">People to follow on Twitter</h2>
<p>Here are a few people who you may consider following on Twitter:</p>
<p><a target="_blank" href="https://twitter.com/VitalikButerin">Vitalik</a><br><a target="_blank" href="https://twitter.com/ashleighschap">Ashleigh Schapp</a><br><a target="_blank" href="https://twitter.com/CryptoHayes">Arthur Hayes</a><br><a target="_blank" href="https://twitter.com/StaniKulechov">Stani Kulechov</a><br><a target="_blank" href="https://twitter.com/gkimbwala">Gloria Kimbwala</a><br><a target="_blank" href="https://twitter.com/niran">Niran Babalola</a><br><a target="_blank" href="https://twitter.com/ricburton">Ric Burton</a><br><a target="_blank" href="https://twitter.com/dennisonbertram">Dennison Bertram</a><br><a target="_blank" href="https://twitter.com/manasilvora">Mana Silvora</a><br><a target="_blank" href="https://twitter.com/austingriffith">Austin Griffith</a><br><a target="_blank" href="https://twitter.com/smpalladino">Santiago Palladino</a><br><a target="_blank" href="https://twitter.com/zmanian">Zaki Manian</a><br><a target="_blank" href="https://twitter.com/sassal0x">Anthony Sassano</a></p>
<p>I also found <a target="_blank" href="https://twitter.com/i/lists/869994563691319296/members">this comprehensive list</a> created by someone on Twitter.</p>
<p>A few people on my team at <a target="_blank" href="https://twitter.com/edgeandnode">Edge &amp; Node</a>:<br><a target="_blank" href="https://twitter.com/yanivgraph">Yaniv Tal</a><br><a target="_blank" href="https://twitter.com/theklineventure">Tegan Kline</a><br><a target="_blank" href="https://twitter.com/evabeylin">Eva Beylin</a><br><a target="_blank" href="https://twitter.com/azacharyf">Adam Fuller</a><br><a target="_blank" href="https://twitter.com/RezBrandon">Brandon Ramirez</a></p>
<h2 id="heading-teams-doing-interesting-stuff-and-hiring">Teams doing interesting stuff (and hiring)</h2>
<p><a target="_blank" href="https://compound.finance/about#jobs">Compound</a><br><a target="_blank" href="https://jobs.lever.co/Uniswap">Uniswap</a><br><a target="_blank" href="https://chainlinklabs.com/careers">Chainlink</a><br><a target="_blank" href="https://jobs.lever.co/SkynetLabs">Skynet Labs</a><br><a target="_blank" href="https://aave.com/careers/">Aave</a><br><a target="_blank" href="https://matic.network/careers/">Matic</a><br><a target="_blank" href="https://livepeer.org/jobs">Livepeer</a><br><a target="_blank" href="https://consensys.net/open-roles/">Consensys</a><br><a target="_blank" href="https://medium.com/the-ethereum-name-service/ens-is-hiring-come-build-a-new-decentralized-internet-with-us-24398dea3ac">ENS</a><br><a target="_blank" href="https://openzeppelin.com/jobs/">OpenZeppelin</a><br><a target="_blank" href="https://foundation.app/careers">Foundation</a><br><a target="_blank" href="https://cryptocurrencyjobs.co/startups/zora/">Zora</a><br><a target="_blank" href="https://synthetix.com/careers">Synthetix</a><br><a target="_blank" href="https://jobs.dcg.co/companies">Digital Currency Group</a></p>
<p>You can also find a pretty decent list of job opportunities in cryptocurrency <a target="_blank" href="https://cryptocurrencyjobs.co/">here</a>.</p>
<p>Also, my team at <a target="_blank" href="https://edgeandnode.com/jobs">Edge &amp; Node is hiring</a>!</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Did I mention this space is volatile? Be ready for some high highs and low lows, but also for some of the most fun you may have in your career. </p>
<p>You'll be working alongside some of the smartest people in tech trying to solve some of the most complex problems that I think will ultimately have a massive positive impact on humanity.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The Complete Guide to Full Stack Ethereum Development ]]>
                </title>
                <description>
                    <![CDATA[ By Nader Dabit In this article, you'll learn how to build full stack dApps with React, Ethers.js, Solidity, and Hardhat. You can find the code for this project here. The video course for this tutorial is here. I recently joined Edge & Node as a Devel... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/full-stack-ethereum-development/</link>
                <guid isPermaLink="false">66d46042052ad259f07e4b1e</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ethereum blockchain ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 17 May 2021 20:45:00 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/05/full-stack-ethereum-article.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Nader Dabit</p>
<p>In this article, you'll learn how to build full stack dApps with React, Ethers.js, Solidity, and Hardhat.</p>
<p>You can find the code for this project <a target="_blank" href="https://github.com/dabit3/full-stack-ethereum">here</a>. The video course for this tutorial is <a target="_blank" href="https://www.youtube.com/watch?v=a0osIaAOFSE">here</a>.</p>
<p>I recently joined <a target="_blank" href="https://twitter.com/edgeandnode">Edge &amp; Node</a> as a Developer Relations Engineer and have been diving deeper into smart contract development with Ethereum. I have settled upon what I think is the best stack for building full stack dApps with Solidity:</p>
<ul>
<li>Client Framework – <strong>React</strong></li>
<li>Ethereum development environment – <a target="_blank" href="https://hardhat.org/"><strong>Hardhat</strong></a></li>
<li>Ethereum Web Client Library – <a target="_blank" href="https://docs.ethers.io/v5/"><strong>Ethers.js</strong></a></li>
<li>API layer – <a target="_blank" href="https://thegraph.com/">The Graph Protocol</a></li>
</ul>
<p>But I ran into a problem while figuring all this out. While there's fairly good documentation out there for each of these tools individually, there's not a lot that helps you put them all together and understand how they work with each other. </p>
<p>There are some really good boilerplates out there like <a target="_blank" href="https://github.com/austintgriffith/scaffold-eth">scaffold-eth</a> (which also includes Ethers, Hardhat, and The Graph), but they may be too much to pick up for people just getting started.</p>
<p>I wanted an end-to-end guide to show me how to build full stack Ethereum apps using the most up-to-date resources, libraries, and tooling.</p>
<p>Here's what I was interested in:</p>
<ol>
<li>How to create, deploy, and test Ethereum smart contracts to local, test, and mainnet</li>
<li>How to switch between local, test, and production environments / networks</li>
<li>How to connect to and interact with the contracts using various environments from a front end like React, Vue, Svelte, or Angular</li>
</ol>
<p>After spending some time figuring all of this out, I finally got going with the stack that I felt really happy with. Then I thought it would be nice to write up how to build and test a full stack Ethereum app using this stack.</p>
<p>I hope this guide will be useful not only for other people out there who may be interested in this stack, but also for myself for future reference. This is that reference.</p>
<h2 id="heading-the-tech-well-be-using">The Tech We'll Be Using</h2>
<p>Let's go over the main pieces we will be using and how they fit into the stack.</p>
<h3 id="heading-1-ethereum-development-environment">1. Ethereum development environment</h3>
<p>When building smart contracts, you will need a way to deploy your contracts, run tests, and debug Solidity code without dealing with live environments.</p>
<p>You will also need a way to compile your Solidity code into code that can be run in a client-side application – in our case, a React app. We'll learn more about how this works a little later.</p>
<p>Hardhat is an Ethereum development environment and framework designed for full stack development, and it's the framework that I will be using for this tutorial.</p>
<p>Other similar tools in the ecosystem are <a target="_blank" href="https://www.trufflesuite.com/ganache">Ganache</a> and <a target="_blank" href="https://www.trufflesuite.com/">Truffle</a>.</p>
<h3 id="heading-2-ethereum-web-client-library">2. Ethereum Web Client Library</h3>
<p>In our React app, we will need a way to interact with the smart contracts that have been deployed. We will need a way to read for data as well as send new transactions.</p>
<p><a target="_blank" href="https://docs.ethers.io/v5/">ethers.js</a> aims to be a complete and compact library for interacting with the Ethereum Blockchain and its ecosystem from client-side JavaScript applications like React, Vue, Angular, or Svelte. It is the library we'll be using.</p>
<p>Another popular option in the ecosystem is <a target="_blank" href="https://web3js.readthedocs.io/en/v1.3.4/">web3.js</a></p>
<h3 id="heading-3-metamask">3. Metamask</h3>
<p><a target="_blank" href="https://metamask.io/download.html">Metamask</a> helps you handle account management and connecting the current user to the blockchain. MetaMask enables users to manage their accounts and keys in a few different ways while isolating them from the site context.</p>
<p>Once a user has connected their MetaMask wallet, you as a developer can interact with the globally available Ethereum API (<code>window.ethereum</code>) that identifies the users of web3-compatible browsers (like MetaMask users). Whenever you request a transaction signature, MetaMask will prompt the user in a comprehensible way.</p>
<h3 id="heading-4-react">4. React</h3>
<p>React is a front end JavaScript library for building web applications, user interfaces, and UI components. It's maintained by Facebook and many individual developers and companies.</p>
<p>React and its large ecosystem of metaframeworks like <a target="_blank" href="https://nextjs.org/">Next.js</a>, <a target="_blank" href="https://www.gatsbyjs.com/">Gatsby</a>, <a target="_blank" href="https://redwoodjs.com/">Redwood</a>, <a target="_blank" href="https://blitzjs.com/">Blitz.js</a>, and others enable all types of deployment targets including traditional SPAs, static site generators, server-side rendering, and a combination of all three. </p>
<p>React continues to seemingly dominate the front-end space, and I think will continue to do so for the near future and possibly beyond.</p>
<h3 id="heading-5-the-graph">5. The Graph</h3>
<p>For most apps built on blockchains like Ethereum, it's hard and time-intensive to read data directly from the chain. So in the past, you'd see people and companies building their own centralized indexing server and serving API requests from these servers. This requires a lot of engineering and hardware resources and breaks the security properties required for decentralization.</p>
<p>The Graph is an indexing protocol for querying blockchain data that lets you create fully decentralized applications. It solves this problem by exposing a rich GraphQL query layer that apps can consume. </p>
<p>In this guide we won't be building a subgraph for our app, but will do so in a future tutorial.</p>
<h2 id="heading-what-we-will-be-building">What we will be building</h2>
<p>In this tutorial, we'll be building, deploying, and connecting to a couple of basic smart contracts:</p>
<ol>
<li>A contract for creating and updating a message on the Ethereum blockchain</li>
<li>A contract for minting tokens, which allows the owner of the contract to send tokens to others and to read the token balances, and lets owners of the new tokens also send them to others.</li>
</ol>
<p>We will also build out a React front end that will allow a user to:</p>
<ol>
<li>Read the greeting from the contract deployed to the blockchain</li>
<li>Update the greeting</li>
<li>Send the newly minted tokens from their address to another address</li>
<li>Once someone has received tokens, allow them to also send their tokens to someone else</li>
<li>Read the token balance from the contract deployed to the blockchain</li>
</ol>
<h3 id="heading-prerequisites">Prerequisites</h3>
<ol>
<li>Node.js installed on your local machine</li>
<li><a target="_blank" href="https://metamask.io/">MetaMask</a> Chrome extension installed in your browser</li>
</ol>
<p>You do not need to own any Ethereum for this guide as we will be using fake / test Ether on a test network for the entire tutorial.</p>
<h2 id="heading-how-to-get-started-with-create-react-app">How to get started with create-react-app</h2>
<p>To get started, we'll create a new React application:</p>
<pre><code class="lang-sh">npx create-react-app react-dapp
</code></pre>
<p>Next, change into the new directory and install <a target="_blank" href="https://docs.ethers.io/v5/"><code>ethers.js</code></a> and <a target="_blank" href="https://github.com/nomiclabs/hardhat"><code>hardhat</code></a> using either <strong>NPM</strong> or <strong>Yarn</strong>:</p>
<pre><code>npm install ethers hardhat @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers
</code></pre><h2 id="heading-how-to-install-and-configure-an-ethereum-development-environment">How to Install and Configure an Ethereum Development Environment</h2>
<p>Next, initialize a new Ethereum Development Environment with Hardhat:</p>
<pre><code class="lang-sh">npx hardhat

? What <span class="hljs-keyword">do</span> you want to <span class="hljs-keyword">do</span>? Create a sample project
? Hardhat project root: &lt;Choose default path&gt;
</code></pre>
<p>Now you should see the following artifacts created for you in your root directory:</p>
<ul>
<li><strong>hardhat.config.js</strong> – The entirety of your Hardhat setup (that is, your config, plugins, and custom tasks) is contained in this file.</li>
<li><strong>scripts</strong> – A folder containing a script named <strong>sample-script.js</strong> that will deploy your smart contract when executed</li>
<li><strong>test</strong> – A folder containing an example testing script</li>
<li><strong>contracts</strong> – A folder holding an example Ethereum smart contract</li>
</ul>
<p>Because of <a target="_blank" href="https://hardhat.org/metamask-issue.html">a MetaMask configuration issue</a>, we need to update the chain ID on our HardHat configuration to be <strong>1337</strong>. We also need to update the location of the <a target="_blank" href="https://hardhat.org/guides/compile-contracts.html#artifacts">artifacts</a> for our compiled contracts so they're in the <strong>src</strong> directory of our React app.</p>
<p>To make these updates, open <strong>hardhat.config.js</strong> and update the <code>module.exports</code> to look like this:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">solidity</span>: <span class="hljs-string">"0.8.3"</span>,
  <span class="hljs-attr">paths</span>: {
    <span class="hljs-attr">artifacts</span>: <span class="hljs-string">'./src/artifacts'</span>,
  },
  <span class="hljs-attr">networks</span>: {
    <span class="hljs-attr">hardhat</span>: {
      <span class="hljs-attr">chainId</span>: <span class="hljs-number">1337</span>
    }
  }
};
</code></pre>
<h2 id="heading-our-smart-contract">Our smart contract</h2>
<p>Next, let's have a look at the example contract we have at <strong>contracts/Greeter.sol</strong>:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">//SPDX-License-Identifier: MIT</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.7.0;</span>

<span class="hljs-keyword">import</span> <span class="hljs-string">"hardhat/console.sol"</span>;


<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">Greeter</span> </span>{
  <span class="hljs-keyword">string</span> greeting;

  <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> _greeting</span>) </span>{
    console.log(<span class="hljs-string">"Deploying a Greeter with greeting:"</span>, _greeting);
    greeting <span class="hljs-operator">=</span> _greeting;
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">greet</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span></span>) </span>{
    <span class="hljs-keyword">return</span> greeting;
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setGreeting</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> _greeting</span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> </span>{
    console.log(<span class="hljs-string">"Changing greeting from '%s' to '%s'"</span>, greeting, _greeting);
    greeting <span class="hljs-operator">=</span> _greeting;
  }
}
</code></pre>
<p>This is a very basic smart contract. When deployed, it sets a Greeting variable and exposes a function (<code>greet</code>) that can be called to return the greeting.</p>
<p>It also exposes a function that allows a user to update the greeting (<code>setGreeting</code>). When deployed to the Ethereum blockchain, these methods will be available for a user to interact with.</p>
<p>Let's make one small modification to the smart contract. Since we set the solidity version of our compiler to <code>0.8.3</code> in <strong>hardhat.config.js</strong>, let's also be sure to update our contract to use the same version of solidity:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">// contracts/Greeter.sol</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.3;</span>
</code></pre>
<h3 id="heading-how-to-read-and-write-to-the-ethereum-blockchain">How to Read and Write to the Ethereum Blockchain</h3>
<p>There are two ways to interact with a smart contract – reading or writing / transactions. In our contract, <code>greet</code> can be considered reading, and <code>setGreeting</code> can be considered writing / transactional.</p>
<p>When writing or initializing a transaction, you have to pay for the transaction to be written to the blockchain. To make this work, you need to pay <a target="_blank" href="https://www.investopedia.com/terms/g/gas-ethereum.asp#:~:text=What%20Is%20Gas%20(Ethereum)%3F,on%20the%20Ethereum%20blockchain%20platform">gas</a> which is the fee or price required to successfully conduct a transaction and execute a contract on the Ethereum blockchain.</p>
<p>As long as you are only reading from the blockchain and not changing or updating anything, you don't need to carry out a transaction and there will be no gas or cost to do so. The function you call is then carried out only by the node you are connected to, so you don't need to pay any gas and the read is free.</p>
<p>From our React app, we will interact with the smart contract using a combination of the <code>ethers.js</code> library, the contract address, and the <a target="_blank" href="https://docs.soliditylang.org/en/v0.5.3/abi-spec.html">ABI</a> that will be created from the contract by Hardhat.</p>
<p>What is an ABI? ABI stands for application binary interface. You can think of it as the interface between your client-side application and the Ethereum blockchain where the smart contract you are going to be interacting with is deployed.</p>
<p>ABIs are typically compiled from Solidity smart contracts by a development framework like Hardhat. You can also often find the ABIs for a smart contract on <a target="_blank" href="https://etherscan.io/">Etherscan</a></p>
<h3 id="heading-how-to-compile-the-abi">How to Compile the ABI</h3>
<p>Now that we have gone over the basic smart contract and know what ABIs are, let's compile an ABI for our project.</p>
<p>To do so, go to the command line and run the following command:</p>
<pre><code class="lang-sh">npx hardhat compile
</code></pre>
<p>Now, you should see a new folder named <strong>artifacts</strong> in the <strong>src</strong> directory. The <strong>artifacts/contracts/Greeter.json</strong> file contains the ABI as one of the properties. When we need to use the ABI, we can import it from our JavaScript file:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> Greeter <span class="hljs-keyword">from</span> <span class="hljs-string">'./artifacts/contracts/Greeter.sol/Greeter.json'</span>
</code></pre>
<p>We can then reference the ABI like this:</p>
<pre><code><span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Greeter ABI: "</span>, Greeter.abi)
</code></pre><blockquote>
<p>Note that Ethers.js also enables <a target="_blank" href="https://blog.ricmoo.com/human-readable-contract-abis-in-ethers-js-141902f4d917">human readable ABIs</a>, but will will not be going into this during this tutorial.</p>
</blockquote>
<h3 id="heading-how-to-deploy-and-use-a-local-network-blockchain">How to Deploy and Use a Local Network / Blockchain</h3>
<p>Next, let's deploy our smart contract to a local blockchain so that we can test it out.</p>
<p>To deploy to the local network, you first need to start the local test node. To do so, open the CLI and run the following command:</p>
<pre><code class="lang-sh">npx hardhat node
</code></pre>
<p>When we run this command, you should see a list of addresses and private keys.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e176nc82ik77hei3a48s.jpg" alt="Hardhat node addresses" width="2000" height="1204" loading="lazy"></p>
<p>These are 20 test accounts and addresses created for us that we can use to deploy and test our smart contracts. Each account is also loaded up with 10,000 fake Ether. In a moment, we'll learn how to import the test account into MetaMask so that we can use it.</p>
<p>Next, we need to deploy the contract to the test network. First update the name of <strong>scripts/sample-script.js</strong> to <strong>scripts/deploy.js</strong>.</p>
<p>Now we can run the deploy script and give a flag to the CLI that we would like to deploy to our local network:</p>
<pre><code class="lang-sh">npx hardhat run scripts/deploy.js --network localhost
</code></pre>
<p>Once this script is executed, the smart contract should be deployed to the local test network and we should be then able to start interacting with it.</p>
<blockquote>
<p>When the contract was deployed, it used the first account that was created when we started the local network.</p>
</blockquote>
<p>If you look at the output from the CLI, you should be able to see something like this:</p>
<pre><code class="lang-sh">Greeter deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0
</code></pre>
<p>This address is what we will use in our client application to talk to the smart contract. Keep this address available as we will need to use it when connecting to it from the client application.</p>
<p>To send transactions to the smart contract, we will need to connect our MetaMask wallet using one of the accounts created when we ran <code>npx hardhat node</code>. In the list of contracts that the CLI logs out, you should see both an <strong>Account number</strong> as well as a <strong>Private Key</strong>:</p>
<pre><code class="lang-bash">➜  react-defi-stack git:(main) npx hardhat node
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/

Accounts
========
Account <span class="hljs-comment">#0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH)</span>
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

...
</code></pre>
<p>We can import this account into MetaMask in order to start using some of the fake Eth available there. To do so, first open MetaMask and update the network to be Localhost 8545:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qnbsbcm4y1md6cwjttpx.jpg" alt="MetaMask Localhost" width="1500" height="1246" loading="lazy"></p>
<p>Next, in MetaMask click on <strong>Import Account</strong> from the accounts menu:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n7vbzlov869gwk9rtwl1.jpg" alt="Import account" width="1500" height="1246" loading="lazy"></p>
<p>Copy then paste one of the <strong>Private Keys</strong> logged out by the CLI and click <strong>Import</strong>. Once the account is imported, you should see the Eth in the account:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/x5lob4yug3jznhy9z0qt.jpg" alt="Imported account" width="1500" height="1246" loading="lazy"></p>
<p>Now that we have a deployed our smart contract and set up our account, we can start interacting with it from the React app.</p>
<h3 id="heading-how-to-connect-the-react-client">How to Connect the React Client</h3>
<p>In this tutorial we are not going to be worrying about building a beautiful UI with CSS and all of that – we are focused 100% on the core functionality to get you up and running. From there, you can take it and make it look good if you'd like.</p>
<p>With that being said, let's review the two objectives that we want from our React application:</p>
<ol>
<li>Fetch the current value of <code>greeting</code> from the smart contract</li>
<li>Allow a user to update the value of the <code>greeting</code></li>
</ol>
<p>So how do we accomplish this? Here are the things we need to do to make this happen:</p>
<ol>
<li>Create an input field and some local state to manage the value of the input (to update the <code>greeting</code>)</li>
<li>Allow the application to connect to the user's MetaMask account to sign transactions</li>
<li>Create functions for reading and writing to the smart contract</li>
</ol>
<p>To do this, open <code>src/App.js</code> and update it with the following code, setting the value of <code>greeterAddress</code> to the address of your smart contract:</p>
<pre><code class="lang-js"><span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>;
<span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { ethers } <span class="hljs-keyword">from</span> <span class="hljs-string">'ethers'</span>
<span class="hljs-keyword">import</span> Greeter <span class="hljs-keyword">from</span> <span class="hljs-string">'./artifacts/contracts/Greeter.sol/Greeter.json'</span>

<span class="hljs-comment">// Update with the contract address logged out to the CLI when it was deployed </span>
<span class="hljs-keyword">const</span> greeterAddress = <span class="hljs-string">"your-contract-address"</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-comment">// store greeting in local state</span>
  <span class="hljs-keyword">const</span> [greeting, setGreetingValue] = useState()

  <span class="hljs-comment">// request access to the user's MetaMask account</span>
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">requestAccount</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">await</span> <span class="hljs-built_in">window</span>.ethereum.request({ <span class="hljs-attr">method</span>: <span class="hljs-string">'eth_requestAccounts'</span> });
  }

  <span class="hljs-comment">// call the smart contract, read the current greeting value</span>
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetchGreeting</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-built_in">window</span>.ethereum !== <span class="hljs-string">'undefined'</span>) {
      <span class="hljs-keyword">const</span> provider = <span class="hljs-keyword">new</span> ethers.providers.Web3Provider(<span class="hljs-built_in">window</span>.ethereum)
      <span class="hljs-keyword">const</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(greeterAddress, Greeter.abi, provider)
      <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> contract.greet()
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'data: '</span>, data)
      } <span class="hljs-keyword">catch</span> (err) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Error: "</span>, err)
      }
    }    
  }

  <span class="hljs-comment">// call the smart contract, send an update</span>
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setGreeting</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (!greeting) <span class="hljs-keyword">return</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-built_in">window</span>.ethereum !== <span class="hljs-string">'undefined'</span>) {
      <span class="hljs-keyword">await</span> requestAccount()
      <span class="hljs-keyword">const</span> provider = <span class="hljs-keyword">new</span> ethers.providers.Web3Provider(<span class="hljs-built_in">window</span>.ethereum);
      <span class="hljs-keyword">const</span> signer = provider.getSigner()
      <span class="hljs-keyword">const</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(greeterAddress, Greeter.abi, signer)
      <span class="hljs-keyword">const</span> transaction = <span class="hljs-keyword">await</span> contract.setGreeting(greeting)
      <span class="hljs-keyword">await</span> transaction.wait()
      fetchGreeting()
    }
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">header</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App-header"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{fetchGreeting}</span>&gt;</span>Fetch Greeting<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{setGreeting}</span>&gt;</span>Set Greeting<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setGreetingValue(e.target.value)} placeholder="Set greeting" /&gt;
      <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<p>To test it out, start the React server:</p>
<pre><code class="lang-sh">npm start
</code></pre>
<p>When the app loads, you should be able to fetch the current greeting and log it out to the console. You should also be able to make updates to the greeting by signing the contract with your MetaMask wallet and spending the fake Ether.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9a57jbzrwylr2l0rujxm.png" alt="Setting and getting the greeting value" width="1538" height="1294" loading="lazy"></p>
<h3 id="heading-how-to-deploy-and-use-a-live-test-network">How to Deploy and Use a Live Test Network</h3>
<p>There are several Ethereum test networks like Ropsten, Rinkeby, or Kovan that we can also deploy to in order to have a publicly accessible version of our contract available without having to deploy it to mainnet. </p>
<p>In this tutorial we'll be deploying to the <strong>Ropsten</strong> test network.</p>
<p>To start off, first update your MetaMask wallet to connect to the Ropsten network.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k85gplgp26wp58l95bhr.jpg" alt="Ropsten network" width="1500" height="1246" loading="lazy"></p>
<p>Next, send yourself some test Ether to use during the rest of this tutorial by visiting <a target="_blank" href="https://faucet.ropsten.be/">this test faucet</a>.</p>
<p>We can get access to Ropsten (or any of the other test networks) by signing up with a service like <a target="_blank" href="https://infura.io/dashboard/ethereum/cbdf7c5eee8b4e2b91e76b77ffd34533/settings">Infura</a> or <a target="_blank" href="https://www.alchemyapi.io/">Alchemy</a> (I'm using Infura for this tutorial).</p>
<p>Once you've created the app in Infura or Alchemy, you will be given an endpoint that looks something like this:</p>
<pre><code>https:<span class="hljs-comment">//ropsten.infura.io/v3/your-project-id</span>
</code></pre><p>Be sure to set the <strong>ALLOWLIST ETHEREUM ADDRESSES</strong> in the Infura or Alchemy app configuration to include the wallet address of the account you will be deploying from.</p>
<p>To deploy to the test network we need to update our Hardhat config with some additional network information. One of the things we need to set is the private key of the wallet we will be deploying from.</p>
<p>To get the private key, you can export it from MetaMask.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/deod3d6qix8us12t17i4.jpg" alt="Export private key" width="2060" height="1246" loading="lazy"></p>
<blockquote>
<p>I'd suggest not hardcoding this value in your app but instead setting it as something like an environment variable.</p>
</blockquote>
<p>Next, add a <code>networks</code> property with the following configuration:</p>
<pre><code class="lang-js"><span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">defaultNetwork</span>: <span class="hljs-string">"hardhat"</span>,
  <span class="hljs-attr">paths</span>: {
    <span class="hljs-attr">artifacts</span>: <span class="hljs-string">'./src/artifacts'</span>,
  },
  <span class="hljs-attr">networks</span>: {
    <span class="hljs-attr">hardhat</span>: {},
    <span class="hljs-attr">ropsten</span>: {
      <span class="hljs-attr">url</span>: <span class="hljs-string">"https://ropsten.infura.io/v3/your-project-id"</span>,
      <span class="hljs-attr">accounts</span>: [<span class="hljs-string">`0x<span class="hljs-subst">${your-private-key}</span>`</span>]
    }
  },
  <span class="hljs-attr">solidity</span>: <span class="hljs-string">"0.7.3"</span>,
};
</code></pre>
<p>To deploy, run the following script:</p>
<pre><code class="lang-sh">npx hardhat run scripts/deploy.js --network ropsten
</code></pre>
<p>Once your contract is deployed you should be able to start interacting with it. You should be now able to view the live contract on <a target="_blank" href="https://ropsten.etherscan.io/">Etherscan Ropsten Testnet Explorer</a></p>
<h2 id="heading-how-to-mint-tokens">How to Mint Tokens</h2>
<p>One of the most common use cases of smart contracts is creating tokens. Let's look at how we can do that. Since we know a little more about how all of this works, we'll be going a little faster.</p>
<p>In the main <strong>contracts</strong> directory, create a new file named <strong>Token.sol</strong>.</p>
<p>Next, update <strong>Token.sol</strong> with the following smart contract:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">//SPDX-License-Identifier: MIT</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.3;</span>

<span class="hljs-keyword">import</span> <span class="hljs-string">"hardhat/console.sol"</span>;

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">Token</span> </span>{
  <span class="hljs-keyword">string</span> <span class="hljs-keyword">public</span> name <span class="hljs-operator">=</span> <span class="hljs-string">"Nader Dabit Token"</span>;
  <span class="hljs-keyword">string</span> <span class="hljs-keyword">public</span> symbol <span class="hljs-operator">=</span> <span class="hljs-string">"NDT"</span>;
  <span class="hljs-keyword">uint</span> <span class="hljs-keyword">public</span> totalSupply <span class="hljs-operator">=</span> <span class="hljs-number">1000000</span>;
  <span class="hljs-keyword">mapping</span>(<span class="hljs-keyword">address</span> <span class="hljs-operator">=</span><span class="hljs-operator">&gt;</span> <span class="hljs-keyword">uint</span>) balances;

  <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params"></span>) </span>{
    balances[<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>] <span class="hljs-operator">=</span> totalSupply;
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">transfer</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> to, <span class="hljs-keyword">uint</span> amount</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> </span>{
    <span class="hljs-built_in">require</span>(balances[<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>] <span class="hljs-operator">&gt;</span><span class="hljs-operator">=</span> amount, <span class="hljs-string">"Not enough tokens"</span>);
    balances[<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>] <span class="hljs-operator">-</span><span class="hljs-operator">=</span> amount;
    balances[to] <span class="hljs-operator">+</span><span class="hljs-operator">=</span> amount;
  }

  <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">balanceOf</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> account</span>) <span class="hljs-title"><span class="hljs-keyword">external</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint</span></span>) </span>{
    <span class="hljs-keyword">return</span> balances[account];
  }
}
</code></pre>
<blockquote>
<p>Note that this token contract is for demo purposes only and is not <a target="_blank" href="https://eips.ethereum.org/EIPS/eip-20">ERC20</a>-compliant. We will be covering ERC20 tokens later.</p>
</blockquote>
<p>This contract will create a new token called "Nader Dabit Token" and set the supply to 1000000.</p>
<p>Next, compile this contract:</p>
<pre><code class="lang-sh">npx hardhat compile
</code></pre>
<p>Now, update the deploy script at <strong>scripts/deploy.js</strong> to include this new Token contract:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> hre = <span class="hljs-built_in">require</span>(<span class="hljs-string">"hardhat"</span>);

<span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">main</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [deployer] = <span class="hljs-keyword">await</span> hre.ethers.getSigners();

  <span class="hljs-built_in">console</span>.log(
    <span class="hljs-string">"Deploying contracts with the account:"</span>,
    deployer.address
  );

  <span class="hljs-keyword">const</span> Greeter = <span class="hljs-keyword">await</span> hre.ethers.getContractFactory(<span class="hljs-string">"Greeter"</span>);
  <span class="hljs-keyword">const</span> greeter = <span class="hljs-keyword">await</span> Greeter.deploy(<span class="hljs-string">"Hello, World!"</span>);

  <span class="hljs-keyword">const</span> Token = <span class="hljs-keyword">await</span> hre.ethers.getContractFactory(<span class="hljs-string">"Token"</span>);
  <span class="hljs-keyword">const</span> token = <span class="hljs-keyword">await</span> Token.deploy();

  <span class="hljs-keyword">await</span> greeter.deployed();
  <span class="hljs-keyword">await</span> token.deployed();

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Greeter deployed to:"</span>, greeter.address);
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Token deployed to:"</span>, token.address);
}

main()
  .then(<span class="hljs-function">() =&gt;</span> process.exit(<span class="hljs-number">0</span>))
  .catch(<span class="hljs-function"><span class="hljs-params">error</span> =&gt;</span> {
    <span class="hljs-built_in">console</span>.error(error);
    process.exit(<span class="hljs-number">1</span>);
  });
</code></pre>
<p>Now, we can deploy this new contract to the local or Ropsten network:</p>
<pre><code class="lang-sh">npx hardhat run scripts/deploy.js --network localhost
</code></pre>
<p>Once the contract is deployed, you can start sending these tokens to other addresses.</p>
<p>To do so, let's update the client code we will need in order to make this work:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> <span class="hljs-string">'./App.css'</span>;
<span class="hljs-keyword">import</span> { useState } <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> { ethers } <span class="hljs-keyword">from</span> <span class="hljs-string">'ethers'</span>
<span class="hljs-keyword">import</span> Greeter <span class="hljs-keyword">from</span> <span class="hljs-string">'./artifacts/contracts/Greeter.sol/Greeter.json'</span>
<span class="hljs-keyword">import</span> Token <span class="hljs-keyword">from</span> <span class="hljs-string">'./artifacts/contracts/Token.sol/Token.json'</span>

<span class="hljs-keyword">const</span> greeterAddress = <span class="hljs-string">"your-contract-address"</span>
<span class="hljs-keyword">const</span> tokenAddress = <span class="hljs-string">"your-contract-address"</span>

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> [greeting, setGreetingValue] = useState()
  <span class="hljs-keyword">const</span> [userAccount, setUserAccount] = useState()
  <span class="hljs-keyword">const</span> [amount, setAmount] = useState()

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">requestAccount</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">await</span> <span class="hljs-built_in">window</span>.ethereum.request({ <span class="hljs-attr">method</span>: <span class="hljs-string">'eth_requestAccounts'</span> });
  }

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">fetchGreeting</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-built_in">window</span>.ethereum !== <span class="hljs-string">'undefined'</span>) {
      <span class="hljs-keyword">const</span> provider = <span class="hljs-keyword">new</span> ethers.providers.Web3Provider(<span class="hljs-built_in">window</span>.ethereum)
      <span class="hljs-built_in">console</span>.log({ provider })
      <span class="hljs-keyword">const</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(greeterAddress, Greeter.abi, provider)
      <span class="hljs-keyword">try</span> {
        <span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> contract.greet()
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'data: '</span>, data)
      } <span class="hljs-keyword">catch</span> (err) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Error: "</span>, err)
      }
    }    
  }

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">getBalance</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-built_in">window</span>.ethereum !== <span class="hljs-string">'undefined'</span>) {
      <span class="hljs-keyword">const</span> [account] = <span class="hljs-keyword">await</span> <span class="hljs-built_in">window</span>.ethereum.request({ <span class="hljs-attr">method</span>: <span class="hljs-string">'eth_requestAccounts'</span> })
      <span class="hljs-keyword">const</span> provider = <span class="hljs-keyword">new</span> ethers.providers.Web3Provider(<span class="hljs-built_in">window</span>.ethereum);
      <span class="hljs-keyword">const</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(tokenAddress, Token.abi, provider)
      <span class="hljs-keyword">const</span> balance = <span class="hljs-keyword">await</span> contract.balanceOf(account);
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Balance: "</span>, balance.toString());
    }
  }

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">setGreeting</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (!greeting) <span class="hljs-keyword">return</span>
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-built_in">window</span>.ethereum !== <span class="hljs-string">'undefined'</span>) {
      <span class="hljs-keyword">await</span> requestAccount()
      <span class="hljs-keyword">const</span> provider = <span class="hljs-keyword">new</span> ethers.providers.Web3Provider(<span class="hljs-built_in">window</span>.ethereum);
      <span class="hljs-built_in">console</span>.log({ provider })
      <span class="hljs-keyword">const</span> signer = provider.getSigner()
      <span class="hljs-keyword">const</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(greeterAddress, Greeter.abi, signer)
      <span class="hljs-keyword">const</span> transaction = <span class="hljs-keyword">await</span> contract.setGreeting(greeting)
      <span class="hljs-keyword">await</span> transaction.wait()
      fetchGreeting()
    }
  }

  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sendCoins</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> <span class="hljs-built_in">window</span>.ethereum !== <span class="hljs-string">'undefined'</span>) {
      <span class="hljs-keyword">await</span> requestAccount()
      <span class="hljs-keyword">const</span> provider = <span class="hljs-keyword">new</span> ethers.providers.Web3Provider(<span class="hljs-built_in">window</span>.ethereum);
      <span class="hljs-keyword">const</span> signer = provider.getSigner();
      <span class="hljs-keyword">const</span> contract = <span class="hljs-keyword">new</span> ethers.Contract(tokenAddress, Token.abi, signer);
      <span class="hljs-keyword">const</span> transation = <span class="hljs-keyword">await</span> contract.transfer(userAccount, amount);
      <span class="hljs-keyword">await</span> transation.wait();
      <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`<span class="hljs-subst">${amount}</span> Coins successfully sent to <span class="hljs-subst">${userAccount}</span>`</span>);
    }
  }

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">header</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"App-header"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{fetchGreeting}</span>&gt;</span>Fetch Greeting<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{setGreeting}</span>&gt;</span>Set Greeting<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setGreetingValue(e.target.value)} placeholder="Set greeting" /&gt;

        <span class="hljs-tag">&lt;<span class="hljs-name">br</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{getBalance}</span>&gt;</span>Get Balance<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">button</span> <span class="hljs-attr">onClick</span>=<span class="hljs-string">{sendCoins}</span>&gt;</span>Send Coins<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setUserAccount(e.target.value)} placeholder="Account ID" /&gt;
        <span class="hljs-tag">&lt;<span class="hljs-name">input</span> <span class="hljs-attr">onChange</span>=<span class="hljs-string">{e</span> =&gt;</span> setAmount(e.target.value)} placeholder="Amount" /&gt;
      <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
  );
}

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> App;
</code></pre>
<p>Next, run the app:</p>
<pre><code class="lang-sh">npm start
</code></pre>
<p>We should be able to click on <strong>Get Balance</strong> and see that we have 1,000,000 coins in our account logged out to the console.</p>
<p>You should also be able to view them in MetaMask by clicking on <strong>Add Token</strong>:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0t2ip26i5d2ltjc9j2a6.jpg" alt="Add token" width="1500" height="1246" loading="lazy"></p>
<p>Next click on <strong>Custom Token</strong> and enter the token contract address and then <strong>Add Token</strong>. Now the tokens should be available in your wallet:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5op32iqbeszizri72qc0.jpg" alt="NDT" width="1500" height="1246" loading="lazy"></p>
<p>Next, let's try to send those coins to another address.</p>
<p>To do so, copy the address of another account and send them to that address using the updated React UI. When you check the token amount, it should be equal to the original amount minus the amount you sent to the address.</p>
<h2 id="heading-how-to-build-an-erc20-token">How to Build An ERC20 Token</h2>
<p>The <a target="_blank" href="https://ethereum.org/en/developers/docs/standards/tokens/erc-20/">ERC20 Token Standard</a> defines a set of rules that apply to all ERC20 tokens which allow them to easily interact with each other. ERC20 makes it really easy for someone to mint their own tokens that will have interoperability with others on the Ethereum blockchain.</p>
<p>Let's look at how we can build our own token using the ERC20 standard.</p>
<p>First, install the <a target="_blank" href="https://github.com/OpenZeppelin/openzeppelin-contracts">OpenZepplin</a> smart contract library where we will be importing the base <code>ERC20</code> Token:</p>
<pre><code class="lang-sh">npm install @openzeppelin/contracts
</code></pre>
<p>Next, we'll create our token by extending (or inheriting from) the <code>ERC20</code> contract:</p>
<pre><code class="lang-solidity"><span class="hljs-comment">//SPDX-License-Identifier: MIT</span>
<span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.8.3;</span>

<span class="hljs-keyword">import</span> <span class="hljs-string">"@openzeppelin/contracts/token/ERC20/ERC20.sol"</span>;

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">NDToken</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC20</span> </span>{
    <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> name, <span class="hljs-keyword">string</span> <span class="hljs-keyword">memory</span> symbol</span>) <span class="hljs-title">ERC20</span>(<span class="hljs-params">name, symbol</span>) </span>{
        _mint(<span class="hljs-built_in">msg</span>.<span class="hljs-built_in">sender</span>, <span class="hljs-number">100000</span> <span class="hljs-operator">*</span> (<span class="hljs-number">10</span> <span class="hljs-operator">*</span><span class="hljs-operator">*</span> <span class="hljs-number">18</span>));
    }
}
</code></pre>
<p>The constructor allows you to set the token name and symbol, and the <code>_mint</code> function allows you to mint the tokens and set the amount.</p>
<p>By default, ERC20 sets the number of decimals to 18, so in our <code>_mint</code> function we multiply 100,000 by 10 to the 18 power to mint a total of 100,000 tokens, each with 18 decimal places (similarly to how 1 Eth is made up of 10 to the 18 <a target="_blank" href="https://www.investopedia.com/terms/w/wei.asp">wei</a>.</p>
<p>To deploy, we need to pass in the constructor values (<code>name</code> and <code>symbol</code>), so we might do something like this in our deploy script:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> NDToken = <span class="hljs-keyword">await</span> hre.ethers.getContractFactory(<span class="hljs-string">"NDToken"</span>);
<span class="hljs-keyword">const</span> ndToken = <span class="hljs-keyword">await</span> NDToken.deploy(<span class="hljs-string">"Nader Dabit Token"</span>, <span class="hljs-string">"NDT"</span>);
</code></pre>
<p>By extending the original ERC20 token, your token will inherit all of the following functions and functionality:</p>
<pre><code class="lang-solidity"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">name</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">string</span></span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">symbol</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">string</span></span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">decimals</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint8</span></span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">totalSupply</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span></span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">balanceOf</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> _owner</span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span> balance</span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">transfer</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> _to, <span class="hljs-keyword">uint256</span> _value</span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span> success</span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">transferFrom</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> _from, <span class="hljs-keyword">address</span> _to, <span class="hljs-keyword">uint256</span> _value</span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span> success</span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">approve</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> _spender, <span class="hljs-keyword">uint256</span> _value</span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">bool</span> success</span>)
<span class="hljs-title"><span class="hljs-keyword">function</span></span> <span class="hljs-title">allowance</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> _owner, <span class="hljs-keyword">address</span> _spender</span>) <span class="hljs-title"><span class="hljs-keyword">public</span></span> <span class="hljs-title"><span class="hljs-keyword">view</span></span> <span class="hljs-title"><span class="hljs-keyword">returns</span></span> (<span class="hljs-params"><span class="hljs-keyword">uint256</span> remaining</span>)</span>
</code></pre>
<p>Once deployed, you can use any of these functions to interact with the new smart contract. For another example of an ERC20 token, check out Solidity by example here: <a target="_blank" href="https://solidity-by-example.org/app/erc20/">https://solidity-by-example.org/app/erc20/</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Ok, we covered a lot in this article. But for me this is kind of the bread and butter / core of getting started with this stack. </p>
<p>It's kind of what I wanted to have, not only as someone who was learning all of this stuff, but also in the future if I ever need to reference anything I may need. I hope you learned a lot.</p>
<p>If you want to support multiple wallets in addition to MetaMask, check out <a target="_blank" href="https://github.com/Web3Modal/web3modal">Web3Modal</a> which makes it easy to implement support for multiple providers in your app with a fairly simple and customizable configuration.</p>
<p>In my future tutorials and guides, I'll be diving into more complex smart contract development and also how to deploy them as <a target="_blank" href="https://thegraph.com/docs/define-a-subgraph">subgraphs</a> to expose a GraphQL API on top of them and implement things like pagination and full text search.</p>
<p>I'll also be going into how to use technologies like IPFS and Web3 databases to store data in a decentralized way.</p>
<p>If you have any questions or suggestions for future tutorials, let me know.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Universal Ethereum Delegated Transactions: No More Transaction Fees ]]>
                </title>
                <description>
                    <![CDATA[ TL;DR Check this back end and front end solutions for delegated transactions. It is universal for any token which supports the delegation of its functions. Read more below. This mostly technical article provides a universal framework and a working s... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/universal-ethereum-delegated-transactions-no-more-ethereum-fees/</link>
                <guid isPermaLink="false">66b99b7c3cd81de09c96b2bc</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ crypto ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptocurrency ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ethereum blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ token economy ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Tokenization ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Nikita Savchenko ]]>
                </dc:creator>
                <pubDate>Mon, 30 Sep 2019 15:53:22 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/09/you-need-some-ether-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <blockquote>
<p>TL;DR Check this <a target="_blank" href="https://github.com/ZitRos/ethereum-delegated-tx-service">back end</a> and <a target="_blank" href="https://zitros.github.io/ethereum-delegated-tx-widget/">front end</a> solutions for delegated transactions. It is universal for any token which supports the delegation of its functions. Read more below.</p>
</blockquote>
<p>This mostly technical article provides a <strong>universal framework</strong> and a <strong>working solution</strong> for Ethereum tokens and applications that eliminates the need to pay fees in Ether, a problem that is practically killing the user experience of many blockchain applications.</p>
<blockquote>
<p><em>Imagine spending dollars and then being asked to also hand over some</em> <a target="_blank" href="https://en.wikipedia.org/wiki/Ukrainian_hryvnia"><em>Hryvnias</em></a> <em>as a transaction fee. That's how Ethereum tokens work so far.</em></p>
</blockquote>
<p>In other words, for example, to transfer any Ethereum token (like <a target="_blank" href="https://coinmarketcap.com/currencies/tether/">Tether</a>, <a target="_blank" href="https://coinmarketcap.com/currencies/dai/">DAI</a>, <a target="_blank" href="https://coinmarketcap.com/currencies/basic-attention-token/">BAT</a>, <a target="_blank" href="https://token.dreamteam.gg/">DREAM</a>, etc.), the user has to also spend some <a target="_blank" href="http://ethereum.org/use/#_2-what-is-eth-and-how-do-i-get-it">Ether</a> (internal Ethereum platform currency). This introduces a big inconvenience that prevents the mass adoption of DApps: users have to purchase multiple currencies instead of just one to interact with the blockchain network.</p>
<h1 id="heading-the-problem">The Problem</h1>
<p>Tokens, as we imagine them today are just fuel for applications and services on top of blockchain networks. Organizations create their own tokens (using ICOs, IEOs, etc) and run services/applications that utilize them, introducing their own micro-economy (widely known as a <a target="_blank" href="https://medium.com/@pentremont/token-economy-101-or-why-blockchain-powered-decentralized-networks-are-important-310de1cc8bac">token economy</a>). But almost every token turns out to be quite a complex currency itself. By design of how blockchain networks work, in order to do something with your tokens, you also need another currency — often Ether (for Ethereum) to be able to transfer tokens.</p>
<p>To illustrate the problem, let's look into how users come to use different blockchain-powered services and applications like:</p>
<ul>
<li><a target="_blank" href="https://trickle.gg/">Trickle</a> - where you create secure, hourly-based contracts with an untrusted party in any token</li>
<li><a target="_blank" href="https://loomx.io/">Loom</a> - where you use Loom tokens to create sidechains in Loom Network</li>
<li><a target="_blank" href="https://www.cryptokitties.co/">Cryptokitties.co</a> - where you breed, trade and transfer kitties (ERC721 tokens)</li>
<li><a target="_blank" href="https://www.stateofthedapps.com/">Others</a> (there are a lot!)</li>
</ul>
<p>All these applications use tokens, as well as they require you to purchase Ether. The complexity of using crypto tokens as we know them today is one of the biggest reasons why 99% of crypto startups fail (or avoid adopting real crypto, for example, by replacing it with virtual coins).</p>
<p>As you may already know, the harder it is to use the application, the fewer users it will get right from the beginning. This is something known as <a target="_blank" href="https://www.appcues.com/blog/user-onboarding-funnel-amplitude">The User Onboarding Funnel</a>, which is still a big pain for blockchain-powered applications and services:</p>
<p><img src="https://lh3.googleusercontent.com/XJyaZoGARI3TF4DOjODJerEUNwn3qFm2D8WSZBrxwYE81oSHaw5h3MOweymV5VV9Jby-2OBUE7o1FGkVqZxWvONW0GLuoezAKqt8HmB-N-vPwHL_ouohPO2whDyS1jiXHLIQv9am" alt="Image" width="1275" height="359" loading="lazy">
<em>The typical user onboarding funnel of a decentralized, blockchain-based application</em></p>
<p>To understand why I put 0.001% of users prior to the service use, let's see what exactly purchasing some Ether means:</p>
<ul>
<li>Creating a crypto wallet</li>
<li>Registering on Exchange (and learning all the exchange rules, including country policies!)</li>
<li>Passing KYC (though it's getting easier, still, many countries have limited access to exchanges)</li>
<li>Purchasing a minimum allowed amount of Ether (usually, it's <a target="_blank" href="https://changelly.com/widget-settings">whopping $50</a> while you need just nearly $0.05 to perform one or two transactions)</li>
<li>Withdrawing Ether to your wallet</li>
<li>Not to mention reading lengthy guides on how to perform all these steps properly</li>
</ul>
<p>Instead of just:</p>
<ul>
<li>Creating a crypto wallet</li>
</ul>
<p>Of course, it highly depends on how the application or service is made. But, so far, there was no better simplification of the onboarding flow as just cutting crypto tokens from there, or making them fake, "virtual" currency with deposit and withdrawal function. Unfortunately, the latter approach is now the common one across all startups and companies adopting crypto, for many good reasons. Another reason could be a monetization strategy, but this is another big story worth a dedicated article (Interested? Comment out!).</p>
<p>Getting back to the transaction fees problem, we can state the following, which is hard to argue with.</p>
<blockquote>
<p><em>It is natural for the user to purchase <strong>only</strong> the cryptocurrency they really need (for instance, tokens:</em> <a target="_blank" href="https://coinmarketcap.com/currencies/tether/"><em>Tether</em></a><em>,</em> <a target="_blank" href="https://coinmarketcap.com/currencies/dai/"><em>DAI</em></a><em>,</em> <a target="_blank" href="https://coinmarketcap.com/currencies/basic-attention-token/"><em>BAT</em></a><em>,</em> <a target="_blank" href="https://token.dreamteam.gg/"><em>DREAM</em></a><em>, etc.), and they would normally expect to pay any transaction fees <strong>in this cryptocurrency</strong>.</em></p>
</blockquote>
<p>So why not just allow them to do so? Because it's quite complex indeed. Let's see why, and how this has just got easier with our open-sourced solution (at least for Ethereum).</p>
<h1 id="heading-existing-approaches">Existing Approaches</h1>
<p>From the very beginning of blockchain existence, there were a couple of solutions that could simplify the user onboarding flow to the flow depicted below, avoiding the step of purchasing an intermediate currency like Ether. Still, creating a blockchain wallet is not an easy step, but some users who do understand the value of the application/service go through this step quite well.</p>
<p><img src="https://lh3.googleusercontent.com/B_D585TaVcYR9qXA-0q3MfvAv1DjGzAulIup0XT1X8Va3eeekX32jAtayKbFCmKoISotoBk_WOyq9jGAdqJzfAnz5q61foOPjgxeVbcfq8bXlA9X25iqzKczy6qmjPvZJgBYsRrL" alt="Image" width="1275" height="359" loading="lazy">
<em>The user onboarding funnel with delegated transactions</em></p>
<p>The solution which allows to avoid using intermediate currencies (Ether for Ethereum) is called "delegated transactions", or "meta transactions". </p>
<blockquote>
<p><em>In short, delegated transaction, or "meta transaction" in blockchain is the type of transaction which performs an intended action on one account's behalf, while it is conducted (published) by another account (delegate), who actually pays fees for the transaction.</em></p>
</blockquote>
<p>There are <a target="_blank" href="https://medium.com/@austin_48503/ethereum-meta-transactions-90ccf0859e84">multiple</a> <a target="_blank" href="https://fravoll.github.io/solidity-patterns/proxy_delegate.html">approaches</a> <a target="_blank" href="https://medium.com/@e2toe4/ethereum-meta-transactions-36f10448619">around</a> <a target="_blank" href="https://github.com/ethereum/EIPs/issues/1035">the</a> <a target="_blank" href="https://github.com/ethereum/EIPs/issues/1228">internet</a> of the generalized concept of delegated transactions I am presenting in this article. But it seems that none of them are still widely adopted, as these approaches are quite complex by its nature, very specific as for the implementation, as well as some of them are <strong>quite complex to standardize</strong>. To be more constructive, existing approaches can be divided into 3-4 groups: those which use proxy smart contracts, those which embed delegation into a smart contract itself and, theoretically, there is an opportunity for the blockchain-native implementation (say, Ethereum 2.0).</p>
<h2 id="heading-1-delegated-transactions-approaches-which-use-proxy-contracts">1. Delegated transactions approaches which use proxy-contracts</h2>
<p>Proxy contracts, or, in this context, identity contracts are tiny contracts deployed to replace the user account which wants to avoid paying fees. This smart contract is programmed to act as a wallet, as well as a "caller" (sender) of other smart contract's functions. The key is that it is a delegate account that triggers all the actions, while the true "owner" of this smart contract is another user. The user just generates correct signatures in order to control their funds stored on a smart contract address (= in their wallet).</p>
<p><img src="https://lh3.googleusercontent.com/BqoXbK-n6UmpKY-nu8_GuibFbfA3a2Lrghc_fHSoJOzMqv_MYL2BNzIUzyZPgT1aSM00WC0fJoyErLQKc0Dtu3D92NRdYB3Cm4bJ8vZAnbfHVaSe4pCxrEsI8rvEiNCbQriStqfx" alt="Image" width="1025" height="471" loading="lazy">
<em>A visualization of how identity contracts look like</em></p>
<p><strong>Pros of this approach:</strong></p>
<ul>
<li>It works with any tokens and contracts which are already deployed to the network</li>
</ul>
<p><strong>Cons of this approach:</strong></p>
<ul>
<li>Users don't see tokens in their wallet, because they are physically on an identity smart contract</li>
<li>As a result, a need to develop custom UIs and custom tools/wallets</li>
<li>Identity smart contract deployment and assignment initial fees, as opposed to no fees at all</li>
<li>Requires a comprehensive standard to be widely adopted</li>
</ul>
<h2 id="heading-2-semi-delegated-transactions-via-operator-pattern-erc777httpseipsethereumorgeipseip-777">2. Semi-delegated transactions via "Operator" pattern (<a target="_blank" href="https://eips.ethereum.org/EIPS/eip-777">ERC777</a>)</h2>
<p>There is a token standard that describes this approach — <a target="_blank" href="https://eips.ethereum.org/EIPS/eip-777">ERC777</a>. In short, any token holder can authorize any other account to freely manage their tokens. I won't call it delegated transactions but nevertheless, I need to mention that, as here we somewhat delegate control over your tokens to other accounts.</p>
<p><img src="https://lh6.googleusercontent.com/Sf3WEbL4fRfefAZLZIBzxD8nAhLnFt75uIZUSO0SjifRwqbiIwSOUnWf4QkN6v6kmWXBazs05bGnG6w1AOTNZIEXwuVUf6GIPdBNtD60mAwiU5r7Oe4MMlNEGLy5htCrk51zsfwi" alt="Image" width="1025" height="471" loading="lazy">
<em>A visualization of ERC777 standard's "operator" pattern</em></p>
<p><strong>Pros of this approach:</strong></p>
<ul>
<li>Standardized</li>
</ul>
<p><strong>Cons of this approach:</strong></p>
<ul>
<li>Highly centralized around the "operator" accounts</li>
<li>Weak security due to operators have 100% control over your tokens</li>
<li>Initial fees for approval transaction</li>
<li>Requires additional UIs/tools development</li>
</ul>
<h2 id="heading-3-delegated-transactions-embedded-directly-into-a-token-smart-contract">3. Delegated transactions embedded directly into a (token) smart contract</h2>
<p>Just the same as it is possible to implement custom fees in a proxy smart contract, paying fees in tokens can be implemented directly in a token smart contract. For example, using the approach I described in <a target="_blank" href="https://hackernoon.com/you-dont-need-ether-to-transfer-tokens-f3ae373606e1">my previous article</a>, it is possible to implement a function in a smart contract, which will transfer tokens accepting the user's signature, instead of requiring the user to call this function directly. We have implemented this approach in our <a target="_blank" href="https://token.dreamteam.gg/">DREAM Token</a>, which is used on our <a target="_blank" href="https://dreamteam.gg/">dreamteam.gg</a> platform.</p>
<p><img src="https://lh3.googleusercontent.com/NTd44yatekkdfGEOfSDdsXi1S8cmtRdkQLXmUKSIm-nFzMMQdOM1Rox1nML6Y2Z8gYh9t_sMIsPvr7L7AHxTPlYXp0ENnVWQBLf5g85Cue-CiR2zb1Xw4Ym4G407MQOhCUUnSrrQ" alt="Image" width="1025" height="471" loading="lazy">
<em>A visualization of how embedding delegation into the token contract looks like</em></p>
<p>As you may notice, in contrast to the previous approach there is no identity contract anymore, and there is an optional way to call other smart contracts directly from the token contract.</p>
<p><strong>Pros of this approach:</strong></p>
<ul>
<li>Users see their tokens as usual on their wallet's balance</li>
<li>No initial fees for account initialization</li>
<li>May not even require a standard (continue reading)</li>
</ul>
<p><strong>Cons of this approach:</strong></p>
<ul>
<li>If you have a (token) smart contract that is already deployed to the network, you cannot apply this approach to it directly. While you can always deploy a new token and, for example, a "migration" utility, which will allow other users to swap tokens (burn the old token and mint a new one)</li>
<li>Because a standard for this approach is yet not well-defined, implementation can drastically vary</li>
<li>A need to develop custom UI/tools for delegated transactions (continue reading — solved!)</li>
</ul>
<h2 id="heading-4-delegated-transactions-on-the-blockchain-platform-level">4. Delegated transactions on the (blockchain) platform level</h2>
<p>This is far the best one of all the described approaches above but also the one <strong>which is not implemented anywhere yet</strong> (by anywhere I mean the most popular blockchain platforms). There is a hope that its support comes with Ethereum 2.0 release, or at least I've heard from Vitalik that they are in progress with something cool there.</p>
<p>Theoretically, we can imagine this approach as being able to make an "offline" signature of two transactions at a time: one which does something useful for the signing account which wants to avoid paying fees (for example, transferring tokens) and another one which does something useful for the delegate (for example, paying fee in tokens to the account which executes these two transactions).</p>
<p><img src="https://lh5.googleusercontent.com/R1S5_YVazRlh2mfzuMLaKAnix8GmXJy4swBQyxzWFzhIZhE5nDTZ4gfOLp9G51dx-ydW7sLQCsWkic6k_nVj_1CD8JkHjGjRYSMwt17wGSLAG58Vs2ve02KS3L5m5L2oTCMWfxlG" alt="Image" width="1142" height="505" loading="lazy">
<em>A visualization of how platform-native delegated transactions could look like</em></p>
<p>But the problem is, regarding Ethereum 2.0, this feature has a chance to land only in 2022 or even later. I also suppose that this feature will still require a dedicated back end (similar to the one which is introduced within this article), as it is hard to imagine how miners will accept fees in tokens. Simply put, if some of them refuse to accept fees in tokens than it makes little sense to do it on a "mining" level at all, not to mention how much would it take to track all token prices and volumes across exchanges, in a decentralized manner.</p>
<p><strong>Pros of this approach:</strong></p>
<ul>
<li>No need to change smart contracts that were already deployed</li>
<li>No initial fees for account initialization</li>
<li>May not even require a custom UI/tools if standardized</li>
</ul>
<p><strong>Cons of this approach:</strong></p>
<ul>
<li>Most likely, will still require a centralized back end (the "delegate")</li>
<li>Not yet implemented on a platform level (as of 2019)</li>
</ul>
<h1 id="heading-the-solution">The Solution</h1>
<p>From the four approaches above, except for the platform-level approach which is yet to be implemented and standardized in 2022+, the most appealing one is <strong>the third approach</strong>, where we embed delegated functions directly to the token smart contract. Thus, we save the standard token paradigm allowing wallets to normally work with the smart contract and have no need to wait until delegated transactions will land natively in one of the top blockchain platforms. We will stick to this approach and make it <strong>universal</strong> just below.</p>
<p>Delegated transactions support programmed right in the token smart contract is awesome. But how to deal with its cons? In fact, the only problem which is tough to deal with (as you cannot modify existing smart contracts), <strong>you will need to deploy a new token smart contract if you have already deployed it without delegated functions</strong> (for instance, standard ERC20 or ERC721 tokens). The next step, in this case, would be adding a way to migrate tokens from one smart contract to another. For example, you can decide to implement one more function in the new smart contract that will allow token holders to migrate their assets from the old smart contract.</p>
<p>Token migration function implementation can vary, starting from implementing <em>receiveApproval</em> in the new token, if the previous token supports <em>approveAndCall</em>, or ending with utilizing <em>approve</em> + <em>transferFrom</em> framework if you have just a bare minimal ERC20 (the user _approve_s tokens to the new token contract address and then calls a function in the new contract which burns old tokens and mints new ones — but this requires a standard fee for the user for the approval transaction). Actually, there is more: you can decide not to burn old tokens but to "lock" them on a new token smart contract, minting new tokens — this opens an opportunity to implement <strong>two-sided token migration</strong>, which is awesome — <strong>you won't need to list the "new" token on the exchange</strong>, while the users will still be able to send the old token to exchanges without fees in Ether! If you are interested, please fill the issue <a target="_blank" href="https://github.com/ZitRos/ethereum-delegated-tx-service/issues">here</a> if you want to know more details on how to do it, because this approach is worth a whole new article.</p>
<p>In my <a target="_blank" href="https://hackernoon.com/you-dont-need-ether-to-transfer-tokens-f3ae373606e1">previous article</a>, I provided an example of the token smart contract which supports delegation of such functions like <em>transfer</em>, <em>transferFrom</em>, <em>approve</em> and <em>approveAndCall</em>. Exactly these "delegated" functions allow users to pay fees in tokens, instead of Ether.</p>
<p><img src="https://lh6.googleusercontent.com/K95psDr4YlNLWPFIByI6HmE5DOz-uIGmD9xfNODmhfj6oRfkIlGJwkZLPYBEVof4MwitQe5Li6SbUNptplVKL2MfERLbVHLJru5jJkTpCVDnDaQbpMd24wtbWOTp81hX7CHtiRtR" alt="Image" width="1568" height="609" loading="lazy">
<em>How delegation works in Ethereum, in short. Read more in <a target="_blank" href="https://hackernoon.com/you-dont-need-ether-to-transfer-tokens-f3ae373606e1">this article</a>.</em></p>
<p>But that wasn't enough to start the mass adoption. In this article, I am providing a complete <a target="_blank" href="https://github.com/ZitRos/ethereum-delegated-tx-service">universal back end solution</a> (Transaction Publisher in the picture above), as well as a <a target="_blank" href="https://github.com/ZitRos/ethereum-delegated-tx-widget">configurable widget</a> (<a target="_blank" href="https://zitros.github.io/ethereum-delegated-tx-widget/">check it here</a>), which allows you to replace Ether fees for token fees today.</p>
<p>Some key points before we dive in:</p>
<ul>
<li>This delegated transactions back end is made to be universal, or <strong>standard-free</strong>, meaning that you can have <strong>any implementation</strong> of delegated functions and <strong>use any signature standard(s)</strong> in your token. From the back end standpoint, you just need to write a manifest file for your token, describing its usage.</li>
<li>Currently, converting collected fees in tokens back to Ether is a manual action on exchanges. But it could be a potential improvement for automation in the future (if needed).</li>
</ul>
<h1 id="heading-the-concept-behind-the-universal-solution">The Concept Behind the Universal Solution</h1>
<p>What does it mean that the token supports delegated transactions? Let's look at it using the ERC20 standard token as an example.</p>
<h2 id="heading-smart-contract">Smart Contract</h2>
<p>As for the token smart contract, the approach is quite straightforward. In addition to every method like <strong>transfer(to, value)</strong> which we want to be "delegatable", we add a companion function which, instead of inspecting <strong>msg.sender</strong>, accepts the signature of a user and does the same what the original function meant to do by validating this signature inside the smart contract. Thus, for example, for <strong>transfer(to, value)</strong> function we can add <strong>transferViaSignature(to, value, ...aditionalParams)</strong> function. As you know from <a target="_blank" href="https://en.wikipedia.org/wiki/Public-key_cryptography">public-key cryptography</a>, no one can create a valid signature except private key owner, so that's why this approach is as secure as Ethereum itself.</p>
<p>And the coolest part is that the delegated function implementation, as well as its signature doesn't matter much, from the delegate back end standpoint. You can even decide to implement one "call by signature" function for all other functions that the smart contract supports. Delegate back end just need to know <strong>how</strong> to call this function, which is solved by providing an off-chain contract manifest for the delegate back end. For example, the argument <em>additionalParams</em> in <strong>transferViaSignature</strong> can vary and can include anything from this list, if not more: fee, fee recipient address, expiration timestamp, a signature standard used, a signature itself, nonce number or any other unique delegated transaction ID and so on. Regarding the smart contract design, in order to understand why exactly these arguments, read my <a target="_blank" href="https://hackernoon.com/you-dont-need-ether-to-transfer-tokens-f3ae373606e1">previous article</a>.</p>
<p>We also want to allow "delegates" to earn something in order to cover their Ether spending, as well as to be profitable. Thus, we have to add a fee, but a much more natural fee than Ether: a fee in the token itself. So that, for example, if you need to transfer 100 tokens, you pay 3 more tokens to the delegate depending on its price and network conditions to perform a transfer, and this should be preserved in a smart contract logic.</p>
<h2 id="heading-back-end">Back End</h2>
<p>All right, now we have a token that allows transferring someone else's tokens by using their signature. Now, the crucial part is to automate the process of requesting and publishing such transactions. And here where our open-sourced <a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-service">back end</a> (and a <a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-widget">front end</a>) kicks in.</p>
<p>Below is the sequence diagram describing how front end (client) communicates with the back end from the delegated transaction request to its publishing to the network:</p>
<ol>
<li>(hidden on the diagram) The client requests information from the delegated back end to understand which contracts does it support, as well as which functions can it delegate.</li>
<li>The client requests a particular smart contract's function to be delegated. Most importantly, the back end returns the fees it charges and a data to be signed by the client.</li>
<li>The client signs the data in their wallet. Signing is a free operation, unlike publishing transaction to the network.</li>
<li>The client sends their signature back, thus confirming their intent to perform this particular delegated transaction. The back end validates this transaction against the current network.</li>
<li>Finally, the back end publishes a transaction to the network.</li>
<li>(hidden on the diagram) The client constantly polls the back end for the delegated request status until it receives a mined status. Note: it is important to poll the back end instead of using a transaction hash to understand when the transaction is mined. It is a very common case when the gas price suddenly increases, and, in order for the transaction to be mined quickly, the back end may republish it with a higher gas price. Though it is currently not implemented, it is very likely to be implemented soon.</li>
</ol>
<p><img src="https://lh5.googleusercontent.com/X2SADmcB2aMcJoUgN291XXPdk73sVNi4ebruRwN6TCcDgVWi7ILZs02Mlz0WSR4ufOnzXqxrHIdTSJyijeSKsTw1Z89vB0zjwD8dvQ3Jop6Z4xPKET1TWBnNDBad5QDlD8y0jptG" alt="Image" width="1600" height="1190" loading="lazy">
<em>Sequence diagram representing the simplified flow of how delegated transaction is delivered to the network</em></p>
<p>This approach is universal, and only requires the manifest file for the back end to understand how to calculate fees and which signature standard to use on the client side. Here is another visualization of the components of the system and their interaction sequence:</p>
<p><img src="https://lh4.googleusercontent.com/EmfRndRu7BJyU9UTYVGt_rKlQIE83v21s7UywoeTeZQ3Y832Z85KgYRQgmB4o9bqUS7OExMGy2ace6kc3v7QEL-t0bcsvsg9xu9zqLdKDUrzHWXrhHnwoOQWUkd8GBAOWwLww5e8" alt="Image" width="1459" height="934" loading="lazy">
<em>Component diagram</em></p>
<p>We've provided a comprehensive <a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-service#delegated-transactions-concept">documentation</a> for this solution. You can check how the back end <a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-service#api">API is structured</a>, as well as find the token <a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-service/blob/master/config/contracts/mainnet/0x82f4ded9cec9b5750fbff5c2185aee35afc16587/manifest.js">manifest file</a> which describes how to work with a <a target="_blank" href="https://etherscan.io/address/0x82f4ded9cec9b5750fbff5c2185aee35afc16587#code">particular token contract</a>. We encourage you to contribute your own tokens there!</p>
<p>And you don't need much setup: it's already there with the universal front end!</p>
<h2 id="heading-front-end">Front End</h2>
<p><a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-widget">Open-sourced front end part</a> of the delegated transactions is the user interface which is <strong>set up for every token</strong>: just run your delegated transactions back end and you are ready to go!</p>
<p><img src="https://lh4.googleusercontent.com/8TagMGFbuyXbiIEe8_x7cmBycjrAxcpE8zyURXmDIF1cQET-K64NchEmK0lWfNpwR5mzcJIQ5YLp--hLSCksLlMflOAPBbDCf2frPrF4xm6cEZ92GNXH-QDA3MBKpokX4O2tZoUq" alt="Image" width="689" height="908" loading="lazy">
<em>What <a target="_blank" href="https://send-token.dreamteam.gg">it</a> looks like</em></p>
<p>It is made to be an embeddable widget, which will guide the user through the procedure of sending tokens. You can plug any back end, token or call any token function with it by utilizing <a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-widget#embedding">additional URL parameters</a> you can specify.</p>
<p>Using this widget, and by implementing something similar to widely used, but not standardized <em><strong>approveAndCall</strong></em> function in your token smart contract, you will be able to call other smart contracts with arbitrary data by paying fees in tokens!</p>
<p>Here is a quick guide for you if you want to play with this UI yourself:</p>
<ol>
<li>Access the widget via <a target="_blank" href="https://zitros.github.io/ethereum-delegated-tx-widget/?contractAddress=0xcc7e25e30b065ea61814bec6ecdb17edb0f891aa">this link</a>.</li>
<li>It will ask you to switch to the Kovan test network.</li>
<li>Get some test Ether using <a target="_blank" href="https://www.google.com/search?q=ethereum+kovan+faucet">any available Kovan faucet</a>.</li>
<li>Use test Ether to mint some <a target="_blank" href="https://kovan.etherscan.io/address/0xcc7e25e30b065ea61814bec6ecdb17edb0f891aa#writeContract">test tokens</a>: call <a target="_blank" href="https://kovan.etherscan.io/dapp/0xcc7e25e30b065ea61814bec6ecdb17edb0f891aa#writeContract">mintTokens</a> function in a token smart contract which will give you 10 test tokens.</li>
<li>Now, get back to <a target="_blank" href="https://zitros.github.io/ethereum-delegated-tx-widget/?contractAddress=0xcc7e25e30b065ea61814bec6ecdb17edb0f891aa">the widget</a> and try to transfer these tokens!</li>
</ol>
<p>If you open up the browser's developer tools, you may notice that there are a couple of back ends connected by default — they provide the front end with all required information to make a delegated request according to given widget URL parameters. All backends are requested during the widget load and, if any of them can provide a delegation for a particular contract's function, then the widget requests additional information: fees, supported signatures, etc. If there are multiple back ends which can delegate the same contract function, all of them are requested and the back end which provides the best fee will be used for the transaction.</p>
<p>Transaction mining time is seemingly fixed, but it can vary because of the network conditions. The back end uses an actual network fee when calculating the token fee, however, it may change before the user decides to execute the transaction. Thus, the "underpriced" transaction is submitted to the network and can be pending for a while. While the back end is currently not programmed to deal with this case, it might be implemented in future — transactions will be republished with higher gas fees in case of the network fee increases. But, we will also need to count this into the token fee.</p>
<h2 id="heading-signature-standards">Signature Standards</h2>
<p>The last question which you may be wondering is — which signature standard to use for your token. There are several available: _eth<em>sign</em> (deprecated), _eth<em>personalSign</em> (note that old <a target="_blank" href="https://trezor.io/">Trezor</a> and <a target="_blank" href="https://www.ledger.com/">Ledger</a> produce a different signatures because of ambiguity in a standard, so you may want to include both), _eth<em>signTypedData</em> (deprecated), <a target="_blank" href="https://medium.com/metamask/eip712-is-coming-what-to-expect-and-how-to-use-it-bb92fd1a7a26">_eth_signTypedData<em>v3</em></a> and so on. I would recommend supporting at least two: ageless _eth<em>personalSign</em> and new <a target="_blank" href="https://medium.com/metamask/eip712-is-coming-what-to-expect-and-how-to-use-it-bb92fd1a7a26">_eth_signTypedData<em>v3</em></a> (as of 2019).</p>
<p><img src="https://lh3.googleusercontent.com/TZhSpdfJF_035M1uCARZVYixZC4W8hsiG1jbs2zTyYZQC5fpwJUR3W7x14WaLofyklmEaR9O4Cgt7EkKb7MCb1RHK6geJfxKb-oGVVxlOXBOu6dh5c6nRtNwblF5B0sZ07Gf6mV7" alt="Image" width="1408" height="1279" loading="lazy">
<em>Signature standards comparison — what the user sees</em></p>
<p>The front end is programmed to always prefer the user-readable standard like <a target="_blank" href="https://medium.com/metamask/eip712-is-coming-what-to-expect-and-how-to-use-it-bb92fd1a7a26">eth_signTypedData_v3</a> to any others eth_personalSign. So if your token supports many signature standards, and you added all of them to the <a target="_blank" href="https://github.com/dreamteam-gg/ethereum-delegated-tx-service/blob/master/config/contracts/mainnet/0x82f4ded9cec9b5750fbff5c2185aee35afc16587/manifest.js">manifest file</a> of your token, it will display <a target="_blank" href="https://medium.com/metamask/eip712-is-coming-what-to-expect-and-how-to-use-it-bb92fd1a7a26">eth_signTypedData_v3</a> prompt first.</p>
<h1 id="heading-conclusion">Conclusion</h1>
<p>Delegated transactions are great: they solve one of the biggest problems of blockchain application adoption, which eases the mass adoption of crypto overall. I will put a couple of thesis in a Q&amp;A format here for you to answer the last questions that you may still have after reading this article:</p>
<ul>
<li>Our open-source solution is free to use and production-ready, feel free to apply it to your applications or tokens!</li>
<li>The described approach does not compromise security nor centralization. Think this way: the centralized back end is only a helper for someone who wants to transfer tokens without fee in Ether. If the back end is hacked, or it is just unavailable, there's no problem to interact with the network just as it was before, by paying fees in Ether. As well as the back end cannot harm or trick the user to steal their tokens when a proper signature standard is used (it's up to your token implementation).</li>
<li>There is a way to support delegated transactions for existing, already-deployed tokens. However, it requires the additional Ether-consuming step to migrate existing tokens to a new token contract. And, by programming a new token contract properly, as well as designing your application to work with both tokens you can even avoid a need to list a new token on exchanges.</li>
<li>By using the <a target="_blank" href="https://github.com/zitros/ethereum-delegated-tx-service/blob/master/config/contracts/mainnet/0x82f4ded9cec9b5750fbff5c2185aee35afc16587/manifest.js">existing tokens as an example</a>, which is available in delegated transactions <a target="_blank" href="https://github.com/zitros/ethereum-delegated-tx-service">back end</a> and <a target="_blank" href="https://github.com/zitros/ethereum-delegated-tx-widget">front end</a> repositories, you can produce your own manifest for your own token.</li>
<li><a target="_blank" href="https://github.com/zitros/ethereum-delegated-tx-service#setup">Read the instructions</a> on how to set up your own back end for a token, and then add it to the URL of your widget (or commit to the open-source repository).</li>
<li>Have a token which already supports delegated transactions? Plug it into <a target="_blank" href="https://zitros.github.io/ethereum-delegated-tx-widget">our UI</a> with these three quite simple steps: (1) create a manifest for your token and put your token abi file while setting up the delegate back end, (2) run this back end, exposing a public API URL and (3) use URL parameters in a widget to reference your back end or commit it directly to our open-source repository. Read more about it in GitHub's readme file.</li>
</ul>
<p>I hope that was a really helpful piece of information for all the searchers of incredible. Feel free to contact <a target="_blank" href="https://nikita.tk/">me</a> or fill the issue <a target="_blank" href="https://github.com/ZitRos/ethereum-delegated-tx-service/issues">here</a> if I missed something. Have fun, let the token economy be simple!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Technical primer to Blockchain & Ethereum ]]>
                </title>
                <description>
                    <![CDATA[ By Srinivasan C I attended a talk on Ethereum sometime back and was fascinated by the possibilities it provided and started exploring the ecosystem. It is a pretty nascent ecosystem that is catching up fast among the developer community. In this post... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/technical-primer-to-blockchain-ethereum/</link>
                <guid isPermaLink="false">66d4614fbd438296f45cd3be</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Cryptocurrency ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ethereum blockchain ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Tue, 23 Jul 2019 06:30:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9ca14a740569d1a4ca4dc5.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Srinivasan C</p>
<p>I attended a talk on Ethereum sometime back and was fascinated by the possibilities it provided and started exploring the ecosystem. It is a pretty nascent ecosystem that is catching up fast among the developer community. In this post I will explain the technology behind Ethereum so that we can get started with developing with Ethereum. This assumes you have technology background and basic understanding of blockchain so that we can discuss the Ethereum implementation.</p>
<h2 id="heading-first-things-first">First things first</h2>
<p>Blockchain provides a <strong>de-centralized</strong>, <strong>peer to peer</strong> network where digital assets can be transferred from one peer to another. The major problem we face in a de-centralized network is who will verify the validity of all the <strong>transactions</strong> taking place? The short answer is <strong>everyone.</strong></p>
<p>Imagine a document with some information . Each person in the network keeps a copy of the same document. If there is an update in the document, it is propagated across the network and everyone updates their own copy of the document. Lets say a new person comes with different content in the document, then all the others can verify their copy and detect that the new person is lying and kick him out of the network. This is basically how a blockchain works.</p>
<p>First we need to understand few basic terms to get started.</p>
<h3 id="heading-hash">Hash</h3>
<p>We can use a cryptographic hash function(SHA256) to convert any string to its equivalent hash. The hash has two unique properties:</p>
<ol>
<li>The hash produced has <strong>one to one mapping</strong> with the input string. The same input always produces the same unique hash and no other input can have the same hash.</li>
<li>Even a <strong>small change</strong> in the input string will lead to a <strong>large change</strong> in the output hash and thus the input can be easily validated.</li>
</ol>
<h3 id="heading-transaction">Transaction</h3>
<p>The process by which assets are moved from one party to another in the network is known as Transaction. All transactions are recorded and permanently stored.Lets say A wants to transfer 5 Ether to B. Then this is a transaction in the network.</p>
<h3 id="heading-block">Block</h3>
<p>Many transactions are combined together to form a block. Each block consists a unique <strong>hash</strong> which identifies it in the network. A block is chained to previous block using the hash of the previous block.</p>
<h3 id="heading-genesis-block">Genesis Block</h3>
<p>The initial block or state of the blockchain that is agreed upon by all the nodes in the network.</p>
<h3 id="heading-blockchain">Blockchain</h3>
<p>As the transactions are added many blocks are created and then they are chained together using their hashes into blockchain network.</p>
<h3 id="heading-proof-of-work">Proof of work</h3>
<p>A <strong>proof of work</strong> is a piece of data which is difficult (costly, time-consuming) to produce but easy for others to verify and which satisfies certain requirements. When there is a transaction in the network, any node that tries to process the transaction should solve a cryptographic puzzle for it to be accepted to the block. This is known as proof of work. The work that is to be performed can be done only by trial and error and this has to be performed for any valid transaction in the network before it can become part of the blockchain.</p>
<h3 id="heading-mining">Mining</h3>
<p>The process of processing a transaction and adding it to the block by carrying out the proof of work is known as mining. The miners(nodes) get the rewards of the transaction once the transaction is accepted as part of the blockchain.</p>
<h3 id="heading-merkle-tree">Merkle Tree</h3>
<p>A <strong>Merkle tree</strong> is a tree in which every non-leaf node is labelled with the hash of the labels of its child nodes. We can verify that the data blocks received from other nodes are received undamaged and unaltered, and even to check that the other nodes do not lie and send fake blocks.</p>
<h3 id="heading-working">Working</h3>
<p>We can now move on to basic working of a blockchain.</p>
<ol>
<li>Each node starts with genesis block and builds its way up to the “current state” of the blockchain. When it receives a new block each node verifies its hash and thus validates if its a valid block or not and keeps building the chain.</li>
<li>Once there is a transaction in the network, the miner mines it by generating the required proof of work. Then the miner adds it to his copy of the network and <strong>propagates</strong> the change to the nearby nodes.</li>
<li>All the nodes which receives it will validate the proof of work and then add it to their respective copies. If it is not valid, then the block is not added to the chain.</li>
<li>When there is a conflict in the network , then the “longest chain rule” is applied to resolve it. Lets say two miners claim the same block and both have valid proof of work. Then the longest chain rule is applied which is whichever miner has the longest chain of blocks will be taken as the winner and that is added to the blockchain.</li>
</ol>
<h2 id="heading-ethereum">Ethereum</h2>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*AReX8uZOZKpGcvuUjogh0g.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Now that you have got a grasp of blockchain lets move ahead with Ethereum. Ethereum is a <strong>decentralized platform that</strong> allows us to write applications that run exactly as programmed without any possibility of downtime, censorship, fraud or third party interference. It consists of Ethereum Virtual Machine(EVM) which provides the container in which all the smart contracts can be executed.</p>
<h3 id="heading-smart-contracts">Smart contracts</h3>
<p>Ethereum allows us to write applications on the blockchain and this applications are known as smart contracts. These smart contracts reside on the blockchain and they are <strong>immutable</strong> in nature, ie. the code cannot be deleted or modified in the blockchain once it is deployed. This can be written using Solidity or other languages, but the most preferred is solidity. It is a turing complete language.</p>
<h3 id="heading-ether">Ether</h3>
<p>Ether is the cryptocurrency used in the Ethereum blockchain.</p>
<h3 id="heading-accounts">Accounts</h3>
<p>In Ethereum, the state is made up of objects called “accounts”, with each account having a 20-byte address and state transitions being direct transfers of value and information between accounts. There are two types of accounts in Ethereum:</p>
<ul>
<li><strong>Externally owned accounts :</strong> These accounts are owned by users, controlled by private keys. An externally owned account has no code, and one can send messages from an externally owned account by creating and signing a transaction.</li>
<li><strong>Contract accounts:</strong> These accounts are owned by contract code. In a contract account, every time the contract account receives a message its code activates, allowing it to read and write to internal storage and send other messages or create contracts in turn.</li>
</ul>
<h3 id="heading-gas">Gas</h3>
<p>As smart contracts are turing complete any infinity loop or other code can be written and the blockchain can be crashed. To prevent from such attacks Ethereum uses a concept called gas. Gas is nothing but some transaction cost which is paid to execute the transaction using Ether(basic currency in Ethereum chain). Each instruction requires some gas to be executed and the gas is sent along with any call that needs to modify the blockchain.</p>
<h3 id="heading-dapps">DAPPS</h3>
<p>These are distributed apps that can be built using the smart contracts and providing an interface for the users(accounts). Different kinds of applications can be developed which will interact with smart contracts residing in the blockchain.</p>
<h3 id="heading-basic-workflow-using-ethereum">Basic Workflow using Ethereum</h3>
<p>We can discuss a basic workflow in Ethereum network for better understanding of how all these concepts work together in unison.</p>
<ol>
<li>We can write smart contracts and deploy it to Ethereum network. Once deployed these contracts cannot be changed.</li>
<li>Any account or another smart contract in the network can execute these smart contracts functions through transactions.</li>
<li>The smart contracts can be called and executed by sending transactions to the contract. These transactions cost <strong>gas</strong> and a certain gas should also be sent along with the transaction.</li>
<li>Sometimes we just need to know the state of some contract without modifying the blockchain. These are known as <strong>calls and they do not cost any gas.</strong></li>
<li>We can build various Dapps by executing the smart contracts using transactions and calls , thus allowing the user to directly interact the smart contract in different ways.</li>
</ol>
<p>I believe this post provides basic understanding of the blockchain and Ethereum. In my next post I will provide a detailed guide to getting started with building Dapps using Ethereum.</p>
<p><em>If you liked this story, feel free to reach out to me at <a target="_blank" href="https://kaizencoder.com/contact">https://kaizencoder.com/</a></em></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Build your first blockchain app with Ethereum smart contracts and Solidity ]]>
                </title>
                <description>
                    <![CDATA[ Learn how to build a blockchain app using Ethereum smart contracts in this video course from Dapp University. A smart contract is a collection of code and data that resides at a specific address on the Ethereum blockchain. You will learn how to creat... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/blockchain-app-etherium-solidity/</link>
                <guid isPermaLink="false">66b200cfa2135cc2539a212c</guid>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ethereum blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Solidity ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Fri, 28 Jun 2019 13:35:45 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/06/blockchain.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Learn how to build a blockchain app using Ethereum smart contracts in this video course from Dapp University. A smart contract is a collection of code and data that resides at a specific address on the Ethereum blockchain.</p>
<p>You will learn how to create a todo app with Ethereum smart contracts using the Solidity programming language. You will also learn to write tests, deploy to the blockchain, and create a client-side application.</p>
<p>You can watch the full video course on the <a target="_blank" href="https://www.youtube.com/watch?v=coQ5dg8wM2o">freeCodeCamp.org YouTube channel</a> (1.5 hour watch).</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to set up a multi-node private Ethereum blockchain on your Mac ]]>
                </title>
                <description>
                    <![CDATA[ By Prashant Ram In this tutorial we will: Setup a blockchain with multiple nodes Setup mining nodes Connect the multiple nodes and setup the blockchain network Test the blockchain network by mining blocks and verifying that blocks are propagated to ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-set-up-a-multi-node-private-ethereum-blockchain-from-scratch-in-20-mins-or-less-e0d7e091e062/</link>
                <guid isPermaLink="false">66c3546b076180535b910555</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ ethereum blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 17 Aug 2018 02:41:13 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*GF6ozztlIUgBB7wY8OtxLA.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Prashant Ram</p>
<p>In this tutorial we will:</p>
<ul>
<li>Setup a blockchain with multiple nodes</li>
<li>Setup mining nodes</li>
<li>Connect the multiple nodes and setup the blockchain network</li>
<li>Test the blockchain network by mining blocks and verifying that blocks are propagated to all the nodes</li>
<li>Verify that the local copy of blockchain on all the nodes is updated</li>
</ul>
<h3 id="heading-setup-and-prerequisite-software">Setup and Prerequisite Software</h3>
<p><a target="_blank" href="https://geth.ethereum.org/">Go Etheruem</a> (Geth) is a command line client interface tool that allows you to interact with your private Ethereum blockchain.</p>
<p>If you need to install <a target="_blank" href="https://brew.sh/">Homebrew</a> on your Mac, place the following line in your terminal command prompt:</p>
<pre><code>$ /usr/bin/ruby -e <span class="hljs-string">"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"</span>
</code></pre><p>Once Homebrew is installed, <a target="_blank" href="https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Mac">install</a> Geth:</p>
<pre><code>$ brew tap ethereum/ethereum$ brew install ethereum
</code></pre><h3 id="heading-configure-the-genesis-block">Configure the Genesis Block</h3>
<p>Create a new project directory. Within it create the <code>**genesis.json**</code> file using any editor of your choice. I use <a target="_blank" href="https://code.visualstudio.com/docs/setup/mac">Visual Studio code on Mac</a>, which is a free editor:</p>
<pre><code>$ mkdir project3$ cd project3
</code></pre><p>Copy the following JSON into your <code>**genesis.json**</code> file, and save the file in your project directory.</p>
<pre><code>\\genesis.json file
</code></pre><pre><code>{
</code></pre><pre><code><span class="hljs-string">"config"</span>: {
</code></pre><pre><code><span class="hljs-string">"chainId"</span>: <span class="hljs-number">4321</span>,
</code></pre><pre><code><span class="hljs-string">"homesteadBlock"</span>: <span class="hljs-number">0</span>,
</code></pre><pre><code><span class="hljs-string">"eip155Block"</span>: <span class="hljs-number">0</span>,
</code></pre><pre><code><span class="hljs-string">"eip158Block"</span>: <span class="hljs-number">0</span>
</code></pre><pre><code>},
</code></pre><pre><code><span class="hljs-string">"alloc"</span>: {},
</code></pre><pre><code><span class="hljs-string">"difficulty"</span> : <span class="hljs-string">"0x20000"</span>,
</code></pre><pre><code><span class="hljs-string">"gasLimit"</span>   : <span class="hljs-string">"0x8880000"</span>
</code></pre><pre><code>}
</code></pre><h3 id="heading-set-up-the-first-node-node-1">Set up the first node (Node 1)</h3>
<p>Once the <code>**genesis.json**</code> file is saved, you are ready to create your first node. To create your first node, open a new terminal window and navigate to your project folder, and type in the following command:</p>
<pre><code>$ geth --datadir blkchain1 init genesis.json
</code></pre><p>This command initializes a new blockchain node using the configuration specified in the <code>**genesis.json**</code> file. By using <code>— -datadir</code> we specify the name of the directory where the local copy of the blockchain will be stored on the node.</p>
<p>This command will create a directory called <code>**blkchain1**</code> in your project directory. This directory contains the <code>**geth**</code> and <code>**keystore**</code> directories. The blockchain data will be stored in the local database in the <code>**geth**</code> directory.</p>
<p>You can verify this by navigating into the <code>**blkchain1**</code> directory in your command terminal and typing in <code>ls -l</code>. Also navigate to the <code>**geth**</code> sub-directory and type in <code>ls -l</code>.</p>
<p>Now that your Node 1 is initialized, let’s start Node 1 using Geth. Within your terminal window, navigate to your project folder (where you saved your <code>**genesis.json**</code> file) and type in the following:</p>
<pre><code>$ geth --datadir blkchain1 --nodiscover --networkid <span class="hljs-number">1234</span> <span class="hljs-built_in">console</span>
</code></pre><p>This command will start your first node and bring up the Geth console, where you can type in commands to interact with the Node1 blockchain.</p>
<p>You will see the following:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/qFQFOHhKzFjrlf9fkdB8VkXKLgZP4vwruNFq" alt="Image" width="800" height="344" loading="lazy"></p>
<p>Let’s break down this “geth console” command and understand it:</p>
<p><code>— -datadir blkchain1</code>:<br>specifies the data directory of the blockchain. If you do not specify this, it will default to the main Ethereum blockchain.</p>
<p><code>--nodiscover</code>:<br>disables the peer discovery mechanism and enables manual peer addition.</p>
<p><code>--networkid 1234</code><strong>:</strong><br>identity of your Ethereum network, other peer nodes will also have the same network identifier. <strong>The network id can be any random integer value.</strong></p>
<p>Now that you are in the Geth Console, to get more information about the node we will use the <strong>admin</strong> command. Type in the following command in the Geth console:</p>
<pre><code>&gt; admin.nodeInfo
</code></pre><p>This will give you more information about your node:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/EQ8atvBkddL3jmQoPHHaXKesil9dIcghlS4Z" alt="Image" width="800" height="251" loading="lazy"></p>
<p>Notice the following:</p>
<ul>
<li>by default the <code>listener</code> port is 30303</li>
<li>the <code>enode id</code> is your node id</li>
<li>the <code>discovery</code> port is ‘0’, since we set it to <code>--nodiscover</code>.</li>
</ul>
<p>To get a list of all admin commands, type in “admin.” and press </p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/laeqYYTVI8myUczhPOyCAaJUfL18KLzWWWnj" alt="Image" width="800" height="57" loading="lazy"></p>
<p>Now, let’s setup an account where the <a target="_blank" href="https://www.ethereum.org/ether">mined ethers</a> will be collected. Type in the following in the Geth console:</p>
<pre><code>&gt; personal.newAccount()
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/qu3VCmulyFDh9DHJeGLIXAu45c-dQe697rNj" alt="Image" width="800" height="64" loading="lazy"></p>
<p>You can put in any passphrase — this is your password. The command returns the account id.</p>
<p>To get a list of all the accounts:</p>
<pre><code>&gt; personal.listAccounts
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/iWcJXCbvNTTtVOWtR0x5dp7nkldcdO9kY0ol" alt="Image" width="800" height="73" loading="lazy"></p>
<p>Node 1 is now ready!</p>
<p>Keep the terminal window (with the Geth Console for Node1) open and running. We will open a new terminal window to setup Node 2.</p>
<h3 id="heading-set-up-the-second-node-node-2">Set up the second node (Node 2)</h3>
<p>Now let’s setup a second node in the blockchain network. The process will be similar to setting up Node1.</p>
<p>Open a new terminal window and navigate to the project folder that contains the <code>**genesis.json**</code> file.</p>
<p>Initialize the new node with the following command:</p>
<pre><code>$ geth --datadir blkchain2 init genesis.json
</code></pre><p><strong>Note</strong>: Since we want this node to be part of the same blockchain, we use the same genesis block.</p>
<p>This will create a new node whose data will be stored in a new directory called <code>**blkchain2**</code> (this will contain the local copy of the blockchain database for the node 2).</p>
<p>To get the node 2 up and running with a Geth console, type in the following:</p>
<pre><code>$ geth --datadir blkchain2 --nodiscover --networkid <span class="hljs-number">1234</span> --port <span class="hljs-number">30304</span> <span class="hljs-built_in">console</span>
</code></pre><p>This will start up Node 2 and bring up the Geth console connected to Node 2.</p>
<p>Note the following differences for Node 2:</p>
<ul>
<li>we specify a port number 30304<br>The default port 30303 is already being used by the first node, so if we do not specify a separate port it will throw an error.</li>
<li>we give the same networkid as we did for node 1. This is important, since we want both the nodes to be part of the network</li>
<li>we specify that the <code>— -datadir</code> for node2 will be in <code>**blkchain2**</code></li>
</ul>
<p>Run the <code>admin.nodeInfo</code> command in Geth Console for Node2:</p>
<pre><code>&gt; admin.nodeInfo
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/SrPWuVNtDrPLzXnnsjXrvfS5a6GAhp85XXXP" alt="Image" width="800" height="299" loading="lazy"></p>
<p>Notice that this provides the node information for Node 2. You can compare the <code>enode id</code> by running the <code>same admin.nodeInfo</code> command in the Terminal window running the Geth console for Node1.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/2sIy-KrePNkkxM7rzFa2y2nr9s3l-POZtDB8" alt="Image" width="800" height="258" loading="lazy">
<em>NODE 1</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/MZImf8aMKy81B6yI-Xa01G2nVjKsW2Hn980q" alt="Image" width="800" height="299" loading="lazy">
<em>NODE 2</em></p>
<p>Similar to Node 1, we can setup an account on Node 2 by typing in <code>personal.newAccount()</code> in the Geth console for Node2.</p>
<p>You can use any passphrase for the account.</p>
<pre><code>&gt; personal.newAccount()
</code></pre><p>Node 2 is now ready!</p>
<p>Keep open both the terminal windows, one running the Geth Console (Node1) and the second running the Geth Console (Node2), side by side.</p>
<p>In the next step we will connect Node1 and Node2 and create the blockchain network!</p>
<h3 id="heading-connect-the-nodes">Connect the Nodes</h3>
<p>Congratulations! You have 2 blockchain nodes running.</p>
<p>The next step is to connect them to each other and create a network. We will do this by adding one of the nodes to the other as a “peer”.</p>
<p>Run the following command on the Geth Consoles of both Node1 and Node2:</p>
<pre><code>&gt; admin.peers
</code></pre><p>Notice that both return an empty array, since the nodes are not connected to any other nodes.</p>
<p>Let’s add Node1 as a peer to Node2.</p>
<ol>
<li>Run the <code>admin.nodeInfo</code> command on Node1</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/tuXpZT0g2vBWFEevELfZq14Ht0M8WzTCp6Is" alt="Image" width="800" height="258" loading="lazy"></p>
<ol start="2">
<li>Copy the <code>enode id</code> for Node 1:</li>
</ol>
<pre><code><span class="hljs-string">"enode://549468e6d00e135128af33e03a6d27b0ee5fda7fbd0154b2e83fe68afdfda869eb6ace6ccaefe84ed7a5b804529dcef49f0b5d64be97da87b1e28ddecfca227a@[::]:30303?discport=0"</span>
</code></pre><ol start="3">
<li>In the Geth Console for Node2, add the Node1 as a peer to Node2 using the command <code>admin.addPeer(“//enode id”):</code></li>
</ol>
<pre><code>&gt; admin.addPeer(<span class="hljs-string">"enode://549468e6d00e135128af33e03a6d27b0ee5fda7fbd0154b2e83fe68afdfda869eb6ace6ccaefe84ed7a5b804529dcef49f0b5d64be97da87b1e28ddecfca227a@[::]:30303?discport=0"</span>)
</code></pre><p>Now when you run the <code>admin.peers</code> command in either of the Geth Console you will see the other Node listed as a peer!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/WqDvQvSJMzQU-S-dPkXruPAoPVd7-L9EWfbO" alt="Image" width="800" height="216" loading="lazy"></p>
<p>Hurray! You now have a connect blockchain network!</p>
<p>But how do we know for sure?</p>
<p>Let’s put it to the test, shall we? Let’s update something in Node1 and see if that change is propagated through the blockchain network to Node2.</p>
<h3 id="heading-verify-that-you-have-a-connected-blockchain-and-a-distributed-database">Verify that you have a connected blockchain and a distributed database</h3>
<p>Ok, thus far you should have:</p>
<ul>
<li>Two terminal windows open<br>One running Geth Console for Node1, and the second running Get Console for Node2</li>
<li>Node 1 saves its local copy of the blockchain in the <code>**blkchain1**</code> folder</li>
<li>Node 2 saves its local copy of the blockchain in the <code>**blkchain2**</code> folder</li>
<li>Also, in the previous step you connected the two nodes using <code>admin.addPeer()</code></li>
</ul>
<p>Thus, if the new blocks are mined and added in Node 1, this new block should propagate over the blockchain network, and the local blockchain copy of node2 should update automatically.</p>
<p>Let us verify if this happens.</p>
<p>In the Geth Console(Node1) let’s begin mining:</p>
<pre><code>&gt; miner.start(<span class="hljs-number">1</span>)
</code></pre><p><img src="https://cdn-media-1.freecodecamp.org/images/dHeuhJXRCmmyY2DJnMggCUugBMw0yumw5qlr" alt="Image" width="800" height="260" loading="lazy"></p>
<p>To check how many blocks have been mined at Node1 at any point, run the following in the Geth Console (Node1):</p>
<pre><code>&gt; eth.blockNumber
</code></pre><p>This will return the number of the current block mined (or the blockchain height).</p>
<p>After a few blocks have been mined, go to the Geth Console (Node 2) and run the <code>eth.blockNumber</code> command.</p>
<p>You will notice that the block height in Node 2 matches with the block height in Node 1! This verifies that the Blocks that were mined in Node 1 were propagated over the Blockchain to Node 2.</p>
<p>To kick it up a notch, you can verify the data in the actual blocks on Node 1 and Node 2.</p>
<p>Wait until about 10 blocks have been mined and then run the following command in Geth Console(Node1) and Geth Console(Node2):</p>
<pre><code>&gt; eth.getBlock(<span class="hljs-number">3</span>)
</code></pre><p>This command displays the contents of Block 3 from the blockchain. Notice that the data displayed in Geth Console (Node1) and Geth Console(Node2) is identical, indicating that the Block3 that was mined by Node1 was propagated over the blockchain network and is also part of the local blockchain data in Node 2.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/d7QchSLFO99BhalkAiYPJBOHLQ-u0JRak8fL" alt="Image" width="800" height="441" loading="lazy">
<em>Node 1</em></p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/GGrpKsjlth7LndbiKQR3haXwTi2kGpC2csjc" alt="Image" width="800" height="446" loading="lazy">
<em>Node 2</em></p>
<p>Hurray!! You now have a fully functional and connected multi-node private Ethereum network!</p>
<p>Happy Coding!</p>
<p><strong><em>Follow me on <a target="_blank" href="https://medium.com/@prashantramnyc">Medium</a> for the latest updates and posts!</em></strong></p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
