<?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 - 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 - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 25 May 2026 10:49:59 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/ethereum/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ Learn Web3.js Basics – Ethereum Development for Beginners ]]>
                </title>
                <description>
                    <![CDATA[ By Oluwatise Okuwobi Ethereum is one of the major pioneers in the decentralized ecosystem. And Web3.js is an essential tool if you're working on Ethereum-based projects.  To fully understand why this tool is important, we must first take a deeper div... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-web3js-basics/</link>
                <guid isPermaLink="false">66d4608cd1ffc3d3eb89de38</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web3 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Mon, 27 Nov 2023 22:39:24 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/11/Learn-Web3.js-Basics---Ethereum-Development.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Oluwatise Okuwobi</p>
<p>Ethereum is one of the major pioneers in the decentralized ecosystem. And Web3.js is an essential tool if you're working on Ethereum-based projects. </p>
<p>To fully understand why this tool is important, we must first take a deeper dive into Ethereum development.</p>
<p>Grab your coffee, young Web3 enthusiast. We're going on a journey that will change your Web3 career forever.</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>Before you can carry on with this tutorial, you'll need to understand the basics of JavaScript, and should be able to install npm packages. </p>
<p>If you've worked with JavaScript before, the rest of this tutorial should be a breeze. </p>
<h2 id="heading-what-is-ethereum-development">What is Ethereum Development?</h2>
<p>Ethereum is a decentralized open-source blockchain platform that lets developers build decentralized applications, popularly known as dAPPs. These dApps are built on top of the Ethereum blockchain, harnessing some of the core features of the Ethereum network. </p>
<p>Ethereum is written in Solidity, which is the primary programming language used in the Ethereum ecosystem. You can use Solidity to design smart contracts, which are basically self-executing contracts that power a lot of dApps.</p>
<p>If you want to work in Ethereum development, understanding smart contracts is extremely important. </p>
<p>Smart contracts consist of the terms of the agreement between buyer and seller that are directly written into the lines of code. This code is written in Solidity, which can only exist in the blockchain network.</p>
<p>To become an Ethereum developer, you are going to work mainly around the network, building smart contracts and dApps. </p>
<p>Let's talk about the tools you are going to need:</p>
<ul>
<li>Solidity</li>
<li>Ether.js</li>
<li>JavaScript/React for front-end visual interaction</li>
</ul>
<h2 id="heading-the-world-of-web3js">The World of Web3.js</h2>
<p>Now that you have an idea of what Ethereum development is, we can begin to understand Web3.js a little better. </p>
<p>Web3.js is a collection of libraries that allow you to interact with a local or remote Ethereum node, using HTTP, IPC, or Web Sockets (which is my personal favorite). It is written in JavaScript, and to put it simply, it lets you interact with the blockchain more efficiently.</p>
<p>By reading data from the blockchain, you will be able to make transactions and deploy smart contracts live on the mainnet.</p>
<h2 id="heading-how-to-set-up-web3js">How to Set Up Web3.js</h2>
<p>Web3.js can access blockchain information from both the back end and front end to make transactions and deploy smart contracts. </p>
<p>You are going to need Node.js, which you can easily <a target="_blank" href="https://nodejs.org/en/">download from the official website</a>. The installation process is pretty straightforward. </p>
<p>After you've successfully installed Node and npm (the official package manager for Node), open your command line in the root folder of your project and type the following command:</p>
<pre><code class="lang-javascript">npm install web3 --save
</code></pre>
<p>Then you'll be able to import Web3.js into a Node script using this simple code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> Web3 = <span class="hljs-built_in">require</span>(<span class="hljs-string">"web3"</span>)
</code></pre>
<p>We've got some of the hard part locked down. Now we just need our project to communicate directly with the blockchain. </p>
<p>To initiate our Web3 provider, we must instantiate, which just means creating a Web3 instance, and pass a constructor to the URL of the provider. </p>
<p>In this case, we'll have to find an Ethereum node that we can connect to and start crafting magic. </p>
<p>There are multiple node providers like Alchemy, Chainstack, and Moralis, and there's a lot of documentation when it comes to getting a direct access.</p>
<p>You can make use of the Ganache instance as well, which will essentially help you set up the environment for anything you need to work in your local environment.</p>
<p>To understand <a target="_blank" href="https://medium.com/coinmonks/get-started-with-building-ethereum-dapps-and-smart-contracts-d86b9f7bd1c">how to set up Ganache</a>, you can read the linked guide that covers everything you need to know.</p>
<p>You simply place this below your code like so:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> Web3 = <span class="hljs-built_in">require</span>(<span class="hljs-string">"web3"</span>)
<span class="hljs-keyword">const</span> web3 = <span class="hljs-keyword">new</span> Web3(<span class="hljs-string">"http://localhost:8545"</span>)
</code></pre>
<p>To test that you have successfully configured everything, you can write some simple code to get the latest block number on the blockchain:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> Web3 = <span class="hljs-built_in">require</span>(<span class="hljs-string">"web3"</span>)
<span class="hljs-keyword">const</span> web3 = <span class="hljs-keyword">new</span> Web3(<span class="hljs-string">"http://localhost:8545"</span><span class="hljs-string">")

web3.eth.getBlockNumber(function (error, result) {
  console.log(result)
})</span>
</code></pre>
<p>This function simply accepts a callback as a parameter, then prints the result as an integer. Running this would just give you a block number on your console. </p>
<p>There are many other functions you can use. The web3 <a target="_blank" href="https://docs.web3js.org/">official documentation</a> provides a comprehensive list of functions that you can learn about and try out.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>If you're wanting to get into Ethereum development, Web3.js will be a vital part of your stack. Throughout your journey, you are going to be interacting with the Ethereum node more frequently and Web3.js will come in handy.</p>
<p>There are other alternatives like Ether.js, which also strive to provide a complete library that can interact with the Ethereum node. But Web3 is known to have a larger network of support, a larger community of developers, and more mature documentation that you can refer to regarding problems of any sort.</p>
<p>Hopefully this article has given all of the insights you need for you to start your Ethereum journey. I'm available on <a target="_blank" href="https://www.twitter.com/tiseysoft">Twitter</a>, if you have any questions.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Decentralized Identity – Build a Profile with Next.js, Ethereum & Ceramic Network ]]>
                </title>
                <description>
                    <![CDATA[ Long-standing centralized intermediaries, like the government or big companies, are the ones who make and keep your ID information in traditional systems that manage who you are.  But this implies that you have no control over the information relatin... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/decentralized-identity-build-a-profile-with-ethereum-ceramic-and-reactjs/</link>
                <guid isPermaLink="false">66b905ce5730a049b6bfea7d</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ decentralization ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web3 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Idris Olubisi ]]>
                </dc:creator>
                <pubDate>Fri, 17 Feb 2023 22:44:56 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2023/02/Decentralized-Identity--Build-a-Profile-with-NextJs--Ethereum---Ceramic-Network.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Long-standing centralized intermediaries, like the government or big companies, are the ones who make and keep your ID information in traditional systems that manage who you are. </p>
<p>But this implies that you have no control over the information relating to your identification, who has access to <a target="_blank" href="https://www.dol.gov/general/ppii#:~:text=Personal%20Identifiable%20Information%20(PII)%20is,either%20direct%20or%20indirect%20means.">personally identifiable information (PII)</a>, and to what extent.</p>
<p>As a result, Decentralized Identity provides identity-related information that is self-controlled, private, and portable. Decentralized identifiers and attestations serve as the main building pieces. </p>
<p>Thanks to Ceramic's decentralized application databases, application developers can reuse data across applications and automatically make them interoperable.</p>
<p>In this article, you will learn about Decentralized Identity, Decentralized Identifiers, Ceramic network, and how to build a decentralized identity profile with Ethereum on Ceramic Networks.</p>
<h3 id="heading-heres-what-well-cover">Here's what we'll cover:</h3>
<ul>
<li>What is a Decentralized Identity?</li>
<li>What are Decentralized Identifiers?</li>
<li>What is Ceramic Data Network?</li>
<li>Why Ceramic Network?</li>
<li>How to Build a Decentralized Identity Profile with Next.js</li>
<li>Prerequisites</li>
<li>Project Setup and Installation</li>
<li>Install TailwindCSS in Next.js</li>
<li>Authenticate Users</li>
<li>Create/Update User Profile</li>
<li>How to Test the Application</li>
<li>Conclusion</li>
<li>References</li>
</ul>
<h2 id="heading-what-is-a-decentralized-identity">What is a Decentralized Identity?</h2>
<p><a target="_blank" href="https://ethereum.org/en/decentralized-identity/">Decentralized Identity</a> is a digital identification concept where people, companies, and items are in charge of their data and can share it selectively without relying on a centralized authority. </p>
<p>This is made possible by using decentralized technologies, such as blockchain. These give people control and ownership over the information associated with their identities rather than having it stored on a central server or managed by a third party.</p>
<p>A decentralized identity is a self-owned, independent identity that enables trusted data exchange.</p>
<p>Blockchain-based digital wallets, such as those used to store and handle cryptocurrencies, serve as a practical illustration of decentralized identification. Users of these wallets control the private keys that provide them access to their money and can distribute their public keys to others to accept payments from them.</p>
<p>Users who manage their private keys can conduct transactions with others without relying on a central authority, such as a bank, and keep custody of their money.</p>
<h2 id="heading-what-are-decentralized-identifiers">What are Decentralized Identifiers?</h2>
<p>Decentralized identifiers (DIDs) are issued, held, and controlled by individuals. Since they are kept on peer-to-peer networks or distributed ledgers (blockchains), they are globally unique, highly available, and cryptographically verifiable. </p>
<p>Decentralized identifiers can be associated with individuals, groups, or governmental entities.</p>
<p>DIDs are a vital component of the developing decentralized identity ecosystem. They are designed to offer a uniform process for developing, maintaining, and exchanging digital identities unaffiliated with any one company or piece of technology. </p>
<p>This implies that a DID can be maintained and controlled by the person or entity to which it belongs and utilized across various systems and applications.</p>
<p>In recent years, smart contract platforms like Ethereum have demonstrated the utility of decentralized applications (dApps) that can be assembled like blocks to create new applications. This is especially evident in tokens that build upon one another, in DeFi protocols that use one another, and so on.</p>
<p>Thanks to Ceramic, data on the internet can now have the same kind of composability. Any data type, including profiles, social connections, blog posts, identities, reputations, and so on., can be included. You will learn more about Ceramic Network in the section below.</p>
<h2 id="heading-what-is-ceramic-network">What is Ceramic Network?</h2>
<p><a target="_blank" href="https://ceramic.network/">Ceramic</a> is a public, permissionless, open-source protocol that offers computation, state transitions, and consensus for all data structures on the decentralized web. </p>
<p>With the help of stream processing provided by Ceramic, developers can build apps that are strong, safe, trustless, and censorship-resistant using dynamic information – without using unreliable database servers.</p>
<p>Ceramic stores all content in smart documents, which are append-only IPFS logs. Before being anchored in a blockchain for consensus, each commit is verified by a decentralized identification (DID).</p>
<p>All papers in Ceramic are openly discoverable and can be referenced by other documents or queried by any other network user because the system is entirely peer-to-peer.</p>
<h2 id="heading-why-ceramic-network">Why Ceramic Network?</h2>
<p>Data interoperability is one of Ceramic Network's key benefits. This platform features a flexible and modular data schema that enables the decentralized and interoperable sharing and combining of various sorts of data. </p>
<p>Developers now have an easier time creating decentralized identification solutions that can be integrated with other programs and systems.</p>
<p>The infrastructure of Ceramic Network is scalable, fault-tolerant, decentralized, and highly available. This enables developers to create robust decentralized identity systems available to users everywhere.</p>
<p>Ceramic Network also provides a set of developer tools and libraries, making it simple to create decentralized identity apps and services. These tools include SDKs, APIs, developer guides, and an expanding ecosystem of open-source tools and libraries.</p>
<p>Now that you have learnt the theories behind decentralized identity, let's take a practical deep dive and get your hands dirty.</p>
<h2 id="heading-how-to-build-a-decentralized-identity-profile-with-nextjs">How to Build a Decentralized Identity Profile with Next.js</h2>
<h3 id="heading-prerequisites">Prerequisites</h3>
<p>To go through this tutorial, you'll need some experience with JavaScript and React.js. Experience with Next.js isn't a requirement, but it's nice to have.</p>
<p>Make sure to have Node.js or npm installed on your computer. If you don't, click <a target="_blank" href="https://docs.npmjs.com/downloading-and-installing-node-js-and-npm"><strong>here</strong></a>.</p>
<p>Also, it'll be very useful to have a basic understanding of blockchain technology and Web3 concepts.</p>
<h3 id="heading-project-setup-and-installation">Project Setup and Installation</h3>
<p>Navigate to the terminal and <code>cd</code> into any directory of your choice. Then run the following commands:</p>
<pre><code class="lang-bash">mkdir decentralized-identity-project
<span class="hljs-built_in">cd</span> decentralized-identity-project
npx create-next-app@latest .
</code></pre>
<p>Accept the following options:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676416198416/0b46fd0f-d47a-4533-9450-a79007205efe.png" alt="Image" width="611" height="71" loading="lazy"></p>
<p>Install the <code>@self.id/react</code> and <code>@self.id/web</code> packages using the code snippet below:</p>
<pre><code class="lang-bash">npm install @self.id/web @self.id/react
</code></pre>
<p>Next, start the app using the following command:</p>
<pre><code class="lang-bash">npm run dev
</code></pre>
<p>You should have something similar to what is shown below: the default boilerplate layout for Next.js 13.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676416289117/799cfc73-78b3-49f9-8b72-a407813f7d9c.png" alt="Image" width="1292" height="884" loading="lazy"></p>
<h3 id="heading-install-tailwindcss-in-nextjs">Install TailwindCSS in Next.js</h3>
<p>In this section, you will set up Tailwind CSS in a Next.js project. Install <code>tailwindcss</code> and its peer dependencies via npm, and then run the init command to generate both <code>tailwind.config.js</code> and <code>postcss.config.js</code>.</p>
<pre><code class="lang-bash">npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
</code></pre>
<p>Navigate to the <code>tailwind.config.js</code> file, and add the paths to your template files with the following code snippet.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">/** <span class="hljs-doctag">@type <span class="hljs-type">{import('tailwindcss').Config}</span> </span>*/</span>

<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">content</span>: [
    <span class="hljs-string">"./app/**/*.{js,ts,jsx,tsx}"</span>,
    <span class="hljs-string">"./pages/**/*.{js,ts,jsx,tsx}"</span>,
    <span class="hljs-string">"./components/**/*.{js,ts,jsx,tsx}"</span>,

    <span class="hljs-comment">// Or if using `src` directory:</span>
    <span class="hljs-string">"./src/**/*.{js,ts,jsx,tsx}"</span>,
  ],
  <span class="hljs-attr">theme</span>: {
    <span class="hljs-attr">extend</span>: {},
  },
  <span class="hljs-attr">plugins</span>: [],
}
</code></pre>
<p>Delete all the CSS styles inside <code>globals.css</code> . Add the <code>@tailwind</code> directives for each of Tailwind’s layers to your <code>globals.css</code> file.</p>
<pre><code class="lang-css"><span class="hljs-keyword">@tailwind</span> base;
<span class="hljs-keyword">@tailwind</span> components;
<span class="hljs-keyword">@tailwind</span> utilities;
</code></pre>
<h3 id="heading-configure-the-provider-component">Configure the Provider Component</h3>
<p>The <code>Provider</code> component must be placed at the top of the application tree to use the hooks detailed below. You can use it to supply an initial state as well as a specific configuration for the <a target="_blank" href="http://Self.ID">Self.ID</a> clients and queries.</p>
<p>Update the <code>_app.js</code> file under the pages folder with the following code snippet:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Import the Provider component from the "@self.id/react" library.</span>
<span class="hljs-keyword">import</span> { Provider } <span class="hljs-keyword">from</span> <span class="hljs-string">"@self.id/react"</span>;

<span class="hljs-comment">// Import the "globals.css" file from the "@/styles" directory.</span>
<span class="hljs-keyword">import</span> <span class="hljs-string">"@/styles/globals.css"</span>;

<span class="hljs-comment">// Define the App component as a default export.</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params">{ Component, pageProps }</span>) </span>{

  <span class="hljs-comment">// Render the Provider component, which provides authentication and authorization functionality to the application.</span>
  <span class="hljs-comment">// Pass a client prop to the Provider component, which configures the Ceramic testnet with the "testnet-clay" value.</span>
  <span class="hljs-comment">// Render the Component with its props inside the Provider component, which allows the application to access the authentication and authorization context.</span>

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Provider</span> <span class="hljs-attr">client</span>=<span class="hljs-string">{{</span> <span class="hljs-attr">ceramic:</span> "<span class="hljs-attr">testnet-clay</span>" }}&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Component</span> {<span class="hljs-attr">...pageProps</span>} /&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">Provider</span>&gt;</span></span>
  );
}
</code></pre>
<p>In the code snippet above, we:</p>
<ul>
<li>Imported a context provider component and global CSS styles and then defined an <code>App</code> component that wraps the entire application with the context provider.</li>
<li>Configured the context provider with a Ceramic testnet client, which allows the application to access authentication and authorization functionality.</li>
<li>Finally, the <code>Component</code> is rendered with its props inside the context provider, allowing the application to access the authentication and authorization context.</li>
</ul>
<h3 id="heading-build-the-layout">Build the Layout</h3>
<p>Next, navigate to the <code>index.js</code> file under the <code>pages</code> folder and update it with the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Import the Head component from the "next/head" module.</span>
<span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">"next/head"</span>;

<span class="hljs-comment">// Import the useViewerConnection and useViewerRecord hooks from the "@self.id/react" library.</span>
<span class="hljs-keyword">import</span> { useViewerConnection, useViewerRecord } <span class="hljs-keyword">from</span> <span class="hljs-string">"@self.id/react"</span>;

<span class="hljs-comment">// Import the EthereumAuthProvider component from the "@self.id/web" library.</span>
<span class="hljs-keyword">import</span> { EthereumAuthProvider } <span class="hljs-keyword">from</span> <span class="hljs-string">"@self.id/web"</span>;

<span class="hljs-comment">// Import the useState hook from the "react" module.</span>
<span class="hljs-keyword">import</span> { useEffect, useState } <span class="hljs-keyword">from</span> <span class="hljs-string">"react"</span>;


<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Home</span>(<span class="hljs-params"></span>) </span>{

  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>
          Decentralized Identity: Build a Profile with NextJs, Ethereum &amp; Ceramic Network
        <span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"description"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"Generated by create next app"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"viewport"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"width=device-width, initial-scale=1"</span> /&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">link</span> <span class="hljs-attr">rel</span>=<span class="hljs-string">"icon"</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"/favicon.ico"</span> /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">main</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"min-h-screen bg-gray-200"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-gray-600 py-4 px-4 sm:px-6 lg:px-8 lg:py-6 shadow-lg text-white"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"container mx-auto px-6 md:px-0"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-2xl font-bold text-white text-center"</span>&gt;</span>
              Decentralized Identity: Build a Profile with NextJs, Ethereum &amp; Ceramic Network
            <span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>

        <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"flex items-center justify-center pt-20 font-sans overflow-hidden"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"max-w-md w-full mx-auto"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-white p-10 rounded-lg shadow-lg"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mb-6"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>
                    <span class="hljs-attr">className</span>=<span class="hljs-string">"block text-gray-700 font-bold mb-2"</span>
                    <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"name"</span>
                  &gt;</span>
                    Name
                  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
                    <span class="hljs-attr">className</span>=<span class="hljs-string">"border border-gray-300 p-2 w-full rounded-lg"</span>
                    <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
                    <span class="hljs-attr">name</span>=<span class="hljs-string">"name"</span>
                    <span class="hljs-attr">id</span>=<span class="hljs-string">"name"</span>
                    <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Your name"</span>
                  /&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mb-6"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>
                    <span class="hljs-attr">className</span>=<span class="hljs-string">"block text-gray-700 font-bold mb-2"</span>
                    <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"bio"</span>
                  &gt;</span>
                    Bio
                  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">textarea</span>
                    <span class="hljs-attr">className</span>=<span class="hljs-string">"border border-gray-300 p-2 w-full rounded-lg"</span>
                    <span class="hljs-attr">name</span>=<span class="hljs-string">"bio"</span>
                    <span class="hljs-attr">id</span>=<span class="hljs-string">"bio"</span>
                    <span class="hljs-attr">rows</span>=<span class="hljs-string">"5"</span>
                    <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Write something about yourself"</span>
                  &gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">textarea</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mb-6"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>
                    <span class="hljs-attr">className</span>=<span class="hljs-string">"block text-gray-700 font-bold mb-2"</span>
                    <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"username"</span>
                  &gt;</span>
                    Username
                  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
                    <span class="hljs-attr">className</span>=<span class="hljs-string">"border border-gray-300 p-2 w-full rounded-lg"</span>
                    <span class="hljs-attr">type</span>=<span class="hljs-string">"text"</span>
                    <span class="hljs-attr">name</span>=<span class="hljs-string">"username"</span>
                    <span class="hljs-attr">id</span>=<span class="hljs-string">"username"</span>
                    <span class="hljs-attr">placeholder</span>=<span class="hljs-string">"Your username"</span>
                  /&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"flex items-center justify-between"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
                    <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"</span>
                    <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>
                  &gt;</span>
                    Update Profile
                  <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">className</span>=<span class="hljs-string">"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"</span>
                    <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span>
                  &gt;</span>
                    Connect Wallet
                  <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  );
}
</code></pre>
<p>To start the application, run the following command and navigate to localhost:3000 on your browser; you should have something similar to what is shown below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676418666618/bc0620d9-d7bb-4297-bdb1-6021d08d8d6c.png" alt="Image" width="1544" height="1060" loading="lazy"></p>
<h3 id="heading-how-to-authenticate-users">How to Authenticate Users</h3>
<p>In this section, you will implement user authentication to allow users to connect their wallets and interact with the application.</p>
<p>Update the <code>index.js</code> with the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">//..</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Home</span>(<span class="hljs-params"></span>) </span>{

  <span class="hljs-comment">// State variables for connection, connect function, and disconnect function</span>
  <span class="hljs-keyword">const</span> [connection, connect, disconnect] = useViewerConnection();


  <span class="hljs-keyword">const</span> [isWindow, setIsWindow] = useState(<span class="hljs-literal">null</span>);


  <span class="hljs-comment">// State variable for viewer's basic profile data</span>
  <span class="hljs-keyword">const</span> record = useViewerRecord(<span class="hljs-string">"basicProfile"</span>);

  <span class="hljs-comment">// Function to create EthereumAuthProvider using window.ethereum provider</span>
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createAuthProvider</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> addresses = <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">return</span> <span class="hljs-keyword">new</span> EthereumAuthProvider(<span class="hljs-built_in">window</span>.ethereum, addresses[<span class="hljs-number">0</span>]);
  }

  <span class="hljs-comment">// Function to connect to viewer's account using created authProvider</span>
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">connectAccount</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> authProvider = <span class="hljs-keyword">await</span> createAuthProvider();
    <span class="hljs-keyword">await</span> connect(authProvider);
  }

  <span class="hljs-comment">// Rendered JSX code</span>
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>
      {/* ... */}
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"flex items-center justify-between"</span>&gt;</span>
        {/* ... */}

        {/* Conditionally render a button to connect/disconnect user */}
        {connection.status === "connected" ? (
          <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
            <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-4 rounded"</span>
            <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span>
            <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> disconnect()}
          &gt;
            Disconnect
          <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        ) : isWindow &amp;&amp; "ethereum" in window ? (
          <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
            <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded"</span>
            <span class="hljs-attr">type</span>=<span class="hljs-string">"button"</span>
            <span class="hljs-attr">disabled</span>=<span class="hljs-string">{connection.status</span> === <span class="hljs-string">"connecting"</span> || !<span class="hljs-attr">record</span>}
            <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> {
              connectAccount();
            }}
          &gt;
            Connect Wallet
          <span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>
        ) : (
          <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-red-500 text-sm italic mt-2 text-center w-full"</span>&gt;</span>
            An injected Ethereum provider such as{" "}
            <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"https://metamask.io/"</span>&gt;</span>MetaMask<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span> is needed to
            authenticate.
          <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
        )}
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  )
}
</code></pre>
<p>In the code snippet above,</p>
<ul>
<li>The <code>useViewerConnection</code> hook is used to set up a state variable for the user's connection status, connect and disconnect.</li>
<li><code>isWindow</code> to set the initial state of the the window to avoid <a target="_blank" href="https://nextjs.org/docs/messages/react-hydration-error">React hydration error</a></li>
<li>The <code>useViewerRecord</code> hook is used to retrieve the user's basic profile data.</li>
<li>The <code>createAuthProvider</code> function creates an <code>EthereumAuthProvider</code> object using the <code>window.ethereum</code> provider.</li>
<li>The <code>connectAccount</code> function calls <code>createAuthProvider</code> and connects to the user's account using <code>connect(authProvider)</code>.</li>
<li>The JSX code conditionally renders a button based on the user's connection status and the availability of an <code>ethereum</code> provider in the <code>window</code> object.</li>
<li>If the user is already connected, the button will enable them to disconnect. If the user is not yet connected and an <code>ethereum</code> provider is available, the button will enable them to connect. But if the user is not connected and no <code>ethereum</code> provider is available, a message will be displayed to inform the user that an injected Ethereum provider like MetaMask is required to authenticate.</li>
</ul>
<p>Testing out the authentication functionality, you should have something similar to what is shown below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1676467487656/bc91509c-cd69-479a-80e5-7bc9b680150d.png" alt="Image" width="1561" height="695" loading="lazy"></p>
<h3 id="heading-how-to-create-or-update-a-user-profile">How to Create or Update a User Profile</h3>
<p>In the previous section, you learned how to successfully authenticate users. Next, you will implement functionality to create and update an authenticated user with the following code snippet:</p>
<p><code>pages/index.js</code></p>
<pre><code class="lang-javascript"><span class="hljs-comment">//...</span>


<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Home</span>(<span class="hljs-params"></span>) </span>{
<span class="hljs-comment">// Use the useState hook to create state variables and functions to update them</span>
  <span class="hljs-keyword">const</span> [name, setName] = useState(<span class="hljs-string">""</span>);
  <span class="hljs-keyword">const</span> [bio, setBio] = useState(<span class="hljs-string">""</span>);
  <span class="hljs-keyword">const</span> [username, setUsername] = useState(<span class="hljs-string">""</span>);

  <span class="hljs-comment">//...</span>

<span class="hljs-comment">// Define an asynchronous function called updateProfile to update the profile information</span>
  <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">updateProfile</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-comment">// If any of the required fields are empty, return early and do not update</span>
     <span class="hljs-keyword">if</span> (!name || !bio || !username) {
       <span class="hljs-keyword">return</span>;
     }

     <span class="hljs-comment">// Use the merge method to update the record with the new information</span>
     <span class="hljs-keyword">await</span> record.merge({
       name,
       bio,
       username,
     });
   }

  <span class="hljs-comment">// Render the component's UI</span>
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;&gt;</span>

    {/* ... */}

    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"flex items-center justify-center pt-20 font-sans overflow-hidden"</span>&gt;</span>
          <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"max-w-md w-full mx-auto"</span>&gt;</span>
            <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-white p-10 rounded-lg shadow-lg"</span>&gt;</span>
              <span class="hljs-tag">&lt;<span class="hljs-name">form</span>&gt;</span>
               {/* ... */}
              <span class="hljs-tag">&lt;/<span class="hljs-name">form</span>&gt;</span>
            <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            {connection.status === "connected" &amp;&amp; record &amp;&amp; record.content ? (
              <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"flex flex-col items-center mt-8"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">h2</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-3xl font-bold mb-6 text-gray-900"</span>&gt;</span>
                  Profile Information
                <span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"w-full max-w-md bg-white p-8 rounded-lg shadow-lg"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mb-4"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"font-bold text-gray-700 mr-2 text-lg"</span>&gt;</span>
                      Name:
                    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>{" "}
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"nameOutput"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-lg"</span>&gt;</span>
                      {record.content.name || "No name set"}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>

                  <span class="hljs-tag">&lt;<span class="hljs-name">p</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mb-4"</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"font-bold text-gray-700 mr-2 text-lg"</span>&gt;</span>
                      Bio:
                    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>{" "}
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"bioOutput"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-lg"</span>&gt;</span>
                      {record.content.bio || "No bio set"}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"font-bold text-gray-700 mr-2 text-lg"</span>&gt;</span>
                      Username:
                    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>{" "}
                    <span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"usernameOutput"</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"text-lg"</span>&gt;</span>
                      {record.content.username || "No username set"}
                    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
                  <span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            ) : (
              <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mt-8"</span>&gt;</span>
                <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-white p-8 rounded-lg shadow-lg"</span>&gt;</span>
                  <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>No profile found.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
                <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
              <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
            )}

          <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/&gt;</span></span>
  ) 
}
</code></pre>
<p>In the code above,</p>
<ul>
<li>The component uses the useState hook to manage the state of three variables: <code>name</code>, <code>bio</code>, and <code>username</code>.</li>
<li>There's an async function called <code>updateProfile</code> that is responsible for merging the current state of the variables into a record.</li>
<li>If any of the variables is empty, the <code>updateProfile</code> function returns without updating the record.</li>
<li>There are three conditional statements that render a different UI based on whether a record is found or not.</li>
<li>The first conditional statement checks whether the record is still loading, and if it is, it displays a <code>Loading...</code> message.</li>
<li>The second conditional statement checks whether there's no record content and the connection status is connected. If this is true, it displays a <code>No profile found.</code> message.</li>
</ul>
<p>The third conditional statement checks whether the record content exists. If it does, it displays the profile information, which includes the user's <code>name</code>, <code>bio</code>, and <code>username</code>.</p>
<p>You are almost there. In the form tag, update the <code>name</code>, <code>bio</code> and <code>username</code> input field with the following code:</p>
<pre><code class="lang-javascript">&lt;div className=<span class="hljs-string">"mb-6"</span>&gt;
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">label</span>
    <span class="hljs-attr">className</span>=<span class="hljs-string">"block text-gray-700 font-bold mb-2"</span>
    <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"name"</span>
  &gt;</span>
    Name
  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">input</span>
    //<span class="hljs-attr">...</span>
    <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> {
      setName(e.target.value);
    }}
  /&gt;</span>
&lt;/div&gt;
<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"mb-6"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>
    <span class="hljs-attr">className</span>=<span class="hljs-string">"block text-gray-700 font-bold mb-2"</span>
    <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"bio"</span>
  &gt;</span>
    Bio
  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">textarea</span>
    //<span class="hljs-attr">...</span>
    <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> {
      setBio(e.target.value);
    }}
  &gt;<span class="hljs-tag">&lt;/<span class="hljs-name">textarea</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></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">"mb-6"</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">label</span>
    <span class="hljs-attr">className</span>=<span class="hljs-string">"block text-gray-700 font-bold mb-2"</span>
    <span class="hljs-attr">htmlFor</span>=<span class="hljs-string">"username"</span>
  &gt;</span>
    Username
  <span class="hljs-tag">&lt;/<span class="hljs-name">label</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">input</span>
    //<span class="hljs-attr">...</span>
    <span class="hljs-attr">onChange</span>=<span class="hljs-string">{(e)</span> =&gt;</span> {
      setUsername(e.target.value);
    }}
  /&gt;
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>
</code></pre>
<p>In the code snippet above, <code>setName</code>, <code>setBio</code>, and <code>setUsername</code> are functions provided by the <code>useState</code> hook that update the state of <code>name</code>, <code>bio</code>, or <code>username</code>.</p>
<p>Next, the <code>Update Profile</code> button.</p>
<pre><code class="lang-xml">//...

 <span class="hljs-tag">&lt;<span class="hljs-name">button</span>
     <span class="hljs-attr">className</span>=<span class="hljs-string">"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"</span>
     <span class="hljs-attr">type</span>=<span class="hljs-string">"submit"</span>
     <span class="hljs-attr">disabled</span>=<span class="hljs-string">{!record.isMutable</span> || <span class="hljs-attr">record.isMutating</span>}
     <span class="hljs-attr">onClick</span>=<span class="hljs-string">{()</span> =&gt;</span> updateProfile()}
 &gt;
    {record.isMutating ? "Updating..." : "Update Profile"}
<span class="hljs-tag">&lt;/<span class="hljs-name">button</span>&gt;</span>

//..
</code></pre>
<p>In the code snippet above, the button is disabled when the record is not mutable or is currently mutating. </p>
<p>When the button is clicked, it calls the <code>updateProfile</code> function, which is responsible for updating the user's profile information. If the record mutates, the button will display <code>Updating...</code>. Otherwise, it will display <code>Update Profile</code>.</p>
<p>You can test out the application similar to what is shown below.</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.loom.com/share/f2103bcb44c949f7bfdbd5cb531b0c71">https://www.loom.com/share/f2103bcb44c949f7bfdbd5cb531b0c71</a></div>
<p>Kindly find the complete code on <a target="_blank" href="https://github.com/Olanetsoft/decentralized-identity-project">GitHub repository here</a>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this post, you learn about Decentralized Identity, Decentralized Identifiers, Ceramic networks, why Ceramic network is useful, and how to build a decentralized identity profile with Ethereum on Ceramic Networks.</p>
<h3 id="heading-references">References</h3>
<ul>
<li><a target="_blank" href="https://github.com/ceramicnetwork/ceramic">Ceramic Network</a></li>
<li><a target="_blank" href="https://developers.ceramic.network/reference/">Ceramic Documentation</a></li>
<li><a target="_blank" href="https://ethereum.org/en/decentralized-identity/">Decentralized Identity - Ethereum</a></li>
</ul>
<p>I'd love to connect with you at <a target="_blank" href="https://twitter.com/olanetsoft"><strong>Twitter</strong></a> | <a target="_blank" href="https://www.linkedin.com/in/olubisi-idris-ayinde-05727b17a/"><strong>LinkedIn</strong></a> | <a target="_blank" href="https://github.com/Olanetsoft"><strong>GitHub</strong></a> | <a target="_blank" href="https://idrisolubisi.com/"><strong>Portfolio</strong></a></p>
<p>See you in my next article. Take care!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Make an NFT in 14 Lines of Code ]]>
                </title>
                <description>
                    <![CDATA[ By Nico If you're a developer who's interested in Blockchain development, you should know something about NFTs, or Non-Fungible Tokens. So in this article, we'll learn about the engineering behind them so you can start building your own. At the end o... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-make-an-nft/</link>
                <guid isPermaLink="false">66d46040ffe6b1f641b5fa32</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ NFT ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Thu, 14 Oct 2021 17:49:36 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/10/nft.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Nico</p>
<p>If you're a developer who's interested in Blockchain development, you should know something about NFTs, or Non-Fungible Tokens. So in this article, we'll learn about the engineering behind them so you can start building your own.</p>
<p>At the end of the project, you will have your own Ethereum wallet with a new NFT in it. This tutorial is beginner-friendly and does not require any prior knowledge of the Ethereum network or smart contracts. </p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/image-46.png" alt="Image" width="600" height="400" loading="lazy">
<em>The NFT contract has only 14 lines of code</em></p>
<h2 id="heading-what-is-an-nft">What is an NFT?</h2>
<p>NFT stands for non-fungible token. <a target="_blank" href="https://ethereum.org/en/nft/">This quote from ethereum.org</a> explains it well:</p>
<blockquote>
<p>NFTs are tokens that we can use to represent ownership of unique items. They let us tokenise things like art, collectibles, even real estate. They can only have one official owner at a time and they're secured by the Ethereum blockchain – no one can modify the record of ownership or copy/paste a new NFT into existence.</p>
</blockquote>
<h2 id="heading-what-is-an-nft-standard-or-erc-721">What is an NFT standard or ERC-721?</h2>
<p>The ERC-721 is the most common NFT standard. If your Smart Contract implements certain standardized API methods, it can be called an ERC-721 Non-Fungible Token Contract. </p>
<p>These methods are specified in the <a target="_blank" href="https://eips.ethereum.org/EIPS/eip-721">EIP-721</a>. Open-sourced projects like OpenZeppelin have simplified the development process by implementing the most common ERC standards as a reusable library. </p>
<h2 id="heading-what-is-minting-an-nft">What is minting an NFT?</h2>
<p>By minting an NFT, you publish a unique token on a blockchain. This token is an instance of your Smart Contract. </p>
<p>Each token has a unique tokenURI, which contains metadata of your asset in a JSON file that conforms to certain schema. The metadata is where you store information about your NFT, such as name, image, description, and other attributes.</p>
<p>An example of the JSON file for the "ERC721 Metadata Schema" looks like this:</p>
<pre><code class="lang-json">{
    <span class="hljs-attr">"attributes"</span>: [
        {
            <span class="hljs-attr">"trait_type"</span>: <span class="hljs-string">"Shape"</span>,
            <span class="hljs-attr">"value"</span>: <span class="hljs-string">"Circle"</span>
        },
        {
            <span class="hljs-attr">"trait_type"</span>: <span class="hljs-string">"Mood"</span>,
            <span class="hljs-attr">"value"</span>: <span class="hljs-string">"Sad"</span>
        }
    ],
    <span class="hljs-attr">"description"</span>: <span class="hljs-string">"A sad circle."</span>,
    <span class="hljs-attr">"image"</span>: <span class="hljs-string">"https://i.imgur.com/Qkw9N0A.jpeg"</span>,
    <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Sad Circle"</span>
}
</code></pre>
<h2 id="heading-how-do-i-store-my-nfts-metadata">How do I store my NFT's metadata?</h2>
<p>There are three main ways to store an NFT's metadata. </p>
<p>First, you can store the information on-chain. In other word, you can extend your ERC-721 and store the metadata on the blockchain, which can be costly. </p>
<p>The second method is to use <a target="_blank" href="https://docs.ipfs.io/concepts/what-is-ipfs/">IPFS</a>. And the third way is to simply have your API return the JSON file.</p>
<p>The first and second methods are usually preferred, since you cannot temper the underlying JSON file. For the scope of this project, we will opt for the third method. </p>
<p>For a good tutorial on using NFTs with IPFS, read <a target="_blank" href="https://docs.alchemy.com/alchemy/tutorials/how-to-create-an-nft/how-to-mint-a-nft#step-4-configure-the-metadata-for-your-nft-using-ipfs">this article</a> by the Alchemy team.</p>
<h2 id="heading-what-well-be-building">What We'll Be Building</h2>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/emotionalshapes.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>In this tutorial, we'll be creating and minting our own NFT. It is beginner-friendly and does not require any prior knowledge of the Ethereum network or smart contracts. Still, having a good grasp on those concepts will help you understand what is going on behind the scenes. </p>
<p>In an upcoming tutorial, we'll build a fully-functional React web app where you can display and sell your NFTs.</p>
<p>If you are just getting started with dApp development, begin by reading through <a target="_blank" href="https://ethereum.org/en/developers/docs/intro-to-ethereum/">the key topics</a> and watch this <a target="_blank" href="https://www.youtube.com/watch?v=M576WGiDBdQ">amazing course</a> by Patrick Collins.</p>
<p><em>This project is intentionally written with easily understandable code and is not suitable for production usage.</em> </p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<h3 id="heading-metamask">Metamask</h3>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/image-32.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We need an Ethereum address to interact with our Smart Contract. We will be using <a target="_blank" href="https://metamask.io/">Metamask</a> as our wallet. It is a free virtual wallet that manages your Ethereum addresses. We will need it to send and receive transactions (read more on that <a target="_blank" href="https://ethereum.org/en/developers/docs/transactions/">here</a>). For example, minting an NFT is a transaction. </p>
<p>Download their Chrome extension and their mobile app. We will need both as the Chrome extension does not display your NFTs.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/image-34.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Make sure to change the network to "Ropsten Test Network" for development purposes. You will need some Eth to cover the fees of deploying and minting your NFT. Head to the <a target="_blank" href="https://faucet.ropsten.be/">Ropsten Ethereum Faucet</a> and enter your address. You should soon see some test Eth in your Metamask account.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/image-35.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-alchemy">Alchemy</h3>
<p>To interact with the Ethereum Network, you will need to be connected to an Ethereum Node. </p>
<p>Running your own Node and maintaining the infrastructure is a project on its own. Luckily, there are nodes-as-a-service providers which host the infrastructure for you. There are many choices like Infura, BlockDaemon, and Moralis. We will be using <a target="_blank" href="https://www.alchemy.com/">Alchemy</a> as our node provider. </p>
<p>Head over to their website, create an account, choose Ethereum as your network and create your app. Choose Ropsten as your network.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/image-36.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>On your dashboard, click "view details" on your app, then click "view key". Save your http key somewhere as we will need that later.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/image-38.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h3 id="heading-nodejsnpm">NodeJS/NPM</h3>
<p>We will be using NodeJS for the project. If you don't have it installed, <a target="_blank" href="https://www.freecodecamp.org/news/how-to-install-node-in-your-machines-macos-linux-windows/">follow this simple tutorial</a> by freeCodeCamp.</p>
<h2 id="heading-initialize-the-project">Initialize the project</h2>
<p>In your terminal, run this command to make a new directory for your project:</p>
<pre><code>mkdir nft-project
cd nft-project
</code></pre><p>Now, let's make another directory, <code>ethereum/</code>, inside <code>nft-project/</code> and initialize it with <a target="_blank" href="https://hardhat.org/getting-started/">Hardhat</a>. Hardhat is a dev tool that makes it easy to deploy and test your Ethereum software.</p>
<pre><code>mkdir ethereum
cd ethereum
npm init
</code></pre><p>Answer the questions however you want. Then, run those commands to make a Hardhat project:</p>
<pre><code>npm install --save-dev hardhat
npx hardhat
</code></pre><p>You will see this prompt:</p>
<pre><code><span class="hljs-number">888</span>    <span class="hljs-number">888</span>                      <span class="hljs-number">888</span> <span class="hljs-number">888</span>               <span class="hljs-number">888</span>
<span class="hljs-number">888</span>    <span class="hljs-number">888</span>                      <span class="hljs-number">888</span> <span class="hljs-number">888</span>               <span class="hljs-number">888</span>
<span class="hljs-number">888</span>    <span class="hljs-number">888</span>                      <span class="hljs-number">888</span> <span class="hljs-number">888</span>               <span class="hljs-number">888</span>
<span class="hljs-number">8888888888</span>  <span class="hljs-number">8888</span>b.  <span class="hljs-number">888</span>d888 .d88888 <span class="hljs-number">88888</span>b.   <span class="hljs-number">8888</span>b.  <span class="hljs-number">888888</span>
<span class="hljs-number">888</span>    <span class="hljs-number">888</span>     <span class="hljs-string">"88b 888P"</span>  d88<span class="hljs-string">" 888 888 "</span><span class="hljs-number">88</span>b     <span class="hljs-string">"88b 888
888    888 .d888888 888    888  888 888  888 .d888888 888
888    888 888  888 888    Y88b 888 888  888 888  888 Y88b.
888    888 "</span>Y888888 <span class="hljs-number">888</span>     <span class="hljs-string">"Y88888 888  888 "</span>Y888888  <span class="hljs-string">"Y888

Welcome to Hardhat v2.0.8

? What do you want to do? …
  Create a sample project
❯ Create an empty hardhat.config.js
  Quit</span>
</code></pre><p>Select create an empty hardhat.config.js. This will generate an empty <code>hardhat.config.js</code> file that we will later update.</p>
<p>For the web app, we will use <a target="_blank" href="https://nextjs.org/docs/getting-started">Next.js</a> to initialize a fully-functional web app. Go back to the root directory <code>nft-project/</code> and initialize a boilerplate Next.js app called web:</p>
<pre><code>cd ..
mkdir web
cd web
npx create-next-app@latest
</code></pre><p>Your project now looks like this:</p>
<pre><code>nft-project/
    ethereum/
    web/
</code></pre><p>Awesome! We are ready to dive into some real coding.</p>
<h2 id="heading-how-to-define-our-env-variables">How to Define Our .env Variables</h2>
<p>Remember the Alchemy key we grabbed from our test project earlier? We will use that along with our Metamask account's public and private keys to interact with the blockchain. </p>
<p>Run the following commands, make a file called <code>.env</code> inside your <code>ethereum/</code> directory, and install <a target="_blank" href="https://www.npmjs.com/package/dotenv">dotenv</a>. We will use them later.</p>
<pre><code>cd ..
cd ethereum
touch .env
npm install dotenv --save
</code></pre><p>For your <code>.env</code> file, put the key you have exported from Alchemy and <a target="_blank" href="https://metamask.zendesk.com/hc/en-us/articles/360015289632-How-to-Export-an-Account-Private-Key">follow those instructions</a> to grab your Metamask's private key.</p>
<p>Here's your .env file:</p>
<pre><code>DEV_API_URL = YOUR_ALCHEMY_KEY
PRIVATE_KEY = YOUR_METAMASK_PRIVATE_KEY
PUBLIC_KEY = YOUR_METAMASK_ADDRESS
</code></pre><h2 id="heading-the-smart-contract-for-nfts">The Smart Contract for NFTs</h2>
<p>Go to the <code>ethereum/</code> folder and create two more directories: contracts and scripts. <a target="_blank" href="https://hardhat.org/guides/project-setup.html">A simple hardhat project</a> contains those folders.</p>
<ul>
<li><code>contracts/</code> contains the source files of your contracts</li>
<li><code>scripts/</code> contains the scripts to deploy and mint our NFTs</li>
</ul>
<pre><code>mkdir contracts
mkdir scripts
</code></pre><p>Then, install OpenZeppelin. <a target="_blank" href="https://docs.openzeppelin.com/contracts/4.x/">OpenZeppelin Contract</a> is an open-sourced library with pre-tested reusable code to make smart contract development easier.</p>
<pre><code>npm install @openzeppelin/contracts
</code></pre><p>Finally, we will be writing the Smart Contract for our NFT. Navigate to your contracts directory and create a file titled <code>EmotionalShapes.sol</code>. You can name your NFTs however you see fit.</p>
<p>The <code>.sol</code> extension refers to the Solidity language, which is what we will use to program our Smart Contract. We will only be writing 14 lines of code with Solidity, so no worries if you haven't seen it before. </p>
<p>Start with <a target="_blank" href="https://ethereum.org/en/developers/docs/smart-contracts/languages/">this article</a> to learn more about Smart Contract languages. You can also directly jump to this Solidity <a target="_blank" href="https://reference.auditless.com/cheatsheet/">cheat sheet</a> which contains the main syntax.</p>
<pre><code>cd contracts
touch EmotionalShapes.sol
</code></pre><p>This is our 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.0;</span>

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

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">EmotionalShapes</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</span> </span>{
    <span class="hljs-keyword">using</span> <span class="hljs-title">Counters</span> <span class="hljs-title"><span class="hljs-keyword">for</span></span> <span class="hljs-title">Counters</span>.<span class="hljs-title">Counter</span>;
    Counters.Counter <span class="hljs-keyword">private</span> _tokenIdCounter;

    <span class="hljs-function"><span class="hljs-keyword">constructor</span>(<span class="hljs-params"></span>) <span class="hljs-title">ERC721</span>(<span class="hljs-params"><span class="hljs-string">"EmotionalShapes"</span>, <span class="hljs-string">"ESS"</span></span>) </span>{}

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">_baseURI</span>(<span class="hljs-params"></span>) <span class="hljs-title"><span class="hljs-keyword">internal</span></span> <span class="hljs-title"><span class="hljs-keyword">pure</span></span> <span class="hljs-title"><span class="hljs-keyword">override</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> <span class="hljs-string">"YOUR_API_URL/api/erc721/"</span>;
    }

    <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mint</span>(<span class="hljs-params"><span class="hljs-keyword">address</span> to</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">uint256</span></span>)
    </span>{
        <span class="hljs-built_in">require</span>(_tokenIdCounter.current() <span class="hljs-operator">&lt;</span> <span class="hljs-number">3</span>); 
        _tokenIdCounter.increment();
        _safeMint(to, _tokenIdCounter.current());

        <span class="hljs-keyword">return</span> _tokenIdCounter.current();
    }
}
</code></pre>
<p>Let's go through the code and understand what is going on. </p>
<ol>
<li>At the top of the file, we specified which OpenZeppelin module to import. We need the ERC721 contract as it is the 'base' of our Smart Contract. It has already implemented all the methods specified in <a target="_blank" href="https://eips.ethereum.org/EIPS/eip-721">EIP-721</a> so we can safely use it.</li>
<li>A Counter is useful to generate incremental ids for our NFTs. We named the variable <code>_tokenIdCounter</code></li>
<li>In the constructor, we initialized our ERC721 with its name and its symbol. I chose EmotionalShapes and ESS.</li>
<li>We override the default <code>_baseURI</code> function by returning our own. We will get to build that in a second. In summary, it is the URL that will be added as 'prefix' to all our tokenURIs. In the above example, the metadata of our NFTs will live in a JSON file at <code>YOUR_API_URL/[api/erc721/](https://e110-99-121-58-31.ngrok.io/api/erc721/)1</code>.</li>
<li>We implement the 'mint' function. It is the function that lets you publish an instance of this Smart Contract on the blockchain. I required the <code>_tokenIdCounter</code> variable to be less than 3 as I will only create three instances of my NFT. You can remove that if you want to mint more.</li>
<li>Finally, inside the mint function, we increment the <code>_tokenIdCounter</code> variable by 1, so our id will be 1, followed by 2, followed by 3. Then, we call the function provided by OpenZeppelin <code>_safeMint</code> to publish the token.</li>
</ol>
<p>Don't worry if you feel lost. You can attend a workshop led by volunteers from freeCodeCamp, where we invite devs of similar skill levels to build stuff together, including this NFT project. </p>
<p>The events are free and remote, so you can ask any questions directly. You can register <a target="_blank" href="https://equia.io">here</a>. The seats are limited so you will be invited to the next available events.</p>
<h2 id="heading-how-to-build-the-metadata-for-our-nft">How to Build the Metadata for our NFT</h2>
<p>As mentioned earlier, there are three main ways of storing your tokenURI. We will be building a simple API endpoint which resolve in our NFT's information as JSON. </p>
<p>Our Next.js project gives us a handy way to develop API routes. Go to the <code>web/</code> folder, find the <code>api/</code> folder within the <code>pages/</code> folder, and make our dynamic <code>[id].js</code> route in a <code>erc721/</code> folder (read more about routing <a target="_blank" href="https://www.freecodecamp.org/news/p/18513919-9e93-4ab3-9f52-2448aafa8835/develop%20API%20routes">here</a>):</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// web/pages/api/erc721/[id].js</span>

<span class="hljs-keyword">const</span> metadata = {
  <span class="hljs-number">1</span>: {
    <span class="hljs-attr">attributes</span>: [
      {
        <span class="hljs-attr">trait_type</span>: <span class="hljs-string">"Shape"</span>,
        <span class="hljs-attr">value</span>: <span class="hljs-string">"Circle"</span>,
      },
      {
        <span class="hljs-attr">trait_type</span>: <span class="hljs-string">"Mood"</span>,
        <span class="hljs-attr">value</span>: <span class="hljs-string">"Sad"</span>,
      },
    ],
    <span class="hljs-attr">description</span>: <span class="hljs-string">"A sad circle."</span>,
    <span class="hljs-attr">image</span>: <span class="hljs-string">"https://i.imgur.com/Qkw9N0A.jpeg"</span>,
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Sad Circle"</span>,
  },
  <span class="hljs-number">2</span>: {
    <span class="hljs-attr">attributes</span>: [
      {
        <span class="hljs-attr">trait_type</span>: <span class="hljs-string">"Shape"</span>,
        <span class="hljs-attr">value</span>: <span class="hljs-string">"Rectangle"</span>,
      },
      {
        <span class="hljs-attr">trait_type</span>: <span class="hljs-string">"Mood"</span>,
        <span class="hljs-attr">value</span>: <span class="hljs-string">"Angry"</span>,
      },
    ],
    <span class="hljs-attr">description</span>: <span class="hljs-string">"An angry rectangle."</span>,
    <span class="hljs-attr">image</span>: <span class="hljs-string">"https://i.imgur.com/SMneO6k.jpeg"</span>,
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Angry Rectangle"</span>,
  },
  <span class="hljs-number">3</span>: {
    <span class="hljs-attr">attributes</span>: [
      {
        <span class="hljs-attr">trait_type</span>: <span class="hljs-string">"Shape"</span>,
        <span class="hljs-attr">value</span>: <span class="hljs-string">"Triangle"</span>,
      },
      {
        <span class="hljs-attr">trait_type</span>: <span class="hljs-string">"Mood"</span>,
        <span class="hljs-attr">value</span>: <span class="hljs-string">"Bored"</span>,
      },
    ],
    <span class="hljs-attr">description</span>: <span class="hljs-string">"An bored triangle."</span>,
    <span class="hljs-attr">image</span>: <span class="hljs-string">"https://i.imgur.com/hMVRFoJ.jpeg"</span>,
    <span class="hljs-attr">name</span>: <span class="hljs-string">"Bored Triangle"</span>,
  },
};

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">handler</span>(<span class="hljs-params">req, res</span>) </span>{
  res.status(<span class="hljs-number">200</span>).json(metadata[req.query.id] || {});
}
</code></pre>
<p>For the sake of this project, I made the code as easily understandable as possible. This is definitely not suited for production (please don't use an Imgur url for your NFT). Make sure to define the metadata for all the NFTs that you intend to mint.</p>
<p>Now, go to the web directory, and start your Next.js app with this command:</p>
<pre><code>npm run dev
</code></pre><p>Your app should be running on localhost:3000. To make sure our endpoint works, go to <a target="_blank" href="http://localhost:3000/api/erc721/1">http://localhost:3000/api/erc721/1</a> and it should resolve with a JSON object of your first NFT's metadata.</p>
<h2 id="heading-how-to-expose-the-metadata-for-our-nft">How to Expose the Metadata for our NFT</h2>
<p>Since your app is hosted locally, other apps cannot access it. Using a tool like <a target="_blank" href="https://ngrok.com/">ngrok</a>, we can expose our local host to a publicly accessible URL.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/image-39.png" alt="Image" width="600" height="400" loading="lazy"></p>
<ol>
<li>Go to <a target="_blank" href="https://ngrok.com/">ngrok.com</a> and complete the registration process</li>
<li>Unzip the downloaded package</li>
<li>In your terminal, make sure you cd into the folder where you unzipped your ngrok package</li>
<li>Follow the instruction on your dashboard and run</li>
</ol>
<pre><code>./ngrok authtoken YOUR_AUTH_TOKEN
</code></pre><ol start="5">
<li>Then, run this command to create a tunnel to your web app hosted on localhost:3000</li>
</ol>
<pre><code>./ngrok http <span class="hljs-number">3000</span>
</code></pre><ol start="6">
<li>You are almost there! On your terminal, you should see something like this:</li>
</ol>
<pre><code>ngrok by @inconshreveable                                                                            (Ctrl+C to quit)

Session Status                online                                                                                 
Account                       YOUR_ACCOUNT (Plan: Free)                                                                       
Version                       <span class="hljs-number">2.3</span><span class="hljs-number">.40</span>                                                                                 
Region                        United States (us)                                                                     
Web Interface                 http:<span class="hljs-comment">//127.0.0.1:4040                                                                  </span>
Forwarding                    http:<span class="hljs-comment">//YOUR_NGROK_ADDRESS -&gt; http://localhost:3000                             </span>
Forwarding                    https:<span class="hljs-comment">//YOUR_NGROK_ADDRESS -&gt; http://localhost:3000</span>
</code></pre><p>Go to <code>YOUR_NGROK_ADDRESS/api/erc721/1</code> to make sure your endpoint works correctly.</p>
<h2 id="heading-how-to-deploy-our-nft">How to Deploy our NFT</h2>
<p>Now that we have done all the ground work (oof), let's go back to our <code>ethereum/</code> folder and get ready to deploy our NFT.</p>
<p>Change the <code>_baseURI</code> function in your <code>ethreum/contracts/YOUR_NFT_NAME.sol</code> file to return your ngrok address.</p>
<pre><code><span class="hljs-comment">// ethereum/conrtacts/EmotionalShapes.sol</span>

contract EmotionalShapes is ERC721 {
...
    function _baseURI() internal pure override returns (string memory) {
        <span class="hljs-keyword">return</span> <span class="hljs-string">"https://YOUR_NGROK_ADDRESS/api/erc721/"</span>;
    }
...
}
</code></pre><p>To deploy our NFT, we will first need to <a target="_blank" href="https://hardhat.org/guides/compile-contracts.html">compile it using Hardhat</a>. To make the process easier, we will install <a target="_blank" href="https://docs.ethers.io/v5/">ethers.js</a>.</p>
<pre><code>npm install @nomiclabs/hardhat-ethers --save-dev
</code></pre><p>Let's update our hardhat.config.js:</p>
<pre><code><span class="hljs-built_in">require</span>(<span class="hljs-string">"dotenv"</span>).config();
<span class="hljs-built_in">require</span>(<span class="hljs-string">"@nomiclabs/hardhat-ethers"</span>);

<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">solidity</span>: <span class="hljs-string">"0.8.0"</span>,
  <span class="hljs-attr">defaultNetwork</span>: <span class="hljs-string">"ropsten"</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>: process.env.DEV_API_URL,
      <span class="hljs-attr">accounts</span>: [<span class="hljs-string">`0x<span class="hljs-subst">${process.env.PRIVATE_KEY}</span>`</span>],
    },
  },
};
</code></pre><p>To learn more about the hardhat configuration file, take a look at their <a target="_blank" href="https://hardhat.org/config/">documentation</a>. We have configured the ropsten network with our Alchemy URL and provided it with the private key of your metamask account.</p>
<p>Finally, run:</p>
<pre><code>npx hardhat compile
</code></pre><p>This lets hardhat generate two files per compiled contract. We should see a newly created <code>artifacts/</code> folder that contains your compiled contracts in the <code>contracts/</code> folder. To learn more about how that works, read <a target="_blank" href="https://hardhat.org/guides/compile-contracts.html">this tutorial</a> by the Hardhat team.</p>
<p>Now, let's write a script to finally deploy our NFT to the test network. In your <code>scripts/</code> folder, create a file called <code>deploy.js</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// ethereum/scripts/deploy.js</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> EmotionalShapes = <span class="hljs-keyword">await</span> ethers.getContractFactory(<span class="hljs-string">"EmotionalShapes"</span>);
  <span class="hljs-keyword">const</span> emotionalShapes = <span class="hljs-keyword">await</span> EmotionalShapes.deploy();

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"EmotionalShapes deployed:"</span>, emotionalShapes.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>This code is inspired by <a target="_blank" href="https://hardhat.org/guides/deploying.html">the hardhat deployment tutorial</a>.</p>
<blockquote>
<p>A <code>ContractFactory</code> in ethers.js is an abstraction used to deploy new smart contracts, so <code>EmotionalShapes</code> here is a factory for instances of our token contract. Calling <code>deploy()</code> on a <code>ContractFactory</code> will start the deployment, and return a <code>Promise</code> that resolves to a <code>Contract</code>. This is the object that has a method for each of your smart contract functions.</p>
</blockquote>
<h3 id="heading-how-to-view-the-nft-on-the-blockchain">How to view the NFT on the blockchain</h3>
<p>Run the deployment script:</p>
<pre><code>node ./scripts/deploy.js
</code></pre><p>You should see in your terminal <code>EmotionalShapes deployed: SOME_ADDRESS</code>. This is the address where your Smart Contract is deployed on the ropsten test network.</p>
<p>If you head over to <code>https://ropsten.etherscan.io/address/SOME_ADDRESS</code>, you should see your freshly deployed NFT. Yes! You did it!</p>
<p>If you are stuck somewhere in the tutorial or feeling lost, again, you can <a target="_blank" href="https://equia.io">join our live workshops</a> where we will build this project together in a Zoom call. </p>
<h2 id="heading-how-to-mint-your-nft">How to Mint your NFT</h2>
<p>Now that you have deployed your NFT, it's time to mint it for yourself! Create a new file called <code>mint.js</code> in your scripts/ folder. We will be using ethers.js to help us.</p>
<p>Start by adding the <code>ethers.js</code> package:</p>
<pre><code>npm install --save ethers
</code></pre><p>Then, populate the <code>mint.js</code> file:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">require</span>(<span class="hljs-string">"dotenv"</span>).config();
<span class="hljs-keyword">const</span> { ethers } = <span class="hljs-built_in">require</span>(<span class="hljs-string">"ethers"</span>);

<span class="hljs-keyword">const</span> contract = <span class="hljs-built_in">require</span>(<span class="hljs-string">"../artifacts/contracts/EmotionalShapes.sol/EmotionalShapes.json"</span>);
<span class="hljs-keyword">const</span> contractInterface = contract.abi;

<span class="hljs-comment">// https://docs.ethers.io/v5/api/providers</span>
<span class="hljs-keyword">const</span> provider = ethers.getDefaultProvider(<span class="hljs-string">"ropsten"</span>, {
  <span class="hljs-attr">alchemy</span>: process.env.DEV_API_URL,
});

<span class="hljs-comment">// https://docs.ethers.io/v5/api/signer/#Wallet</span>
<span class="hljs-keyword">const</span> wallet = <span class="hljs-keyword">new</span> ethers.Wallet(process.env.PRIVATE_KEY, provider);

<span class="hljs-comment">//https://docs.ethers.io/v5/api/contract/contract</span>
<span class="hljs-keyword">const</span> emotionalShapes = <span class="hljs-keyword">new</span> ethers.Contract(
  YOUR_NFT_ADDRESS,
  contractInterface,
  wallet
);

<span class="hljs-keyword">const</span> main = <span class="hljs-function">() =&gt;</span> {
  emotionalShapes
    .mint(process.env.PUBLIC_KEY)
    .then(<span class="hljs-function">(<span class="hljs-params">transaction</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(transaction))
    .catch(<span class="hljs-function">(<span class="hljs-params">e</span>) =&gt;</span> <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"something went wrong"</span>, e));
};

main();
</code></pre>
<p>I have left comments to where you can find more information about the different methods. We first grab the contract's interface (ABI). From ethereum.org:</p>
<blockquote>
<p>An application binary interface, or ABI, is the standard way to interact with <a target="_blank" href="https://ethereum.org/en/glossary/#contract-account">contracts</a> in the Ethereum ecosystem, both from outside the blockchain and for contract-to-contract interactions.</p>
</blockquote>
<p>Your ABI defines how others interact with your contract. Then, we created our provider with Alchemy (remember about node-as-a-service). Finally, we initialize our wallet with our private key.</p>
<p>The <code>main()</code> function calls the <code>mint</code> method in the Smart Contract we had just deployed. The <code>mint</code> method takes only one parameter, <code>to</code>, which indicate the receiver of the token. Since we are minting for ourself, we put the public address of our Metamask account.</p>
<p>If everything goes well, you should see the transaction logged in your terminal. Grab the <code>hash</code> property and go to <code>https://ropsten.etherscan.io/tx/YOUR_HASH</code>. You should see the minting transaction there!</p>
<h2 id="heading-how-to-view-the-nft-in-your-metamask-wallet">How to View the NFT in your Metamask Wallet</h2>
<p>You need to start by downloading the mobile version of Metamask. Then, log into your account. </p>
<p>You should see an NFTs tab along with an add NFT button. Click on the button and enter the address of your Smart Contract along with the ids that you have minted. If you have followed the tutorial, you should start with an id of <code>1</code>.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/10/IMG_0376.jpeg" alt="Image" width="600" height="400" loading="lazy">
<em>View NFTs in your Metamask wallet</em></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Congratulations! You have just minted your own NFT. In the next part of the project, we will be building the front end React app to interact with our contract. The end goal is to build a fully functional web app where you can sell your own NFTs.</p>
<p>Lastly, you can <a target="_blank" href="https://equia.io">join our live workshops</a> with volunteers from freeCodeCamp where we will build this project together with other developers. </p>
<p>The events are free for everyone across the world and invitations are sent first-come, first-serve. If you'd like to lead the workshops, DM me <a target="_blank" href="https://twitter.com/aly4alyssa">on Twitter</a>, we'd love to have you! We also organize other type of events like hiring fairs and social meetups. </p>
<p>Let me know what you want to build. NFTs are still in its infancy and novel ideas are more than welcome. Can't wait to see what crazy idea you have!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ The New Creator Economy – DAOs, Community Ownership, and Cryptoeconomics ]]>
                </title>
                <description>
                    <![CDATA[ By Nader Dabit I first had what I can only describe as a spiritual awakening about 10 years ago to the fact that technology would (figuratively) rule the world. And since then, I've been obsessed with wanting to understand how software works and how ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/the-new-creator-economy-daos-community-ownership-and-cryptoeconomics/</link>
                <guid isPermaLink="false">66d46049e39d8b5612bc0dcc</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ community ]]>
                    </category>
                
                    <category>
                        <![CDATA[ crypto ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Web3 ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 27 Aug 2021 17:02:29 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/08/democratize.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Nader Dabit</p>
<p>I first had what I can only describe as a spiritual awakening about 10 years ago to the fact that technology would (figuratively) rule the world. And since then, I've been obsessed with wanting to understand how software works and how to build it.</p>
<p>Since that moment, my life has changed significantly for the better. I can only attribute it to the simple fact that I have relied not only on my own instincts, but on those of people much smarter and more experienced than I am.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/kissingsky/status/1428368687644364805"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>My hypothesis is this: try to find and follow the lead of those who have exhibited a long track record of success, find interests in their wake, and do my best to excel at them (while continuing to explore my own curiosities).</p>
<p>This approach has led me to try and master JavaScript, and then React, and finally to build a successful consultancy. All this ultimately landed me on a team at AWS in a life changing experience that lasted a little over 3 years. All of this with <a target="_blank" href="https://twitter.com/dabit3/status/1259471051429478400">no high school diploma or college degree</a>.</p>
<p>During this time (like many developers) I've relentlessly dived into books, podcasts, blog posts, YouTube videos, and source code of every kind. But there has always been a topic that has captured my curiosity the most – futurism.</p>
<p>Futurists like <a target="_blank" href="https://twitter.com/gleonhard">Gerd Leonhard</a> and <a target="_blank" href="https://twitter.com/michiokaku">Michio Kaku</a> speak of a future that's sometimes beautiful and sometimes bleak. But it's always with the passion and phrasing that make your thoughts wander and move past the current moment in time and into a mind boggling world that does not yet exist.</p>
<p>I recently had another "aha" moment, similar to my technological awakening, that has completely changed the direction of my career and my life. In the spirit of these futurists, I want to talk about why <a target="_blank" href="https://www.freecodecamp.org/news/what-is-web3/">Web3</a> excites me just as much as their ideas, but is instead happening as we speak.</p>
<h2 id="heading-why-is-web3-so-exciting">Why is Web3 So Exciting?</h2>
<p>This post is meant to dive more into what I think are the benefits and repercussions of Web3. If you want to know my interpretation of what Web3 is, see my thoughts <a target="_blank" href="https://www.freecodecamp.org/news/what-is-web3/">here</a>.</p>
<p>Web3 represents a handful of ideas which together bring about entirely new mental models, organizational structures, and community incentives. These force us to rethink many things that we have become accustomed to.</p>
<p>All of the recent innovation happening is possible because of decentralized protocols. The internet itself has thrived because of native internet protocols that we use everyday, like HTTP, FTP, TCP, and SSH. </p>
<p>One of the reasons these protocols have been so successful was that they were widely adopted and not subject to change. If I build a site using HTTP, people can use it without any centralized intermediary – we can trust that it is going to work.</p>
<p>There are two major pieces of native functionality that have been left out up until recently – payments and state.</p>
<p>Blockchains have enabled both of these things, opening the door for programmable money and state without the need of a centralized server, bank, or any intermediary at all.</p>
<h3 id="heading-web3-enables-ownership">Web3 Enables Ownership</h3>
<p>One of the driving forces and the one that resonates with most people (and me) is that Web3 enables ownership.</p>
<h4 id="heading-gaming">Gaming</h4>
<p>At some point the internet and gaming became almost indistinguishable. Not only because most games continue to receive updates over time, but the most popular ones are often the most interactive ones.</p>
<p>Fortnite took a lot of people by surprise because it created an innovative new combination of gameplay, peer-to-peer connection, and a unique business model – and everyone gets the game for free. </p>
<p>The experience is very interactive, you can join old friends and make new ones, there are constant improvements and enhancements that just happen automatically – the game is consistently evolving.</p>
<p>The monetization strategy was also innovative. Fortnite allows players to buy in-game currency as well as skins that they can wear in the game. If you have a child you know that the $65 you may have spent on the game itself is probably peanuts compared to the amount of money kids spend over the lifetime of their gameplay.</p>
<p>The problem, though, is this: when the player decides to stop playing the game or outgrows it, where has all that money gone? More importantly, who is allowed as a creator to benefit from all of the purchasing power? The answer is, well, Fortnite (the platform).</p>
<p>What if, instead, players retained ownership of their items and were able to keep or sell them? Their items would maintain, increase, or decrease in value like any physical asset. </p>
<p>These types of experiences and communities are now being made possible via NFTs. NFTs enable scarcity in a world where there was in the past no scarcity.</p>
<p><a target="_blank" href="https://axieinfinity.com/">Axie Infinity</a> is an example of how this looks in practice. It is a blockchain-based game that is the most successful of its kind, and has recently had explosive growth, catapulting it to over <a target="_blank" href="https://hypebeast.com/2021/8/axie-infinity-ethereum-first-nft-game-1-bilion-sales-info">$1 billion in sales</a> with over $780 million in the 30 days ending August 10 2021.</p>
<p><a target="_blank" href="https://parallel.life/faq/">Parallel</a> is an online card game that has done over $100 million in sales and is still extremely early. <a target="_blank" href="https://zkga.me/">Dark Forest</a> enables players to <a target="_blank" href="https://twitter.com/BlaineBublitz/status/1399397415732400129">get paid to play the game</a>.</p>
<p>When players realize they can retain much of the value of their time and investments while still enjoying the benefit of the game, it changes the way they view gaming and where they spend their money. But it also aligns new incentives around the game itself. If the game succeeds, they can share in that success, therefore they become even more invested.</p>
<p>The combination of ownership, community, and creators who have built audiences creates a whirlwind of new and exciting opportunities that we are just starting to begin see explored.</p>
<p><a target="_blank" href="https://twitter.com/Fwiz">Ryan Watt</a>, the head of YouTube gaming agrees.</p>
<h3 id="heading-social-media-and-art">Social media and art</h3>
<p>Social media platforms were revolutionary. They allowed anyone from almost any background the ability to grow and foster large audiences using tools that were made free to anyone with a device and an internet connection. </p>
<p>There are no gatekeepers to becoming famous on social media as there have been in the past in film and TV. The intermediary was abstracted away and peer to peer connections and content sharing was made possible.</p>
<p>The flaw in these implementations is that they offer a terrible monetization system, not just for the platform but for the creator as well. </p>
<p>Advertising and the exploitation of user data is the go to play. Also almost all of the money generated by the platform, goes to the platform – the platform monetizes the content being created by its users in exchange for use of the platform itself. This is how social media works today.</p>
<p>In Web3, both creators and the community are able to gain and retain ownership within a platform, creating a synergy that, once experienced, makes the legacy interactions of the past seem archaic and undesirable. </p>
<p>When I say ownership, I don't only mean ownership of content, but actual equity as well.</p>
<p>We are seeing the beginnings of this in the art world of Web3. Artists who were, in the past, often barely making it are now able to leverage their platforms, often in collaboration with other community members or causes. They can create projects that leverage NFT collections to give community members as well as the public a way to participate and distribute equity all around. Art and code are also beginning to overlap.</p>
<p>Projects like <a target="_blank" href="https://generativemasks.on.fleek.co/#/">Generative Masks</a> allow talented creators like <a target="_blank" href="https://twitter.com/takawo">Takawo Shunsuke</a> to leverage the skills he's acquired throughout his career to generate over $3 million in sales for his collection in just a few minutes. He's able to spread awareness for himself and his cause, and create another new community (of owners) simultaneously. </p>
<p>The best part is that he's giving it all back to the communities he's benefited from. On top of that, smart contracts allow him to programmatically enable a commission for any future sale that happens going forward, and in just a couple of weeks that amounts to another $600,000.00+.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/dabit3/status/1427807893458497544"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>Generative art itself is an emerging category that combines code and creativity and is something that could alone warrant an entire post. But it suits the coming era particularly well, as it enables artists to scale their creativity, community, and distribution.</p>
<p>There will continue to be a larger and larger percentage of digital artists because they can use powerful tools and programs to create art that can then be used in an infinite number of ways. They can then put it for sale on an international, 24 hour, liquid market.</p>
<p>OpenSea, the top online art marketplace today, has seen an absolute explosion in growth the past few months.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/natechastain/status/1429965382849343490"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>Even recently surpassing Etsy in sales.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/xanderatallah/status/1427453596858294272"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>Whether this type of volume continues, I have no idea. My guess is that there will be some volatility and fairly large swings both up and down. But there is definitely <em>something</em> there.</p>
<p>Most of these NFT projects are launched on Ethereum. Ethereum is soon merging <a target="_blank" href="https://ethereum.org/en/eth2/">a new consensus mechanism</a> that will make NFTs orders of magnitude more environmentally friendly as a means of sales and transfer of art, which in the past all required ground transportation.</p>
<h4 id="heading-future-of-social-media">Future of social media</h4>
<p>As it stands today, users of social media platforms can begin leveraging Web3 tools, communities, and platforms to begin monetizing their audience. </p>
<p>I believe there will be a breakthrough app that will disrupt social media as we know it built in the in the next 1 - 3 years that blends all of these ideas together in a way that we haven't experienced yet.</p>
<p>Many people have echoed a similar sentiment. <a target="_blank" href="https://twitter.com/AaveAave">Aave</a>, a very successful DeFi protocol built on Ethereum, has already begun work on <a target="_blank" href="https://decrypt.co/76278/defi-project-aave-to-release-ethereum-based-twitter-alternative-this-year">a decentralized version of Twitter</a>:</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/stanikulechov/status/1416385933549654016"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>Jack Dorsey of Twitter is also working on a Decentralized version of Twitter, though I believe that this type of application will ultimately come from the community or a DAO.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/arcalinea/status/1427314482154414080"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<h3 id="heading-daos-grants-community-ownership-and-social-tokens">DAOs, grants, community ownership, and social tokens</h3>
<blockquote>
<p>DAO stands for Decentralized Autonomous Organization. You can read about what a DAO is <a target="_blank" href="https://www.notboring.co/p/the-dao-of-daos">here</a>, <a target="_blank" href="https://linda.mirror.xyz/Vh8K4leCGEO06_qSGx-vS5lvgUqhqkCz9ut81WwCP2o">here</a>, and <a target="_blank" href="https://decrypt.co/resources/decentralized-autonomous-organization-dao">here</a>, but I want to focus on how DAOs will play a part in the new creator economy.</p>
</blockquote>
<p>Shared ownership is a characteristic you'll see carried across all areas of Web3, including how we think about companies and incentive structures around how business is done.</p>
<p>In Web2 companies, cash usually comes from investors and there is no value returned to them for years. Ownership is largely concentrated in the first handful of employees along with their investors.</p>
<p>It usually takes years to reach a point where investors or employees with equity can begin to see any return on their investment and time spent, often through the old ways of advertising and exploitation of user data.</p>
<p>Web3 and blockchains bring about entirely new business models, made possible by <a target="_blank" href="https://www.gemini.com/cryptopedia/what-is-tokenization-definition-crypto-token#section-security-tokens-utility-tokens-and-cryptocurrencies">tokenization</a> and <a target="_blank" href="https://thegraph.com/blog/modeling-cryptoeconomic-protocols-as-complex-systems-part-1">cryptoeconomic protocols</a>.</p>
<p>There are quite literally countless ways that these tokens are being utilized to create new ways of collaboration and building, ranging from DAOs to web infrastructure to <a target="_blank" href="https://coopahtroopa.mirror.xyz/gWY6Kfebs9wHdfoZZswfiLTBVzfKiyFaIwNf2q8JpgI">micro-economies</a>:</p>
<p><a target="_blank" href="https://twitter.com/prtyDAO">PartyDAO</a> which <a target="_blank" href="https://twitter.com/nnnnicholas/status/1423428739589943300">created over $200,000 in revenue in its first day</a>, was "built in 3 months by a small group of internet friends working part-time", and is backed by a smart contract</p>
<p><a target="_blank" href="https://compound.finance/">Compound</a>, a decentralized finance protocol that allows you to lend and borrow cryptocurrency without trusting a third party with your funds has a market cap of over $2 billion as of this writing</p>
<p><a target="_blank" href="https://docs.superrare.com/the-superrare-dao">Super Rare</a> is a digital art platform that recently launched a token, <a target="_blank" href="https://twitter.com/DCLBlogger/status/1427860274808197124">airdropping as much as $140,000 to its earliest users</a></p>
<p><a target="_blank" href="https://gitcoin.co/">Gitcoin</a> is a platform that enables developers to get paid for working on open source projects</p>
<p><a target="_blank" href="https://thegraph.com/">Graph Protocol</a> is a decentralized web infrastructure protocol that allows developers to build APIs to enable the performant querying of blockchain data, all enabled by its native utility token</p>
<p><a target="_blank" href="https://twitter.com/seedclubhq">Seed Club</a> is a social token incubator that’s focused on helping creators launch and grow social tokens</p>
<p><a target="_blank" href="https://twitter.com/fwbtweets">Friends with Benefits</a> is a social DAO and community that I'm part of that is 100% owned and governed by the participants</p>
<p><a target="_blank" href="https://twitter.com/pleasrdao">PleasrDAO</a> allows investors to come together to purchase high-value non-fungible tokens like <a target="_blank" href="https://foundation.app/@Snowden/stay-free-edward-snowden-2021-24437">this piece</a> from Edward Snowden.</p>
<p>Most DAOs have <a target="_blank" href="https://thegraph.com/blog/wave-one-funding">desirable grants programs</a>, enabling developers and other participants to work with various teams and projects at their will, on things they find interesting or that fit their skill set. </p>
<p>There are more and more people beginning to work full time for grants and with DAOs vs traditional full time employment.</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/dabit3/status/1418307358946701319"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<h2 id="heading-conclusion">Conclusion</h2>
<p>If this sounds like something you're interested in being involved in, I'd suggest that you jump right in. Try P2E (play to earn), get involved with a DAO, or even mint your own NFT.</p>
<p>Also check out <a target="_blank" href="https://www.freecodecamp.org/news/breaking-into-ethereum-crypto-web3-as-a-developer/">How to Get into Crypto, Ethereum, and Web3 as a Developer</a> which is what I put together after getting my own start in the space.</p>
<p>If you want to learn more about these ideas, I encourage you to follow some of the people I mention in this post:</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/dabit3/status/1430865775011803137"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
<p>Also, here are some of my favorite articles that touch on some of the stuff I've outlined here:</p>
<p><a target="_blank" href="https://coopahtroopa.mirror.xyz/gWY6Kfebs9wHdfoZZswfiLTBVzfKiyFaIwNf2q8JpgI">The Rise of Micro-Economies</a></p>
<p><a target="_blank" href="https://www.rushil2cents.com/the-creator-economy-today-vs-2025/">The Creator Economy: Today Vs. 2025</a></p>
<p><a target="_blank" href="https://www.notboring.co/p/the-value-chain-of-the-open-metaverse">The Value Chain of the Open Metaverse</a></p>
<p><a target="_blank" href="https://www.notboring.co/p/the-dao-of-daos">The DAO of DAOs</a></p>
<p>Thanks to <a target="_blank" href="https://twitter.com/adeets_22">Aditi</a> for helping me with ideas and edits as I was getting this across the finish line 🙏</p>
<div class="embed-wrapper">
        <blockquote class="twitter-tweet">
          <a href="https://twitter.com/dabit3/status/1430585405662011397"></a>
        </blockquote>
        <script defer="" src="https://platform.twitter.com/widgets.js" charset="utf-8"></script></div>
 ]]>
                </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[ Solidity Tutorial – How to Create NFTs with Hardhat ]]>
                </title>
                <description>
                    <![CDATA[ I'm a developer who's mostly been writing JavaScript, so the Solidity development environment was a bit hard to learn.  About four months ago, I switched to Hardhat from Truffle. This cool new kid on the block drastically improved my coding experienc... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/solidity-tutorial-hardhat-nfts/</link>
                <guid isPermaLink="false">66b99a2f9aaac6f19de58aff</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ NFT ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Smart Contracts ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Solidity ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Taisuke Mino ]]>
                </dc:creator>
                <pubDate>Mon, 17 May 2021 14:39:55 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2021/05/hardhat_nft-1.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>I'm a developer who's mostly been writing JavaScript, so the Solidity development environment was a bit hard to learn. </p>
<p>About four months ago, I switched to <a target="_blank" href="https://hardhat.org/">Hardhat</a> from Truffle. This cool new kid on the block drastically improved my coding experience. So today I want to share it with my fellow Solidity developers.</p>
<p>In this post, I will walk you through the initial set-up, compilation, testing, debugging, and finally deployment.</p>
<p>At the end of this post, you will be able understand how to deploy an NFT contract to the local network with Hardhat. </p>
<p>The goal of this post is to make you familiar with Hardhat. I won’t talk about how to write a test or Solidity syntax. However, you should be able to follow along without any Solidity knowledge if you know how to write JavaScript.</p>
<p>See <a target="_blank" href="https://github.com/taisukemino/hardhat-nft-tutorial">this repo</a> for the code.</p>
<h2 id="heading-how-to-set-up-the-project">How to Set Up the Project</h2>
<p>Let’s start an npm project first:</p>
<pre><code>npm init --yes
</code></pre><p>Then install the Hardhat package:</p>
<pre><code>npm install --save-dev hardhat
</code></pre><p>Cool! Now you are ready to create a new Hardhat project:</p>
<pre><code>npx hardhat
</code></pre><p>Choose <code>Create an empty hardhat.config.js</code>:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/image-1.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This will create <code>hardhat.config.js</code> in your root directory with the solidity compiler version specified:</p>
<pre><code class="lang-js"><span class="hljs-comment">/**
 * <span class="hljs-doctag">@type </span>import('Hardhat/config').HardhatUserConfig
 */</span>
<span class="hljs-built_in">module</span>.exports = {
  <span class="hljs-attr">solidity</span>: <span class="hljs-string">"0.7.3"</span>,
};
</code></pre>
<h2 id="heading-how-to-write-and-compile-the-contract">How to Write and Compile the Contract</h2>
<p>All right, we will start writing a simple contract and then we'll compile it.</p>
<p>Make a new Solidity file within a new <code>contracts</code> directory:</p>
<pre><code> mkdir contracts &amp;&amp; cd contracts &amp;&amp; touch MyCryptoLions.sol
</code></pre><p>We'll use the open-zeppelin package to write our NFT contract. So first, install the open-zeppelin package:</p>
<pre><code>npm install --save-dev @openzeppelin/contracts
</code></pre><p>Here is the contract code we will be compiling:</p>
<pre><code class="lang-solidity"><span class="hljs-meta"><span class="hljs-keyword">pragma</span> <span class="hljs-keyword">solidity</span> ^0.7.3;</span>

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

<span class="hljs-class"><span class="hljs-keyword">contract</span> <span class="hljs-title">MyCryptoLions</span> <span class="hljs-keyword">is</span> <span class="hljs-title">ERC721</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">ERC721</span>(<span class="hljs-params">name, symbol</span>)
    </span>{}
}
</code></pre>
<p>The first thing you need to do in any solidity file is to declare the compiler version. Then we can import the ERC721 contract (NFT contract) from open-zeppelin just like you do in JavaScript.</p>
<p>Solidity is a contract-oriented language. Just like an object-oriented language, contracts can have members such as functions and variables. In our code, we have only the constructor, which will be called when we deploy our contract.</p>
<p>Our contract inherits the ERC721 and then passes the <code>name</code> and <code>symbol</code> arguments which are going to be passed to the ERC721 contract. They literally decide the name and symbol of your NFT token.</p>
<p>We will pass whatever values we want to <code>name</code> and <code>symbol</code> at the point of deployment.</p>
<p>To compile it, run:</p>
<pre><code>npx hardhat compile
</code></pre><p>You might get some warnings but we'll ignore them to keep things simple. You should see <code>Compilation finished successfully</code> at the bottom.</p>
<p>You should also notice that the <code>/arfifacts</code> and <code>/cache</code> directories were generated. You don’t have to worry about them for this post, but it’s good to keep in mind that you can use <code>abi</code> in the artifacts if you want to interact with the contract when you build the frontend.</p>
<h2 id="heading-how-to-test-the-contract">How to Test the Contract</h2>
<p>Since smart contracts are mostly financial applications – and they're also hard to change – testing is critical.</p>
<p>We will use some packages for testing. Install with the command below:</p>
<pre><code>npm install --save-dev @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers ethers
</code></pre><p><code>ethereum-waffle</code> is a testing framework for smart contracts. <code>chai</code> is an assertion library. We'll write tests in waffle using Mocha alongside Chai. <code>ethers.js</code> is a JavaScript SDK for interacting with the Ethereum blockchain. The other two packages are plugins for Hardhat.</p>
<p>Now, let’s make a new directory <code>test</code> in the root directory and make a new file called <code>test.js</code> in it:</p>
<pre><code>mkdir test &amp;&amp; cd test &amp;&amp; touch test.js
</code></pre><p>Make sure you require <code>@nomiclabs/hardhat-ethers</code> in the <code>hardhat.config.js</code> to make it available everywhere:</p>
<pre><code><span class="hljs-built_in">require</span>(<span class="hljs-string">"@nomiclabs/hardhat-ethers"</span>);
</code></pre><p>Here is a simple test:</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> { expect } = <span class="hljs-built_in">require</span>(<span class="hljs-string">"chai"</span>);

describe(<span class="hljs-string">"MyCryptoLions"</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  it(<span class="hljs-string">"Should return the right name and symbol"</span>, <span class="hljs-keyword">async</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">const</span> MyCryptoLions = <span class="hljs-keyword">await</span> hre.ethers.getContractFactory(<span class="hljs-string">"MyCryptoLions"</span>);
    <span class="hljs-keyword">const</span> myCryptoLions = <span class="hljs-keyword">await</span> MyCryptoLions.deploy(<span class="hljs-string">"MyCryptoLions"</span>, <span class="hljs-string">"MCL"</span>);

    <span class="hljs-keyword">await</span> myCryptoLions.deployed();
    expect(<span class="hljs-keyword">await</span> myCryptoLions.name()).to.equal(<span class="hljs-string">"MyCryptoLions"</span>);
    expect(<span class="hljs-keyword">await</span> myCryptoLions.symbol()).to.equal(<span class="hljs-string">"MCL"</span>);
  });
});
</code></pre>
<p>This code deploys our contract to the local Hardhat network and then checks if the <code>name</code> and <code>symbol</code> values are what we expect.</p>
<p>Run the test:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/image-2.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Awesome, it passed the test!</p>
<h3 id="heading-how-to-use-consolelog-in-hardhat">How to Use console.log() in Hardhat</h3>
<p>Now here is the coolest thing you can do with Hardhat. You can use <code>console.log()</code> just like you do in JavaScript, which was not possible before. <code>console.log()</code> alone is more than enough reason to switch to Hardhat. </p>
<p>Let’s go back to your solidity file and use <code>console.log()</code>.</p>
<pre><code>pragma solidity ^<span class="hljs-number">0.7</span><span class="hljs-number">.3</span>;

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

contract MyCryptoLions is ERC721 {
    <span class="hljs-keyword">constructor</span>(string memory name, string memory symbol) ERC721(name, symbol) {
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"name"</span>, name);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"symbol"</span>, symbol);
        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"msg.sender"</span>, msg.sender); <span class="hljs-comment">//msg.sender is the address that initially deploys a contract</span>
    }
}
</code></pre><p>And run the test again with <code>npx hardhat test</code>. Then the command will compile the contract again, and then run the test. You should be able to see some values logged from the contract.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2021/05/image-3.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This makes debugging a lot easier for you.</p>
<p>One caveat is that it supports only these data types:</p>
<ul>
<li>uint</li>
<li>string</li>
<li>bool</li>
<li>address</li>
</ul>
<p>But other than that, you can use it as if you are writing JavaScript.</p>
<h2 id="heading-how-to-deploy-the-contract">How to Deploy the Contract</h2>
<p>All right! Now let’s deploy our contract. We can deploy our contract to one of the testing networks, the Mainnet, or even a mirrored version of the Mainnet in local. </p>
<p>But in this post, we will deploy to the local in-memory instance of the Hardhat Network to keep things simple. This network is run on startup by default.</p>
<p>Make a new directory called <code>scripts</code> in the root directory and <code>deploy.js</code> in it.</p>
<pre><code>mkdir scripts &amp;&amp; cd scripts &amp;&amp; touch deploy.js
</code></pre><p>Here is the deploy script. You deploy along with constructor values:</p>
<pre><code class="lang-js"><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> MyCryptoLions = <span class="hljs-keyword">await</span> hre.ethers.getContractFactory(<span class="hljs-string">"MyCryptoLions"</span>);
  <span class="hljs-keyword">const</span> myCryptoLions = <span class="hljs-keyword">await</span> MyCryptoLions.deploy(<span class="hljs-string">"MyCryptoLions"</span>, <span class="hljs-string">"MCL"</span>);

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

  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"MyCryptoLions deployed to:"</span>, myCryptoLions.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>You might want to remove <code>console.log()</code> before you deploy. And then run this deploy script with:</p>
<pre><code>npx hardhat run scripts/deploy.js
MyCryptoLions deployed to: <span class="hljs-number">0x5FbDB2315678afecb367f032d93F642f64180aa3</span>
</code></pre><p>Boom! Now your NFT contract is deployed to the local network. </p>
<p>You can target any network configured in the <code>hardhat.config.js</code> depending on your needs. You can find more about configuration <a target="_blank" href="https://hardhat.org/config/">here</a>.</p>
<h2 id="heading-wrapping-up">Wrapping Up</h2>
<p>Hardhat has some other cool features like helpful stack trace, support for multiple Solidity compiler versions, a robust Mainnet forking, great TypeScript support and contract verification in Etherescan. But that’s for another time!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What is a Dapp? A Guide to Ethereum Dapps ]]>
                </title>
                <description>
                    <![CDATA[ By Grant Bartel In the cryptoverse, a lot of attention is laid on Bitcoin. But don't let that overshadow the growing interest in Ethereum, which is revolutionizing the way we think of applications. So, what is a Dapp? A Dapp, or decentralized applica... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-a-dapp-a-guide-to-ethereum-dapps/</link>
                <guid isPermaLink="false">66d45edfd1ffc3d3eb89dddb</guid>
                
                    <category>
                        <![CDATA[ dapps ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Smart Contracts ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 13 May 2020 19:08:55 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2020/05/clifford-photography-hiFghSs4keM-unsplash.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Grant Bartel</p>
<p>In the cryptoverse, a lot of attention is laid on Bitcoin. But don't let that overshadow the growing interest in Ethereum, which is revolutionizing the way we think of applications.</p>
<p>So, what is a Dapp? <strong>A Dapp, or decentralized application, is a software application that runs on a distributed network. It's not hosted on a centralized server, but instead on a peer-to-peer decentralized network.</strong></p>
<p>Alright, that's the short version, but there's a lot more to unpack. Let's dive into the world of Dapps, more specifically those built on the Ethereum protocol.</p>
<h2 id="heading-what-is-ethereum">What is Ethereum?</h2>
<p>To understand what a Dapp is, you first need to understand what Ethereum is. Now, there are other protocols that are used to build Dapps, like EOS, NEO, Stellar, Tron, and Cardano, but the big dog is Ethereum.</p>
<p>Ethereum is a network protocol that allows users to create and run <strong>smart contracts</strong> over a decentralized network. A smart contract contains code that runs specific operations and interacts with other smart contracts, which has to be written by a developer. Unlike Bitcoin which stores a number, Ethereum stores executable code.</p>
<p>So, why should you care?</p>
<p>Because Ethereum removes the need for a third party to handle transactions between peers. Since the middle man is replaced by code, all kinds of costs are reduced, including time and money.</p>
<p><strong>Just like Bitcoin removes the need for someone to hold your money, Ethereum removes the need for someone to broker a deal.</strong></p>
<p>Now you might be wondering, where are all these smart contracts? Well, they're essentially hosted on multiple computer nodes all across the world. </p>
<p>These nodes contain all of the information of all the world's smart contracts, including code, transactions, etc. They're constantly working to keep this information up-to-date so they all have the exact same copy. This what makes smart contracts, and cryptocurrencies in general, decentralized.</p>
<p>And since all of the nodes have the same information and are spread across the world, the removal of a node won't interrupt the execution of any smart contract. Redundancy ensures uptime.</p>
<h2 id="heading-what-is-a-dapp">What is a Dapp?</h2>
<p>Now that we have a good idea of what Ethereum and smart contracts are, we can start diving into the details of what a Dapp is.</p>
<p>Just to be clear, a Dapp is just like any other software application you use. It could be a website or an app on your phone. What makes a Dapp different than a traditional app is that it's built on a decentralized network, like Ethereum.</p>
<p>When you're creating your own Ethereum smart contracts, you're actually writing a piece of the backend code for your Dapp. And while your Dapp will have a user interface like a traditional app, either all or part of the backend is built on top of Ethereum.</p>
<p><strong>Dapp = frontend + smart contract backend</strong></p>
<p>This backend code is written in an Ethereum-specific language, including Solidity (the most popular), Serpent, and Vyper. Below is an example of a simple "Hello World" contract written in Solidity.</p>
<pre><code>pragma solidity ^<span class="hljs-number">0.4</span><span class="hljs-number">.22</span>;

contract helloWorld {
 <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">printHelloWorld</span> (<span class="hljs-params"></span>) <span class="hljs-title">public</span> <span class="hljs-title">pure</span> <span class="hljs-title">returns</span> (<span class="hljs-params">string</span>) </span>{
   <span class="hljs-keyword">return</span> <span class="hljs-string">'Hello World!'</span>;
 }
}
</code></pre><p>If the smart contract is deployed onto Ethereum's mainnet (i.e., production) or even a local testnet, your Dapp can execute the code in the smart contract by calling the function <strong>printHelloWorld()</strong>.</p>
<p>But what about the frontend? Is there any specific language you need to use for your Dapp?</p>
<p>Nope! You can use whatever frontend language/framework you want. But it is possible to host your frontend code on decentralized storage nodes to make both your frontend and backend decentralized. </p>
<p>Take a look at technologies like <a target="_blank" href="https://ethereum.stackexchange.com/questions/375/what-is-swarm-and-what-is-it-used-for?noredirect=1&amp;lq=1">Swarm</a> and <a target="_blank" href="https://en.wikipedia.org/wiki/InterPlanetary_File_System">IPFS</a> to learn more about decentralized storage.</p>
<p>OK, so Dapps are just applications that have some or all of their backend decentralized and possibly even have a decentralized frontend. Why should you care?</p>
<p>The development of Dapps is another step toward a future of the Internet that's commonly referred to as Web 3.0.</p>
<h2 id="heading-ethereum-dapps-the-backbone-of-web-30">Ethereum Dapps: The Backbone of Web 3.0</h2>
<p>Since the creation of the Internet, the amount of information and human interaction has exploded. We're able to produce and consume information at near infinite levels.</p>
<p>Unfortunately, the ability to control this information has become heavily centralized over time. This includes information about your social life, health, finances, and much more. Those who control this information are the ultimate owners of it and can use it as they see fit.</p>
<p>These are essentially middle men that hold your information on their centralized servers so they can provide you with services, like holding your money, hosting you website, connecting with family and friends, etc. And at the push of a button, they can completely remove you from accessing this (your?) information and all related services.</p>
<p>This is a monopoly on the information you produce and consume as well as the services you use. Thankfully, Web 3.0 changes all of that and Ethereum Dapps are playing a central role.</p>
<p>Web 3.0 is a lot of things, but at its core is a technology based on decentralization. By decentralizing information and services, large corporations and governments won't be able to control users of the Internet through monopolistic, authoritarian tactics.</p>
<p>Ethereum Dapps, with their ability to decentralize information and services, gives Web 3.0 a platform to deliver a completely free (as in freedom) and accessible Internet for everyone. No longer will there be a central point of control because there won't be middle men to facilitate the flow of information and services.</p>
<p>Some of the most promising Ethereum tokens and Dapps are laying the foundation for the future of the Internet, including:</p>
<ul>
<li><a target="_blank" href="https://basicattentiontoken.org/">Basic Attention Token</a> (BAT): used to improve privacy and value transfer between users, publishers, and advertisers. Used in the <a target="_blank" href="https://brave.com/">Brave browser</a>.</li>
<li><a target="_blank" href="https://golem.network/">Golem</a> (GNT): used to run code on one or many distributed compute nodes.</li>
<li><a target="_blank" href="https://www.minds.com/">Minds</a>: a social media platform that improves value transfer between content creators and consumers.</li>
<li><a target="_blank" href="https://www.tokensets.com/">TokenSets</a>: used to manage cryptocurrency assets via tokenized automated asset management strategies.</li>
<li><a target="_blank" href="https://aave.com/">Aave</a>: used to earn interest on cryptocurrency deposits and borrow cryptocurrency assets.</li>
<li><a target="_blank" href="https://idex.market/">IDEX</a>: a decentralized cryptocurrency exchange.</li>
</ul>
<h2 id="heading-closing-thoughts">Closing Thoughts</h2>
<p>Since the creation of Bitcoin, the first cryptocurrency, there's been a massive growth in the cryptoverse. </p>
<p>Being able to store data in a decentralized way was a necessary stepping stone to the decentralization of code execution. With Ethereum, it's now possible to deploy smart contracts across the world to power the backend for existing and future Dapps. </p>
<p>And as more and more Dapps are launched, we'll get closer and closer to a more free, fair, and accessible Internet.</p>
<p><em>I’m Grant and I’m a freelance SEO and content professional. If you’re looking to grow your brand's organic search traffic, I can help with your <a target="_blank" href="https://www.writefintech.com/">fintech SEO</a>. Cheers!</em>  </p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ What Is Blockchain Technology? Blockchain Definition Explained ]]>
                </title>
                <description>
                    <![CDATA[ Features of Blockchain Technology Blockchain is almost always used instead of the terms Bitcoin and cryptocurrency. And there are many other places this technology can be used. We are beginning to barely scratch the surface of it.  With all the hype ... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/what-is-blockchain-technology-blockchain-definition-explained/</link>
                <guid isPermaLink="false">66c365a2693ce41cd86e7993</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ toothbrush ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Sun, 26 Jan 2020 22:09:00 +0000</pubDate>
                <media:content url="https://cdn-media-2.freecodecamp.org/w1280/5f9c9d78740569d1a4ca37ed.jpg" medium="image" />
                <content:encoded>
                    <![CDATA[ <h2 id="heading-features-of-blockchain-technology"><strong>Features of Blockchain Technology</strong></h2>
<p>Blockchain is almost always used instead of the terms Bitcoin and cryptocurrency. And there are many other places this technology can be used. We are beginning to barely scratch the surface of it. </p>
<p>With all the hype around it, we know that the Blockchain Technology (BlockTech) is going to be huge. But what makes it unique?</p>
<p>In this article, we are going to explore the key characteristic features of BlockTech.</p>
<h2 id="heading-decentralized-system">Decentralized System</h2>
<p>Blockchain is a Decentralized Technology, by design.</p>
<p>When something is controlled by a central authority, where the power to make decision lies in the hands of the apex of the management, such system is called a Centralized System. Banks, for example, are a centralized system, where it’s the responsibility of the Governor to make decisions.</p>
<p>On the contrary, when the power is vested in the hands of the people or the users, such system is said to be a Decentralized System. The peer to peer network, Torrent, for example is a decentralised system, where the user has complete control.</p>
<p><img src="https://raw.githubusercontent.com/Vagisha16/Hw3/master/blockchain_article_pic.jpg" alt="Decentralized Systems" width="600" height="400" loading="lazy"></p>
<h2 id="heading-distributed-ledger">Distributed Ledger</h2>
<p>Blockchains use distributed Ledger Technology (DLT) to store and access the data around.</p>
<p>When something is stored on a Distributed Ledger, multiple copies of it are made across the network at the same time. Unlike traditional databases, distributed ledger do not have a central database or administration functionality.</p>
<p><img src="https://qph.fs.quoracdn.net/main-qimg-2e24c4949a63eefa9bbab1773e185cdd" alt="Distributed Ledger" width="602" height="316" loading="lazy"></p>
<p>When applied in a decentralized system like Blockchain, each user has a copy of the ledger and participates in the transaction verification. This gives Blockchain the property of Immutability and ensures security. Since, the data is distributed, there is no centralized version of the data for the hackers to corrupt. The data and the records are public and easily verifiable. This also eliminates single point of Failure.</p>
<h2 id="heading-secure-ecosystem-cryptographic-hash">Secure Ecosystem (Cryptographic Hash)</h2>
<p>BlockTech uses the concepts like Proof of Work and Hash encryption to ensure security and immutability. Proof of work involves several people around the world using computational algorithm to try and find the appropriate hash value that satisfies a predefined condition regarding the hash value.</p>
<p><img src="https://raw.githubusercontent.com/Vagisha16/Hw3/master/Hash.png" alt="Hashing" width="600" height="400" loading="lazy"></p>
<p><img src="https://qph.fs.quoracdn.net/main-qimg-098a67b40e4d0f625cf2cbbda2c95df0" alt="Proof of Work" width="602" height="303" loading="lazy"></p>
<h2 id="heading-mining">Mining</h2>
<p>Torrent is a peer-to-peer decentralised network used to share files. BlockTech uses similar technology. What differentiates the users is that, in Torrent, the system relies on the honor code of the users to seed the files. Whereas, in blockchain, the users who are involved in the transaction have economic incentives. These users are called “Miners.” The Miners spend their computing resources to solve the cryptographic hashes and ensure immutability and reliability of the transaction. Every successful solution (decryption) ensures some economic benefit.</p>
<p><img src="https://raw.githubusercontent.com/Vagisha16/Hw3/master/5f6609014470f4b0122de37eb09dbfc7.jpg" alt="Mining" width="600" height="400" loading="lazy"></p>
<h2 id="heading-chronological-and-time-stamped">Chronological and Time stamped</h2>
<p>Blockchains, ideally, are just very sophisticated linked lists where each block is a repository that stores information pertaining to a transaction and also links to the previous block in the same transaction. These blocks are arranged in an order and are time-stamped during creation to ensure a fair record.</p>
<h2 id="heading-consensus-based">Consensus Based</h2>
<p>Consensus Based is an approach to decision making. It is a creative and dynamic way of reaching agreement between all members of a group. A transaction on Blockchain can be executed only if all the parties on the network unanimously approve it. It is however, subjected to alterations to suit various circumstances.</p>
<h3 id="heading-more-info-about-blockchain">More info about Blockchain:</h3>
<ul>
<li><a target="_blank" href="https://www.freecodecamp.org/news/what-is-blockchain-and-how-does-it-work/">What is the Blockchain and how does it work?</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/technical-primer-to-blockchain-ethereum/">Technical primer to Blockchain and Ethereum</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/learn-the-solidity-programming-language/">Learn the Solidity programming language in 2 hours</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/blockchain-app-etherium-solidity/">Build your first blockchain app with this free course</a></li>
<li><a target="_blank" href="https://www.freecodecamp.org/news/the-most-popular-programming-languages-used-in-blockchain-development-5133a0a207dc/">The most popular programming languages for blockchain development</a></li>
</ul>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ Learn how to build Ethereum Dapp and develop for the blockchain ]]>
                </title>
                <description>
                    <![CDATA[ Learn Ethereum Dapp in this full video course for beginners from EatTheBlocks. This course teaches how to build decentralized applications on the Ethereum Blockchain.  You'll learn how to build 5 Ethereum Dapps. For each of them, this course demonstr... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/learn-how-to-build-ethereum-dapp-and-develop-for-the-blockchain/</link>
                <guid isPermaLink="false">66b2046d712508eb16067882</guid>
                
                    <category>
                        <![CDATA[ dapps ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ youtube ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Beau Carnes ]]>
                </dc:creator>
                <pubDate>Mon, 07 Oct 2019 16:04:32 +0000</pubDate>
                <media:content url="https://www.freecodecamp.org/news/content/images/2019/10/ethereumdapps.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Learn Ethereum Dapp in this full video course for beginners from EatTheBlocks. This course teaches how to build decentralized applications on the Ethereum Blockchain. </p>
<p>You'll learn how to build 5 Ethereum Dapps. For each of them, this course demonstrates how to:</p>
<ul>
<li>develop smart contracts,</li>
<li>test smart contracts,</li>
<li>and build a web frontend to interact with the smart contract.</li>
</ul>
<p>The course covers:</p>
<ul>
<li>The architecture of Dapps</li>
<li>Solidity, the programming language for Ethereum smart contract</li>
<li>Remix, the online IDE for Solidity</li>
<li>Truffle, the framework for Solidity smart contracts</li>
<li>Ganache, the local development Blockchain</li>
<li>Web3, the JS library to integrate a Dapp frontend</li>
<li>Metamask, the Ethereum wallet used by most Dapps (browser extension)</li>
<li>Deployment to public testnet (Ropsten) and mainnet, using Infura API</li>
</ul>
<p>Watch the full course below or on the <a target="_blank" href="https://www.youtube.com/watch?v=8wMKq7HvbKw">freeCodeCamp YouTube channel</a> (5 hour watch).</p>
<div class="embed-wrapper">
        <iframe width="560" height="315" src="https://www.youtube.com/embed/8wMKq7HvbKw" style="aspect-ratio: 16 / 9; width: 100%; height: auto;" title="YouTube video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" loading="lazy"></iframe></div>
 ]]>
                </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[ Decentralized Applications Architecture: Back End, Security and Design Patterns ]]>
                </title>
                <description>
                    <![CDATA[ Decentralized applications, or ÐApps, require a special system design to achieve high security and reliability. In this article I am going to cover several main principles of how to properly design and implement back end and smart contracts for decen... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-design-a-secure-backend-for-your-decentralized-application-9541b5d8bddb/</link>
                <guid isPermaLink="false">66b99b76c39234149cf0113c</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ crypto ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Security ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Nikita Savchenko ]]>
                </dc:creator>
                <pubDate>Tue, 02 Apr 2019 15:51:44 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*sd62aH6GGS1RoCR9t4QNyQ.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p><a target="_blank" href="https://en.wikipedia.org/wiki/Decentralized_application">Decentralized applications</a>, or ÐApps, require a special system design to achieve high security and reliability. In this article I am going to cover several main principles of how to properly design and implement back end and smart contracts for decentralized applications, taking <a target="_blank" href="https://www.ethereum.org/">Ethereum</a> as a primary example, though much of it would apply to <a target="_blank" href="https://eos.io/">EOS</a>, <a target="_blank" href="https://tron.network/">Tron</a> and other decentralized data platforms.</p>
<p><strong>Article Highlights</strong>:</p>
<ul>
<li>How to store private keys on the back end without security concerns</li>
<li>How to properly design smart contracts and what to “decentralize”</li>
<li>Decentralized and semi-centralized applications architecture examples</li>
<li>How to deal with low-level stuff like network load and failures</li>
</ul>
<p>It’s going to be big, let’s do it!</p>
<h3 id="heading-decentralized-programs-and-blockchain">Decentralized Programs and Blockchain</h3>
<p>Despite the fact that blockchain is facing a lot of adoption and regulation difficulties today, it’s a kind of technology which is here to stay, whether it’s blockchain, <a target="_blank" href="https://en.wikipedia.org/wiki/Hashgraph">hashgraph</a>, <a target="_blank" href="https://www.radixdlt.com/">tempo</a> or any other distributed ledger technology still to come, regardless of the algorithm.</p>
<blockquote>
<p>The main value that blockchain and other similar technologies bring can be generalized as follows: they allow people to write and run programs which, practically, cannot be changed after creation nor tampered with during execution. In other words, these programs always run as designed, and no single party can influence their behavior.</p>
</blockquote>
<p>This definition is valid for <em>many</em> cryptocurrencies that exist today if we consider them as programs that define how coins can be transferred back and forth. This also explains why cryptocurrencies and many kinds of tokens have real value: they cannot be generated out of thin air, by their defined “underlying programs”.</p>
<p>Ethereum/EOS/Tron/… platforms, in contrast to Bitcoin, implement a more complex program layer, which in turn implements the execution environment allowing anyone to write their own decentralized programs on top of the platform. This user-defined programs always run as designed, without any exceptions, and their security is guaranteed by the platform.</p>
<h3 id="heading-decentralized-applications">Decentralized Applications</h3>
<p>These secure and unchangeable programs running on a decentralized network in combination with traditional front-end and back-end technologies are what we call <strong>decentralized applications</strong> (ÐApps) today. Through some of them can be semi-centralized, a major part of activities in the truly decentralized application should happen out of a central party’s control.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/a0d9mC2p5qPHjMfIXw8Oq0XHCy9CQdLOAWmG" alt="Image" width="800" height="682" loading="lazy">
<em>If someone asked me to draw how DApps work today, I would probably have drawn this</em></p>
<p>To imagine what we call decentralized applications today, take any existing centralized web resource like <a target="_blank" href="https://www.youtube.com/c/NikitaSavchenko"><em>YouTube</em></a> or <a target="_blank" href="https://instagram.com/nikitaeverywhere/"><em>Instagram</em></a> as an example and imagine that instead of a password-protected centralized account you have your “<strong>crypto identity</strong>” bound to the web/mobile resource.</p>
<p>That’s what <a target="_blank" href="https://metamask.io/">Wallet Software</a> provides you. The <a target="_blank" href="https://en.wikipedia.org/wiki/Public-key_cryptography">private key</a> from this identity (a secret, having which, you can act on behalf of this identity) is stored on your local device and never goes online, making no one able to control this identity but you. With this identity, you can perform different actions in both <em>centralized</em> (web resource controlled by a central authority) and <em>decentralized</em> (which is a different network from the traditional www, the goal of which is to eliminate the central authority) <em>networks</em>, using the website as an access point and/or as a graphical user interface. The whole point of this “crypto identity” is that your actions are cryptographically secured, and no one is able to change what have you signed nor your signature.</p>
<p>Today, the computational and storage capabilities of fault-tolerant decentralized networks like <a target="_blank" href="https://www.ethereum.org/">Ethereum</a>, <a target="_blank" href="https://eos.io/">EOS</a> or <a target="_blank" href="https://tron.network/">Tron</a> are limited. If they were scalable, we could use decentralized networks to store the whole decentralized application, including its graphical user interface, data and business logic. In this case, we would call these applications truly decentralized/distributed.</p>
<p>However, because those networks are not scalable today, we combine different approaches to achieve the maximum decentralization level for our applications. The “traditional” back end as we know it isn’t going anywhere. For instance:</p>
<ul>
<li>We use back end to host front end for a decentralized application.</li>
<li>We use back end for integrations with any other existing technologies and services. Real, world-class applications cannot live in an isolated environment.</li>
<li>We use back end to store and process anything big enough for a decentralized network (blockchain in particular). Practically, the whole application and its business logic are stored somewhere in the world, excluding the blockchain part only. Not to mention, <a target="_blank" href="https://ipfs.io/">IPFS</a> and similar storage layers <a target="_blank" href="https://github.com/ipfs/faq/issues/93">cannot guarantee</a> the accessibility of files, hence we cannot rely on them without hosting the files ourselves either. In other words, there’s always a need for a dedicated running server.</li>
</ul>
<p>There’s no way of building a secure and partially decentralized application without using a solid back end as of today, and the whole point of this article is to explain how to do this right.</p>
<h3 id="heading-decentralization-and-tokens">(De)centralization and Tokens</h3>
<p>It so happens that almost all decentralized applications today are built around so-called <a target="_blank" href="https://coinmarketcap.com/tokens/">tokens</a> — custom-built (or just simply cloned) cryptocurrencies that drive a particular decentralized application. Tokens are simply a programmable currency or assets, that’s it.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/b-Ok08iucXB0n6VwiLcPzbW8BAWfTe7YRBxD" alt="Image" width="800" height="589" loading="lazy">
<em>While token smart contracts determine how users can transfer tokens, application smart contracts can extend everything missing in token smart contracts. Both smart contracts run on top of decentralized networks</em></p>
<p>Usually, a token is a “smart contract” (a custom program) written on top of the decentralized platform like Ethereum. By owning some tokens you are basically able to get different services on a web resource or mobile app, and trade this token for something else. The key point here is that the token lives on its own and it is not controlled by a central authority.</p>
<blockquote>
<p>There are many examples of applications that are build around tokens: from numerous collectible games like <a target="_blank" href="https://www.cryptokitties.co/">CryptoKitties</a> (ERC721 tokens) to more service-oriented apps like <a target="_blank" href="https://loomx.io/purchase/">LOOM Network</a>, or even browsers like <a target="_blank" href="https://brave.com/download">Brave</a> and gaming platforms like <a target="_blank" href="https://dreamteam.gg/">DreamTeam</a> (ERC20-compatible tokens).</p>
</blockquote>
<p>Developers themselves determine and decide how much control they will (or won’t) have over their applications. They can build the whole application’s business logic on top of smart contracts (like <a target="_blank" href="https://www.cryptokitties.co/">CryptoKitties</a> did), or, they can make no use of smart contracts at all, centralizing everything on their servers. However, the best approach is somewhere in the middle.</p>
<h3 id="heading-back-end-for-decentralized-networks">Back End for Decentralized Networks</h3>
<p>From a technical point of view, there has to be a bridge that connects tokens and other smart contracts with the web/mobile application.</p>
<p>In today’s fully decentralized applications, where clients interact with smart contracts directly, this bridge is narrowed down to a <a target="_blank" href="https://github.com/ethereum/wiki/wiki/JSON-RPC">JSON RPC API</a> capabilities of <a target="_blank" href="https://infura.io">public APIs or node pools like Infura</a>, which in turn are forced to exist because of the fact that not every device can run and support its individual network node. However, this API provides an only basic and very narrow set of functions, which barely allow making simple queries nor efficiently aggregate data. Because of this, eventually, custom back end kicks in, making the application semi-centralized.</p>
<p>The whole interaction with the decentralized network can be narrowed down to just one or two points, depending on the application needs:</p>
<ol>
<li><strong>Listening to the network events</strong> (like token transfers) / <strong>reading the network state</strong>.</li>
<li><strong>Publishing transactions</strong> (invoking state-changing smart contract functions like token transfer).</li>
</ol>
<p>Implementing both of these points is quite tricky, especially if we want to build a secure and reliable back-end solution. Here are the main points which we are going to break down below:</p>
<ul>
<li>First of all, in Ethereum, events retrieval is not production-ready out of the box. Because of multiple reasons: network nodes can fail while fetching a large number of events, events can disappear or change because of network forks, etc. We have to build an abstraction layer to sync events from the network and guarantee their reliable delivery.</li>
<li>The same for transaction publishing, we have to abstract Ethereum’s low-level stuff like nonce counters and gas estimations, as well as transaction republishing, providing a reliable and stable interface. Moreover, transaction publishing implies using private keys, which requires advanced back-end security.</li>
<li>Security. We are going to take it seriously and face that it’s impossible to guarantee that private keys won’t ever be compromised on a back end. Luckily, there is an approach to designing a decentralized application without even <strong>a need</strong> for back-end accounts to be highly secured.</li>
</ul>
<p>In our practice, all of this made <a target="_blank" href="https://dreamteam.gg/">us</a> create a robust back-end solution for Ethereum which we name <strong>Ethereum Gateway</strong>. It abstracts other microservices from Ethereum’s fun and provides a reliable API to work with it.</p>
<p>As a <a target="_blank" href="https://dreamteam.gg/">fast-growing startup</a>, we cannot disclose the complete solution (just yet) for obvious reasons, but I am going to share everything that you need to know to make your decentralized application work flawlessly. However, if you have any specific questions or inquiries, feel free to contact <a target="_blank" href="https://nikita.tk/">me</a>. Comments to this article are much appreciated as well!</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/aR03aGoFHc3EZ5ZCBVBPn6gqQEYYWFArNVy0" alt="Image" width="800" height="519" loading="lazy">
_Back End Monitoring for Ethereum. The monitor demonstrates activities mainly regarding our [recurring billing feature](https://github.com/dreamteam-gg/smart-contracts/blob/master/contracts/token/TokenRecurringBilling.md" rel="noopener" target="<em>blank" title=") (though you can see peaks happening each hour).</em></p>
<h3 id="heading-decentralized-applications-architecture">Decentralized Applications Architecture</h3>
<p>This part of the article highly depends on the needs of a particular decentralized application, but we will try to sort out some basic interaction patterns on top of which these applications are built (ÐPlatform = Decentralized Platform = Ethereum/EOS/Tron/Whatever):</p>
<h4 id="heading-client-dplatform-fully-decentralized-applications"><strong>Client ⬌ ÐPlatform</strong>: <strong><em>fully decentralized applications</em></strong>.</h4>
<p>The client (browser or mobile application) talks to the decentralized platform directly with the help of Ethereum “wallet” software like <a target="_blank" href="https://metamask.io">Metamask</a>, <a target="_blank" href="https://trustwallet.com/">Trust</a> or hardware wallets like <a target="_blank" href="https://trezor.io/">Trezor</a> or <a target="_blank" href="https://www.ledger.com/">Ledger</a>. Examples of DApps build in such manner are <a target="_blank" href="https://www.cryptokitties.co/">CryptoKitties</a>, <a target="_blank" href="https://loomx.io/">Loom’s</a> <a target="_blank" href="https://delegatecall.com/">Delegated Call</a>, crypto wallets themselves (<a target="_blank" href="https://metamask.io/">Metamask</a>, <a target="_blank" href="https://trustwallet.com/">Trust</a>, <a target="_blank" href="https://tron.network/wallet?lng=en">Tron Wallet</a>, others), decentralized crypto exchanges like <a target="_blank" href="http://etherdelta.com">Etherdelta</a> and so on.</p>
<h4 id="heading-dplatform-client-back-end-dplatform-centralized-or-semi-centralized-applications"><strong>ÐPlatform</strong> ⬌ <strong>Client</strong> ⬌ <strong>Back End</strong> ⬌ <strong>ÐPlatform</strong>: <strong><em>centralized or semi-centralized applications</em></strong>.</h4>
<p>The client interaction with the decentralized platform and the server has little in common. The good example of this is any (<strong><em>centralized</em></strong>) crypto exchange today, like <a target="_blank" href="https://www.bitfinex.com/">BitFinex</a> or <a target="_blank" href="https://poloniex.com">Poloniex</a>: the currencies you trade on exchanges are simply recorded in the traditional database. You can “top up” your database balance by sending assets to a specific address (ÐPlatform ⬌ Client) and then withdraw assets after some actions in the app (Back End ⬌ ÐPlatform), however, everything you do in terms of a “ÐApp” itself (Client ⬌ Back End) does not imply your direct interaction with the ÐPlatform.</p>
<p>Another example is <a target="_blank" href="https://etherscan.io/">Etherscan.io</a>, which uses <strong><em>semi-centralized</em></strong> approach: you can do all useful decentralized actions there, but the application itself just doesn’t make sense without their comprehensive back end (Etherscan continuously syncs transactions, parses data and stores it, ultimately providing a comprehensive API/UI).</p>
<h4 id="heading-something-in-between-still-centralized-or-semi-centralized-applications"><strong>Something in between: <em>still,</em> <em>centralized or semi-centralized applications</em>.</strong></h4>
<p>The above approaches combined. For example, we can have an application which provides various services in exchange for crypto, allowing you to log in and sign information with your crypto identity.</p>
<p>Hopefully, the interaction pattern of fully decentralized applications (Client ⬌ ÐPlatform) does not raise any questions. By relying on such amazing services like <a target="_blank" href="https://infura.io/">Infura</a> or <a target="_blank" href="https://www.trongrid.io/">Trongrid</a> one can simply build an application which doesn’t require a server at all. Almost all client-side libraries like <a target="_blank" href="https://github.com/ethers-io/ethers.js/">Ethers.js</a> for Ethereum or <a target="_blank" href="https://github.com/tronprotocol/tron-web">Tron-Web</a> for Tron can connect to these public services and communicate with the network. However, for more complex queries and tasks, you may need to allocate your own server anyway.</p>
<p>The rest of the interaction patterns which involve back end make things more interesting and complex. To put all these in a picture, let’s imagine a case where our back end reacts to some event in the network. For example, the user publishes an allowance transaction which gives us permission to charge them. To make a charge, we have to publish the charge transaction in response to the emitted allowance event:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/86mjnQ0gwUrAbrBL4t8LFCXbC4HyckEsmFYQ" alt="Image" width="800" height="612" loading="lazy">
<em>An example flow of server’s reaction to the user’s action in the decentralized network</em></p>
<p>From the back end point of view here’s what happens:</p>
<ol>
<li>We listen to a particular network event by continuously polling the network.</li>
<li>Once we get an event, we perform some business logic and then decide to publish a transaction in response.</li>
<li>Prior to publishing the transaction, we want to ensure that it will likely be mined (in Ethereum, the successful transaction gas estimation means there are no errors against the <em>current network state</em>). However, we can’t guarantee that the transaction will be mined <em>successfully</em>.</li>
<li>Using a private key, we sign and publish the transaction. In Ethereum we also have to determine the gas price and gas limit of the transaction.</li>
<li>After publishing the transaction, we continuously poll the network for its status.</li>
<li>If it takes too long and we can’t get the status of the transaction, we have to re-publish it or trigger a “fail scenario”. Transactions can be lost for various reasons: network congestion, dropping peers, network load increase, etc. In Ethereum, you can also consider re-signing a transaction with a different (actual) gas price.</li>
<li>After we finally get our transaction mined, we can perform more business logic if needed. For example, we can notify other back end services about the fact of the transaction being completed. Also, consider waiting for a couple of confirmations prior to making final decisions regarding the transaction: the network is distributed and hence the result can change in a matter of seconds.</li>
</ol>
<p>As you can see, there’s a lot going on! However, your application may not require some of these steps, depending on what you are trying to achieve. But, building a robust and stable back end requires having a solution for all the problems mentioned above. Let’s break this down.</p>
<h3 id="heading-decentralized-applications-back-end">Decentralized Applications Back End</h3>
<p>Here I want to highlight some of the points which arise most of the questions, namely:</p>
<ul>
<li>Listening to network events and reading data from the network</li>
<li>Publishing transactions &amp; how to do it securely</li>
</ul>
<h4 id="heading-listening-to-network-events">Listening to Network Events</h4>
<p>In Ethereum, as well as in other decentralized networks, a concept of smart contract <a target="_blank" href="https://media.consensys.net/technical-introduction-to-events-and-logs-in-ethereum-a074d65dd61e">events (or event logs, or just logs)</a> allows off-chain applications to be aware of what is happening in the blockchain. These events can be created by smart contract developers at any point of the smart contract code.</p>
<p>For example, within the well-known <a target="_blank" href="https://en.wikipedia.org/wiki/ERC-20">ERC20</a> token standard each token transfer <a target="_blank" href="https://etherscan.io/tx/0xe7186ec76b164e44212dda60fdace62bef67cf7dc017d2e6318d517daa9b01c9#eventlog">has to log the Transfer event</a>, thus letting off-chain applications know that there is a token transfer happened. By “listening” to these events we can perform any (re)actions. For instance, some mobile crypto-wallets send you a push/email notification when tokens are transferred to your address.</p>
<p>In fact, there’s no reliable solution for listening to network events out of the box. Different libraries allow you to track/listen to events, however, there are many cases when something can go wrong, resulting in lost or unprocessed events. To avoid losing events, we have to build a custom back end, which will maintain the events sync process.</p>
<p>Depending on your needs, the implementation can vary. But to put you in a picture here is one of the options of how can you build reliable Ethereum events delivery in terms of microservice architecture:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1I5pP5C6HTNGeXpSNO1TpQeFDvxRZnDzZDnt" alt="Image" width="800" height="366" loading="lazy">
<em>Reliable delivery of Ethereum events to all back end services</em></p>
<p>These components work in the following way:</p>
<ol>
<li>Events sync back end service constantly polls the network, trying to retrieve new events. Once there are some new events available, it sends these events to the message bus. Upon successful event submission to the message bus, as for blockchain, we can save the last event’s block in order to request new events from this block next time. Keep in mind that retrieving too many events at once may result in always failing requests, so you have to limit the number of events/blocks you request from the network.</li>
<li>The message bus (for example, <a target="_blank" href="https://www.rabbitmq.com/">Rabbit MQ</a>) routes the event to every queue which was set up individually for each back end service. Prior to event publishing, events sync back end service specifies the routing key (for example, a smart contract address + event <a target="_blank" href="https://codeburst.io/deep-dive-into-ethereum-logs-a8d2047c7371">topic</a>), while consumers (other back end services) create queues which are subscribed for particular events only.</li>
</ol>
<p>As a result, each back end service gets only those events it needs. Moreover, the message bus guarantees the delivery of all events once they are published to it.</p>
<p>Of course, you can use something else instead of the message bus: HTTP callbacks, sockets, etc. In this case, you’ll need to figure out how to guarantee callbacks delivery yourself: manage exponential/custom callback retries, implement custom monitoring and so on.</p>
<h4 id="heading-publishing-transactions"><strong>Publishing Transactions</strong></h4>
<p>There are a couple of steps we have to perform in order to publish a transaction to the decentralized network:</p>
<ol>
<li>Preparing the transaction. Along with transaction data, this step implies requesting the network state in order to find out whether this transaction is valid and is going to be mined (gas estimation in Ethereum) and the transaction’s sequential number (nonce in Ethereum). Some of the libraries <a target="_blank" href="https://github.com/ethers-io/ethers.js/issues/331">try to do this under the hood</a>, however, these steps are important.</li>
<li>Signing the transaction. This step implies the usage of the private key. Most likely, here you’ll want to embed the custom private key assembly solution (<a target="_blank" href="https://github.com/immutability-io/vault-ethereum">for instance</a>).</li>
<li>Publishing and <em>republishing</em> the transaction. One of the key points here is that your published transaction always has a chance to get lost or dropped from the decentralized network. For example, in Ethereum, the published transaction can be dropped if the network’s <a target="_blank" href="https://ethgasstation.info/">gas price</a> suddenly increases. In this case, you have to republish the transaction. Moreover, you may want to republish the transaction with other parameters (at least with higher gas price) in order to get it mined as soon as possible. Thus, republishing the transaction can imply re-signing it, if the replacement transaction wasn’t pre-signed before (with different parameters).</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/ZFZYOVlaW-CDPFpzwutxZTCVdeM4ifLqpsK8" alt="Image" width="800" height="532" loading="lazy">
<em>The above points regarding Ethereum transaction publishing visualized</em></p>
<p>By utilizing the above approaches you can end up building something similar to the thing which is presented in the sequence diagram below. On this particular sequence diagram, I demonstrate (in general!) how the <a target="_blank" href="https://hackernoon.com/payments-of-tomorrow-decentralized-recurring-billing-47d126d895fd">blockchain recurring billing</a> works (there’s more in a linked article):</p>
<ol>
<li>The user executes a function in a smart contract, which ultimately allows the back end to perform a successful charge transaction.</li>
<li>A back end service responsible for a particular task listens to the event of charge allowance and publishes a charge transaction.</li>
<li>Once the charge transaction is mined, this back end service responsible for a particular task receives an event from the Ethereum network and performs some logic (including setting the next charge date).</li>
</ol>
<p><img src="https://cdn-media-1.freecodecamp.org/images/oNsxhuB9bVacGDh7pJyMjjk25gyipzS70lJg" alt="Image" width="800" height="564" loading="lazy">
_The general sequence diagram of how [blockchain recurring billing](https://hackernoon.com/payments-of-tomorrow-decentralized-recurring-billing-47d126d895fd" rel="noopener" target="<em>blank" title=") works, demonstrating the interaction between back-end services and Ethereum network</em></p>
<h3 id="heading-back-end-security-amp-smart-contracts">Back End Security &amp; Smart Contracts</h3>
<p>Transaction publishing always involves using a <strong>private key</strong>. You may be wondering if it is possible to keep private keys secure. Well, yes and no. <a target="_blank" href="https://en.wikipedia.org/wiki/Threshold_cryptosystem">There are</a> <a target="_blank" href="https://medium.com/gemini/cold-storage-keys-crypto-how-gemini-keeps-assets-safe-a732addcd13b">numerous</a> <a target="_blank" href="https://www.coinbase.com/security">complex</a> <a target="_blank" href="https://github.com/immutability-io/vault-ethereum">strategies</a> and <a target="_blank" href="https://www.vaultproject.io/">different types of software</a> which allow storing private keys on the back end quite securely. Some private key storage solutions use geo-distributed databases, while others even suggest the use of special hardware. However, in any case, the most vulnerable point of a semi-centralized application is where the private key is assembled and used to sign a transaction (or, in case of special hardware, a point of triggering a transaction signing procedure). Hence, theoretically, there’s no 100% reliable solution which will enable bullet-proof protection from compromising stored private keys.</p>
<p>Now think this way. In many cases, you don’t even need to secure private keys on the back end that often. Instead, <strong>you can design smart contracts and the whole application in such a manner that a private key leak won’t affect their usual behavior</strong>. With this approach, it doesn’t matter how authorized accounts interact with the smart contract. They’re just “triggering” a smart contract to do its usual job, and the smart contract itself performs any required validation. I call it the “operational accounts pattern”.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/Vl3V0DAGGdqi07BnffXkqRsl-0YROdAkgCG6" alt="Image" width="800" height="366" loading="lazy">
<em>Operational accounts pattern for decentralized applications, where you don’t need military-grade security for your back-end accounts</em></p>
<p>This way, in case of emergency:</p>
<ul>
<li>The only thing the attacker can steal is a tiny amount of Ether (as of Ethereum) deposited to the operational accounts for transaction publishing</li>
<li>The attacker won’t be able to harm the smart contract logic nor anyone who is involved in the process</li>
<li>Compromised operational accounts can be quickly replaced with other ones, however, this requires either the manual replacement (generating new accounts, and reauthorizing accounts in all smart contracts) or developing an additional solution which will do all the magic with a single transaction from a super-secure (hardware or <a target="_blank" href="https://medium.com/@yenthanh/list-of-multisig-wallet-smart-contracts-on-ethereum-3824d528b95e">multi-sig</a>) master account.</li>
</ul>
<p>For instance, in our <a target="_blank" href="https://hackernoon.com/payments-of-tomorrow-decentralized-recurring-billing-47d126d895fd">recurring billing for Ethereum</a> solution, no matter what happens on a back end, the recurring billing smart contract is designed in such a manner that we have a whole month of time for replacing the compromised accounts if any of them are compromised.</p>
<p>But still, if you want to get your back end private key storage as secure as possible, you can try using <a target="_blank" href="https://www.vaultproject.io/">Vault</a> with a <a target="_blank" href="https://github.com/dreamteam-gg">great plugin for Ethereum</a> which stores and manages Ethereum accounts (also, keep an eye on our <a target="_blank" href="https://github.com/dreamteam-gg">open-source modules</a> — we are about to release something similar soon). I am not going to dive deep into the details here, though you can visit the linked projects and learn from there yourself.</p>
<p>This isn’t even all I have to say. However, this article turned out to be much longer than I expected so I have to stop. Subscribe to my <a target="_blank" href="https://medium.com/@zitro">Medium</a> / <a target="_blank" href="https://nikita.tk/">other networks</a> if you’re interested in software, crypto, <a target="_blank" href="https://instagram.com/nikitaeverywhere/">travel tips</a> or just want to follow something interesting. Hope I’ve provided a big valuable piece of information and you’ll find it useful. Feel free to comment and spread this article!</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to run GETH from a Docker container ]]>
                </title>
                <description>
                    <![CDATA[ By Vince Tabora Installing the Ethereum node client on a machine can be a tedious process. There is a simpler way this can be done using a Docker client. This is a guide for running the GETH (Ethereum-Go) node client from inside a Docker container. G... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-run-geth-from-a-docker-container-b6d30620ca74/</link>
                <guid isPermaLink="false">66c35437b1d4339762339fb5</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Docker ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ software ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Wed, 27 Mar 2019 18:56:55 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*QZk8YSNM8shw4Trn8YtvAA.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Vince Tabora</p>
<p>Installing the Ethereum node client on a machine can be a tedious process. There is a simpler way this can be done using a Docker client. This is a guide for running the <strong>GETH</strong> (Ethereum-Go) node client from inside a Docker container. GETH is the GoLang implementation of the Ethereum protocol. There is an image available to pull from the Docker hub repository that can run the environment.</p>
<p>The <a target="_blank" href="https://geth.ethereum.org/"><strong>GoEthereum</strong></a> website lists the following available images with descriptions.</p>
<ul>
<li><code>ethereum/client-go:latest</code> is the latest develop version of Geth</li>
<li><code>ethereum/client-go:stable</code> is the latest stable version of Geth</li>
<li><code>ethereum/client-go:{version}</code> is the stable version of Geth at a specific version number</li>
<li><code>ethereum/client-go:release-{version}</code> is the latest stable version of Geth at a specific version family</li>
</ul>
<p>The following ports are opened by default when running from the container.</p>
<ul>
<li><code>8545</code> TCP, used by the HTTP based JSON RPC API</li>
<li><code>8546</code> TCP, used by the WebSocket based JSON RPC API</li>
<li><code>30303</code> TCP and UDP, used by the P2P protocol running the network</li>
<li><code>30304</code> UDP, used by the P2P protocol's new peer discovery overlay</li>
</ul>
<p>The Docker client software must be installed on the machine you are going to run the container from. Containers can only run if you have the Docker client installed. Depending on your operating system, the correct version of the client will be needed.</p>
<p>There are separate versions for Windows, Linux and the MacOS. The container can even be run on a Linux instance running on AWS, like a typical Linux installation. Once the Docker client is installed, the underlying platform doesn’t matter. The commands will be the same for all.</p>
<h2 id="heading-getting-the-image">Getting The Image</h2>
<p>Open a <strong><em>terminal</em></strong> on Linux or MacOS, or <strong><em>PowerShell</em></strong> command prompt from Windows. In the CLI prompt, type the following command:</p>
<p><strong>docker pull ethereum/client-go</strong></p>
<p>This pulls the Docker image from the hub repository where it was uploaded by the Ethereum developers. Once you have issued this command, the following verbose or similar should be displayed:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-48.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>I have already pulled the image, so the verbose may look different. When you issue the pull command it will always download the latest image available, which is good practice.</p>
<h2 id="heading-running-the-node">Running The Node</h2>
<p>Now you can start the node by issuing the following command:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-49.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>We want to run the node with the flag options <strong>-i</strong> and <strong>-t</strong> to display information from our container. The <strong>-p</strong> indicates the use of a port number, in this case 30303. Likewise, the command can be run without the flags and it will simply use the default ports and settings from inside the container.</p>
<p>The following information should appear from the terminal.</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-51.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>The INFO line that shows the config reveals what the node client software has installed. The node client is running the latest (as of this posting) version of the Ethereum software which is Constantinople that is a user activated hard fork at block height 7280000.</p>
<p>When running in JSON-RPC API:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-52.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>Take note that running the option rpcaddr “0.0.0.0” is not secure, since you are opening up your node to all traffic. If your ETH wallet were unlocked, a hacker can get to your node in this way and take your coins. I don’t cover security in this article, but you can read more about that <a target="_blank" href="https://medium.com/coinmonks/securing-your-ethereum-nodes-from-hackers-8b7d5bac8986">here</a> (securing your GETH node’s RPC ports). Always abide to safe and best practices.</p>
<p>If the node displays the following in the INFO line, there will be a problem:</p>
<p>config=”{ChainID: 1 Homestead: 1150000 DAO: 1920000 DAOSupport: true EIP150: 2463000 EIP155: 2675000 EIP158: 2675000 Byzantium: 4370000 Constantinople:  Engine: ethash}”</p>
<p>The Constantinople:  indicates the software was not updated. There is also no line for ConstantinopleFix, which appears in the correct configuration.</p>
<h2 id="heading-persistent-data">Persistent Data</h2>
<p>For persistent blockchain data, Docker data volumes should be used with the option <strong>-v</strong>. The <code>/path/on/host</code> should be replaced with the location you specify. For this the following command must be used:</p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-54.png" alt="Image" width="600" height="400" loading="lazy"></p>
<h2 id="heading-checking-node-status">Checking Node Status</h2>
<p>You can check the container’s status using the following command:</p>
<p><strong>docker ps</strong></p>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-55.png" alt="Image" width="600" height="400" loading="lazy"></p>
<p>This will display the Container ID with the image name, status and ports used.</p>
<pre><code>
#These are the commands to run <span class="hljs-keyword">from</span> the Docker CLI to run the Ethereum Go node client

#GETTING THE IMAGE

docker pull ethereum/client-go


#RUNNING THE NODE

docker run -it -p <span class="hljs-number">30303</span>:<span class="hljs-number">30303</span> ethereum/client-go

#RUNNING NODE USING API

docker run -it -p <span class="hljs-number">8545</span>:<span class="hljs-number">8545</span> -p <span class="hljs-number">30303</span>:<span class="hljs-number">30303</span> ethereum/client-go --rpc --rpcaddr <span class="hljs-string">"0.0.0.0"</span>

#Note, warning about using --rpcaddr <span class="hljs-string">"0.0.0.0"</span> <span class="hljs-keyword">in</span> a live environment. It is an insecure way <span class="hljs-keyword">of</span> opening your node.
#There are different ways to secure your ports, but <span class="hljs-built_in">this</span> is one thing to take note <span class="hljs-keyword">of</span> <span class="hljs-keyword">if</span> you plan to use the API.


#PERSISTENT DATA

docker run -it -p <span class="hljs-number">30303</span>:<span class="hljs-number">30303</span> -v /path/on/host:<span class="hljs-regexp">/root/</span>.ethereum ethereum/client-go
</code></pre><hr>
<p><img src="https://www.freecodecamp.org/news/content/images/2019/08/image-56.png" alt="Image" width="600" height="400" loading="lazy">
<em>Running GETH from a Docker Container</em></p>
<p>Take note that this does not automatically mine ETH. That is a different process. For getting quick access to the Ethereum blockchain, this is the purpose for running GETH.</p>
<p>For full code source, visit: <a target="_blank" href="https://github.com/Play3rZer0/GETHDocker.git">https://github.com/Play3rZer0/GETHDocker.git</a></p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to build a car manufacturing supply chain system using Ethereum ]]>
                </title>
                <description>
                    <![CDATA[ By Marcelo Russi Mergulhão Here at Daitan we are always looking for new technologies that can help our clients solve their problems more efficiently. Lately one that has captured a lot of our and our clients’ attention is Blockchain. In this article,... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/how-to-build-a-car-manufacturing-supply-chain-system-using-ethereum-cbb87144cde5/</link>
                <guid isPermaLink="false">66c34f53912fb29c4f156c1f</guid>
                
                    <category>
                        <![CDATA[ Blockchain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Ethereum ]]>
                    </category>
                
                    <category>
                        <![CDATA[ General Programming ]]>
                    </category>
                
                    <category>
                        <![CDATA[ supply chain ]]>
                    </category>
                
                    <category>
                        <![CDATA[ tech  ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ freeCodeCamp ]]>
                </dc:creator>
                <pubDate>Fri, 15 Feb 2019 17:16:24 +0000</pubDate>
                <media:content url="https://cdn-media-1.freecodecamp.org/images/1*t0Z20-NTO_EcRzDpgl3FZg.jpeg" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>By Marcelo Russi Mergulhão</p>
<p>Here at <a target="_blank" href="http://www.daitan.com/">Daitan</a> we are always looking for new technologies that can help our clients solve their problems more efficiently. Lately one that has captured a lot of our and our clients’ attention is Blockchain.</p>
<p>In this article, our goal is to present a practical way of implementing your own supply chain application based on a blockchain platform!</p>
<p>The system is used for one of the problems where I think applying blockchain gives the highest value: a supply chain.</p>
<p>This application has been explored a lot lately on PoCs and huge companies are already <a target="_blank" href="https://www.maersk.com/en/news/2018/06/29/maersk-and-ibm-introduce-tradelens-blockchain-shipping-solution">experimenting with that for their operations</a>.</p>
<p>Using blockchain to solve this type of problem is a good alternative because we can benefit from the transparency and efficient provenance tracking inherent to the technology.</p>
<p>Since this article intends to be simple and not a complete project, we will streamline the problem a lot.</p>
<p>At the end, we still have an end-to-end system that can demonstrate the applicability of the technology to this particular set of problems.</p>
<h3 id="heading-choosing-a-platform">Choosing a Platform</h3>
<p>Currently there are a lot of platforms that allow you to make your own blockchain or use a public blockchain for your own projects, so we will leverage one instead of building from scratch.</p>
<p>These projects have a lot of backing from players from both enterprises and the open source community, so we believe that using one is the most practical path for the majority of problems, allowing us to focus on the business logic instead of the infrastructure.</p>
<p>For our demo we chose the <a target="_blank" href="https://www.ethereum.org/">Ethereum Project</a>. It is a popular platform and all the development tools available make implementation of solutions over it easy to accomplish.</p>
<h3 id="heading-the-manufacturing-story"><strong>The Manufacturing Story</strong></h3>
<p>We have established the domain, but what specifically do we intend to make?<br>Let’s describe a simple car manufacturing problem and the players involved in the process.</p>
<p>First, we have the parts factory, responsible for producing wheels, body parts, engines and transmissions. The factory informs each part production using the “ProductManagement” smart contract, which will keep details about each part and product.</p>
<p>Additionally, the factory states that it is the owner of a specific part by calling a method from the “ChangeOwnership” smart contract, which will keep the owner history of each part and product.</p>
<p>Going further on the chain, we have a car factory that buys parts from the part factory to manufacture cars. The “ChangeOwnership” contract is where we keep this type of operation, so we have another method to allow the parts factory to transfer the part ownership to the car factory.</p>
<p>With enough parts, the car factory can finally start to manufacture cars. Similar to what the parts factory did to inform its job, the car factory now uses the “ProductManagement” smart contract to state a specific car assembly. Each car has a set of properties, like a serial number, and also has a parts list, that ties cars to specific parts.</p>
<p>The ownership is controlled by the “ChangeOwnership” contract and so the car factory sets that car ownership to itself.</p>
<p>Finally, we add dealers to the scenario and they can buy cars from a factory and the latter can transfer the car ownership using “ChangeOwnership”. The blockchain stores every transaction that involved that car or any of the parts that compose it, so the dealer (or any other part) can track everything that a specific item has gone through. In our case this tracking will be done by watching the events generated by the transactions. This will become clear when we analyze the code.</p>
<p>The complete product flow can be seen in the picture below:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*UoHJ5vPAkJXnu-cMPYRB_A.jpeg" alt="Image" width="800" height="363" loading="lazy">
<em>Car Manufacturing Supply Chain</em></p>
<p>We know what to do, but we still need to arm ourselves with some tools to enable the development.</p>
<h3 id="heading-environment-and-tools"><strong>Environment and Tools</strong></h3>
<p>First, we need to make a clear distinction between the networks of the Ethereum ecosystem. The main network (called Mainnet) is where the real apps reside and where each unit of ether has real value.</p>
<p>This mean that everything you record there is bound to exist as long as Ethereum itself exists. Additionally, ether can only be obtained by mining or by buying it with real money.</p>
<p>Using that network to develop demonstrations seems like a bad idea, so there are other networks that are better at supporting development. These networks can be public networks, like the one called Rinkeby, or you can even create your own Ethereum network!</p>
<p>While using a public Test Net like Rinkeby provides us a better way to validate our DApp (Decentralized App), we will create our own network to shorten the transaction acceptance time and simplify the development the most.</p>
<p>The tool we will use to create our network is called <a target="_blank" href="https://truffleframework.com/ganache">Ganache</a>.</p>
<p>Ganache is a simple tool that creates a local Ethereum network and you can connect to it just like you would with the main network. It also provides you with 10 accounts with 100 ether every time you run it.</p>
<p>I like to live on the terminal, so instead of using the Ganache UI, I will use <a target="_blank" href="https://github.com/trufflesuite/ganache-cli">ganache-cli</a>, the command line version of Ganache that is a NodeJS-based tool and can be installed with npm:</p>
<p><code>npm install -g ganache-cli</code></p>
<p>To run, just execute <code>ganache-cli</code> and you are good to go! When you run the CLI, it will generate a mnemonic for your wallets. The mnemonic is a 12-word phrase that is the root for generating the account private keys and consequently the wallets.</p>
<p>The output is like the following image:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*Wnlj5Sl_5e-NTos9HPwc3A.png" alt="Image" width="646" height="721" loading="lazy"></p>
<p>Save the mnemonic to use later. Whenever you need to run Ganache again you can preserve the same accounts providing the mnemonic with the -m parameter:</p>
<p><code>ganache-cli -m "now frame tenant chronic oven cube minute immune leaf clock demand volume"</code></p>
<p><strong>Note: mnemonics created by Ganache are not safe and should not be used for wallets on the Ethereum network</strong></p>
<p>Now that we have our network we need to be able to test and deploy our contracts to it. This is accomplished by another tool called <a target="_blank" href="https://truffleframework.com/truffle">Truffle</a>, part of the same development suite as Ganache. Truffle can also be installed with npm, so just run:</p>
<p><code>npm install -g truffle</code></p>
<p>We will use Truffle to prepare our project structure, so run <code>truffle init</code> and check the folder structure that is created:</p>
<pre><code>ethereum-supply-chain|-contracts| — Migrations.sol|-migrations| — <span class="hljs-number">1</span>_initial_migration.js|-testtruffle-config.js
</code></pre><ul>
<li>Contracts: contains the code for our smart contracts</li>
<li>Migrations: contains the deployment instructions to our contracts</li>
<li>Test: contains the tests for the contracts</li>
<li>Truffle-config.js (or truffle.js depending on your O.S.): main configuration file, points to the Ethereum networks that we can deploy to</li>
</ul>
<p>The configuration file comes with a lot of content, but most of it is commented. To add our local network to the deployment options just uncomment the following part (lines 49–53):</p>
<p>Finally, we need to provide an interface to our users to let them interact with the Ethereum networks.</p>
<p>One of the options for this is to install <a target="_blank" href="https://metamask.io/">Metamask</a>, a browser plugin that manages wallets and also enables web systems to speak with the Ethereum networks.</p>
<p>Once installed, Metamask provides an interface to check wallet funds on different networks. Whenever a web system requires an operation that involves payment, Metamask asks for user approval.</p>
<p>To install it, just go to their <a target="_blank" href="https://metamask.io/">website</a> and choose the extension to your browser.</p>
<p>After the installation, Metamask needs to create or import a wallet, so choose “import with seed phrase” and paste the mnemonic you got from ganache-cli.</p>
<p><strong>Note: Metamask is currently in beta, so keep that in mind whenever you use it and follow the instructions given after configuration</strong></p>
<p>And that is all we need for now, let’s dive into the code!</p>
<h3 id="heading-smart-contracts-hands-on"><strong>Smart Contracts Hands On</strong></h3>
<p>The first thing we need to do is to implement the logic behind each of the smart contracts, so we begin with “ProductManagement”.</p>
<p>This contract should have one method for registering parts and another to register products, even if the requirements for each operation are very similar.<br>We do that because we want to check that all the parts exist when we try to build a new product. So we can have the following methods:</p>
<ul>
<li>Part registration: create a mapping given the details of the part itself (type, serial number and manufacturing date), the factory that made it (factory id) and the current owner (owner id).</li>
<li>Product registration: create a mapping given the same as part registration plus the id of each of the parts present on the product.</li>
<li>Getters for the mappings so that we can check parts’ and products’ existence and get their details.</li>
</ul>
<p>The contract code that we need to implement that is:</p>
<p>We define structs for parts and products that map all the information required to “build” our parts and products, and after that we add the mappings that will keep all registered items.</p>
<p>The <code>buildPart</code> method is simple: it uses a helper function to concatenate the sender address and part information on a bytes array and calculate a hash. This hash is the key used when registering and later querying the data, so we return it to aid development.</p>
<p>Since Ethereum transactions are not validated and run when you call the smart contract, we receive a transaction hash and can’t use it for our web app, but we can issue a call instead of a transaction to check the results easily.</p>
<p>In a real system we would expect the manufacturer to provide the part hash with the physical part, but we won’t think about this mechanism here. We know the information used to generate the hash, so we can calculate it when we need, and that is exactly what we do on the testing code and also on the web app.</p>
<p>We won’t cover the test code so that we don’t extend the article, but check it out in our <a target="_blank" href="https://github.com/daitan-innovation/ethereum-supply-chain">repository</a>!</p>
<p>The buildProduct method is just an extension of the buildPart method, adding a simple check to guarantee that all the parts were registered before attempting to create the product.</p>
<p>Two things are really worth noting about the code:</p>
<ul>
<li>Solidity generates getters automatically for public mappings, so we don’t need to worry about that!</li>
<li>But we need to worry when returning array values, exactly the case for our product parts. We have created a “getParts” function to address this need.</li>
</ul>
<p>Continuing our development we will code the “ChangeOwnership” contract. It has a simple purpose: manage the part and product transfer between interested parties.</p>
<p>Since we will use IDs on the ownership transfer operation, we can have one method for manufacturers to register their “initial ownership” and another method to change the ownership to other parties.</p>
<p>We just need to receive a parameter to tell us if we want to register parts or products to know which mapping to check on the “ProductManagement” contract and also where to store the current item owner. The code is the following:</p>
<p>We use a “ProductManagement” instance to query for parts and products whenever we try to interact with them. This highlights an important aspect of smart contracts: you can use them to call other smart contracts! One option to do that is to declare the contract ABI on the beginning of the contract file, but just the parts required by your contract. In our case it means:</p>
<p>To point to the correct contract, we just need to pass the contract address when instantiating it, like this:</p>
<p><code>pm = ProductManagement(prod_contract_add);</code></p>
<p>Proceeding on the “ChangeOwnership” code review, we can also see that we define two events, TransferPartOwnership and TransferProductOwnership. Events can be logged with transactions, so that will the core of our “tracking” functionality.</p>
<p>Whenever a part or product is successfully transferred to another account, we will emit an event.</p>
<p>Take the addOwnership function as an example: we verify that the item exists, check if it is still unregistered and that the manufacturer is the one asking ownership. If we verify all that, we then store the manufacturer as the part owner and record that on Ethereum as an event. Later, we can query events about that part from its hash and see all the transfers.</p>
<p>The only other point to note about this code is on the function “changeOwnership”: whenever a car changes the owner we also change the ownership of the parts that compose it. But enough about code review, let’s check how to deploy it.</p>
<h3 id="heading-contract-deployment">Contract Deployment</h3>
<p>To migrate our contracts to Ethereum we need to create a simple deployment file on the “deployments” folder. We can base ourselves on the “1_initial_migration.js” file created by Truffle, so our code becomes:</p>
<p>We can finally deploy our code to our local Ethereum network by running:</p>
<p><code>truffle migrate -network development</code></p>
<p>When running that you will probably note that the ganache-cli terminal outputs a lot of messages, including some like:</p>
<pre><code>Transaction: <span class="hljs-number">0x9fe6d2ece9cdca2f12b574ead7abb7bea7feab316f5cd6ebbd5b713e76850a1dC</span>ontract created: <span class="hljs-number">0xb6a3c3cf9d1e27e43e5fb12e505d79764748edbe</span>
</code></pre><p>Those represent our contract addresses, so save them to be able to communicate later. We will need this address on our web interface!</p>
<h3 id="heading-web-interface-hands-on"><strong>Web interface Hands On</strong></h3>
<p>Our system now has both smart contracts ready and all we need is the interface to use them.</p>
<p>We made a page for each role on our scenario, so we have a “Part Factory View”, a “Car Factory View” and a “Dealer View”. We won’t get into the specifics of the methods implemented for the interactions, but let’s give an overview to instigate you to check the code!</p>
<p>The part factory interactions, like part registration, ownership addition and ownership transfer, can be performed on the interface shown below. It is interesting to note Metamask asking for permission for every single transaction we make.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*qPeuFBBB1rSmtRSfZGBDbQ.png" alt="Image" width="800" height="740" loading="lazy">
<em>Part Manufacturing Interface</em></p>
<p>Looking at things from a car manufacturer’s perspective, we have the part list populated from the records on the blockchain, then the part selection to assemble the car, the car build, and finally we transfer the ownership to a dealer. Just like a part factory, the car factory also has its own interface, shown below. All interactions with Ethereum use the part/car hash created from their properties.</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*y_O0U_FEUYFeE0F57i-qLQ.png" alt="Image" width="800" height="656" loading="lazy">
<em>Car Manufacturing Interface</em></p>
<p>The final view is from dealers, and for our example that is the simplest: we can just check the cars and parts for the owner history. Check the image below for details:</p>
<p><img src="https://cdn-media-1.freecodecamp.org/images/1*vOylTWq1GMo6wWt3a9iYjw.png" alt="Image" width="800" height="676" loading="lazy">
<em>Dealer View with Owner History for Cars and Parts</em></p>
<p>Under the hood, we use the web3 library to call our smart contracts’ methods. The library provides us with objects representing our contracts and methods, and for that we only need to set:</p>
<ul>
<li>Network location</li>
<li>Contract ABI (smart contract definition)</li>
<li>Contract address</li>
<li>Wallet to use for operations</li>
</ul>
<p>By default, ganache-cli runs the network on the 8545 port and the ABI is generated every time you compile and deploy your contracts (but only when we update the code, so we don’t need to change that).</p>
<p>If you ever need to, get the value stored on the “build” folder of the setup.<br>The contract address we must specify with the values saved before, so change the following lines to your values:</p>
<p>Now that we have our page ready to interact with our smart contracts, we just need to prepare the functions that use the objects provided by web3 and our system is complete!</p>
<p>The functions basically get the data from the input fields on the page and then call the functions with them as parameters. The complete code is too big to fit this article, but let’s check just two parts that explain most of the interactions with the blockchain. The first is:</p>
<p>The “window.co” object is our “ChangeOwnership” contract, and both currentPartOwner and addOwnership are methods provided by it.<br>The difference here is on the function used to call them: call vs send.<br>Web3 1.0 requires you to specify the type of interaction that you want to do with the blockchain: reads or transactions.</p>
<p>So whenever you use a method with “call” you are just reading data from the blockchain, it costs you no ether and also does not change the chain state.</p>
<p>On the other hand, if you use “send” you have to send gas to perform the operation and it creates a transaction. As we have said before, transactions are not mined immediately, so take that into account when developing real world Dapps.</p>
<p>Finally, the second part to be highlighted is:</p>
<p>Remember when we said that Events would be our supply chain core? This line is used to get all events from a specific type, filtering the results by the part hash.</p>
<p>It means that we can get everything that happened with a single part, and if we want we can also get the part details using the same hash and calling “parts” from “ProductManagement”.</p>
<p>Pretty cool, huh?</p>
<h3 id="heading-wrapping-up"><strong>Wrapping Up</strong></h3>
<p>And we’re done!</p>
<p>Every time a part manufacturer wants to notify a new part production, a car manufacturer wants to assemble that in a car, or we want to move the parts and cars from one owner to another, we can simply use the web interface to do it.</p>
<p>We have a transparent record that allows manufacturers, dealers and buyers to have the same information about the products.</p>
<p>If a problem is found about a certain serial number range in the factories, the factory can check where to tackle and solve the problem.</p>
<p>The same is true in the opposite direction: dealers and buyers can trace back their products’ parts to the factories in case they have problems or need replacements.</p>
<p>Implementing the system based on a blockchain also provides a distributed and consistent record that none of the participants can alter without traces, so we avoid foul play.</p>
<p>We have simplified the supply chain scenario a lot, but we hope that this demo has shown the power of using the blockchain in this context. Now you can start your solution planning and consider it as an implementation alternative.</p>
<p>I hope you enjoyed it!</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
