<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Jerry Musaga </title>
    <description>The latest articles on Forem by Jerry Musaga  (@jerrymusaga).</description>
    <link>https://forem.com/jerrymusaga</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1028160%2Fe5e29c6c-8633-4a7d-9772-b6a4be4d48a3.png</url>
      <title>Forem: Jerry Musaga </title>
      <link>https://forem.com/jerrymusaga</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/jerrymusaga"/>
    <language>en</language>
    <item>
      <title>How to mint tokens from the backend using Nest.js on Celo Alfajores network</title>
      <dc:creator>Jerry Musaga </dc:creator>
      <pubDate>Mon, 08 May 2023 10:34:17 +0000</pubDate>
      <link>https://forem.com/jerrymusaga/how-to-mint-tokens-in-the-backend-using-nestjs-on-celo-alfajores-network-2g21</link>
      <guid>https://forem.com/jerrymusaga/how-to-mint-tokens-in-the-backend-using-nestjs-on-celo-alfajores-network-2g21</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In this tutorial, you will learn how to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;create an ERC20 token smart contract from openzeppelin wizard with mint functionality&lt;/li&gt;
&lt;li&gt;deploy the contract to the Alfajore's testnet on Celo&lt;/li&gt;
&lt;li&gt;create API to fetch methods from the deployed smart contract to the backend&lt;/li&gt;
&lt;li&gt;use the celo-ethers-wrapper to make ethers compatible with celo network&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;To follow up this tutorial, a basic understanding on API and &lt;a href="https://nestjs.com/" rel="noopener noreferrer"&gt;nestjs&lt;/a&gt; is necessary.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Generate smart contract from Hardhat
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open up your terminal and create an empty folder using this command &lt;code&gt;mkdir my-project &amp;amp;&amp;amp; cd my-project&lt;/code&gt; Then run &lt;code&gt;yarn init -y&lt;/code&gt; to initialize the project and then install hardhat using the command &lt;code&gt;yarn add --dev hardhat&lt;/code&gt;.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjljhqtepl8gb2w9gk4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhjljhqtepl8gb2w9gk4n.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After that, run &lt;code&gt;yarn hardhat&lt;/code&gt; and select Create a typescript project and leave every other option as the default.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma00h8960qf98slcekjd.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fma00h8960qf98slcekjd.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open up the project folder on &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;visual studio code&lt;/a&gt; or any other text editor. It should look like this&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiveg3gifceoc5wembz3n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiveg3gifceoc5wembz3n.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the contracts folder, delete the Lock.sol file and do so with the files in the scripts and tests folder too.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next up, we will be using the openzeppelin contract library to generate the ERC20 token, instead of writing the code from &lt;br&gt;
scratch. But first, we need to install it using this command &lt;code&gt;yarn add @openzeppelin/contracts&lt;/code&gt; on the terminal. After the installation, go to &lt;a href="https://docs.openzeppelin.com/contracts/4.x/wizard" rel="noopener noreferrer"&gt;openzeppelin wizard&lt;/a&gt; to generate the contract for your token. After selecting mintable, it should look like this&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn55c3mqgw87rob2h9crt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn55c3mqgw87rob2h9crt.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On your text editor, in your contracts folder, create a new file called MyToken.sol and copy the codes from the openzeppelin wizard and paste it into the newly created file. Your file should look like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract MyToken is ERC20, Ownable {
    constructor() ERC20("MyToken", "MTK") {}

    function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The mint function in your contract is for creating the total supply of that token to the wallet address specified in the function &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;This is a basic solidity smart contract with the functionality of a GET and POST requests that we can use in the backend.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On your terminal, run the command &lt;code&gt;yarn hardhat compile&lt;/code&gt; so as to compile the smart contract and generate the artefact folder, which is the JSON file containing useful informations about the smart contract. We will need this JSON object for the backend interaction with the contract.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Deploy smart contract to Alfajores network
&lt;/h2&gt;

&lt;p&gt;We will be using hardhat to deploy our smart contract by setting up celo in our local environment.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your text editor, open up hardhat.config.ts file and add up this celo configuration code below
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const config: HardhatUserConfig = {
  defaultNetwork: "alfajores",
  networks: {
    alfajores: {
      url: "https://alfajores-forno.celo-testnet.org",
      accounts: {
        mnemonic: process.env.MNEMONIC,
        path: "m/44'/52752'/0'/0"
      },
    }
  },
  solidity: "0.8.18",
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In your project root directory, create a .env file where we will be storing our mnemonics. It should look like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;MNEMONICS = "paste your 12 mnemonic keys here"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Next up, install the dotenv using this command &lt;code&gt;yarn add dotenv&lt;/code&gt; so we can access the mnemonic variable in the config file. And then import the dotenv into the file
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import * as dotenv from 'dotenv';
dotenv.config()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Your hardhat.config.ts file should look like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";

import * as dotenv from 'dotenv';
dotenv.config()

const config: HardhatUserConfig = {
  defaultNetwork: "alfajores",
  networks: {
    alfajores: {
      url: "https://alfajores-forno.celo-testnet.org",
      accounts: {
        mnemonic: process.env.MNEMONIC,
        path: "m/44'/52752'/0'/0"
      },
    }
  },
  solidity: "0.8.18",
};

export default config;

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To deploy our smart contract, go to your scripts folder, create a file and name it deploy.ts , copy &amp;amp; paste the code snippets below into it
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { ethers } from "hardhat";
import { MyToken__factory } from "../typechain-types";

async function main() {
  const [signer] =  await ethers.getSigners();
  console.log("Deploying contracts with the account:", signer.address);
  console.log("Account balance:", (await signer.getBalance()).toString()); //get the wallet balance of the signer account
  const contractFactory = new MyToken__factory(signer);

  console.log(`Deploying MyToken Contract...\n`);
  const contract = await contractFactory.deploy();
  const contractTxnReceipt = await contract.deployTransaction.wait();
  console.log(`Deployed contract at address ${contractTxnReceipt.contractAddress}`);


}

main().catch((error) =&amp;gt; {
  console.error(error);
  process.exitCode = 1;
});

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Run this command on your terminal to deploy the contract &lt;code&gt;yarn hardhat run scripts/deploy.ts --network alfajores&lt;/code&gt; and you should get an output similar to this&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmrvmn0jfrabvpqv01ys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvmrvmn0jfrabvpqv01ys.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;If you get an error showing insufficient gas, copy your address to the &lt;a href="https://faucet.celo.org/alfajores" rel="noopener noreferrer"&gt;celo faucet&lt;/a&gt; and fund your account with test tokens.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Take note of the deployed contract address because it will be useful when making API calls to the backend&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up the backend using Nest.js
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.nestjs.com/" rel="noopener noreferrer"&gt;Nest.js&lt;/a&gt; is a framework for building Node.js server side applications.&lt;br&gt;
Let's get started&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your terminal, run this command &lt;code&gt;npm i -g @nestjs/cli&lt;/code&gt; to install nest cli globally.&lt;/li&gt;
&lt;li&gt;In your my-project directory, run &lt;code&gt;nest new backend&lt;/code&gt; which will create a new folder consisting of the base structure of Nest files. After installation using yarn, your terminal should look like this&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdbhk83vtmrr0ixbstyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhdbhk83vtmrr0ixbstyo.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiz2q9yie3v57st1sd00p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fiz2q9yie3v57st1sd00p.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In the terminal, navigate into the backend folder using the command &lt;code&gt;cd backend&lt;/code&gt; and run &lt;code&gt;yarn start:dev&lt;/code&gt; to start up the server and keep it in watch mode.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open up your browser and run &lt;code&gt;http://localhost:3000&lt;/code&gt; and you will see the output of Hello World!, which means the server is running successfully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Let us install a package that will help in describing our RESTful APIs, &lt;a href="https://docs.nestjs.com/openapi/introduction" rel="noopener noreferrer"&gt;nestjs/swagger&lt;/a&gt;. Run the command &lt;code&gt;yarn add @nestjs/swagger&lt;/code&gt; to install.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the installation process is complete, in your src folder, open up the main.ts file and paste the code below into it&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NestFactory } from '@nestjs/core';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  const config = new DocumentBuilder()
    .setTitle('Mint ERC20 Token on Celo Blockchain')
    .setDescription('The ERC20 API description')
    .setVersion('1.0')
    .addTag('celo, alfajores testnet')
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);

  await app.listen(3000);
}
bootstrap();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Open up your browser and enter the url &lt;code&gt;http://localhost:3000/api&lt;/code&gt;. You will get an output like this&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fay9mm1ndrcncy46gssq5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fay9mm1ndrcncy46gssq5.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Integrating Smart contract to the Backend
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;We will be using the &lt;a href="https://docs.ethers.org/v5/" rel="noopener noreferrer"&gt;ethers&lt;/a&gt; library. Run the command &lt;code&gt;yarn add ethers@^5.7.2&lt;/code&gt; to install ethers.&lt;/li&gt;
&lt;li&gt;Remember the artefact folder we generated after we compiled the smart contract? We will copy the contents in MyToken.json file into our backend folder.&lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;backend/src&lt;/code&gt; folder, create a new folder called assets and create a new file MyToken.json, paste the copied contents into the file.&lt;/li&gt;
&lt;li&gt;Open up app.service.ts, import ethers and the json object. Copy and paste the code below into the file
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';
import { ethers } from 'ethers';
import * as MyTokenJson from './assets/MyToken.json';

@Injectable()
export class AppService {

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;We have a problem in importing Json, so we have to fix that by adding &lt;code&gt;"resolveJsonModule": true&lt;/code&gt; to tsconfig.json file.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrij76j8t74to3a3wecn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxrij76j8t74to3a3wecn.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Remember the contract address we got after deploying the smart contract from the script file in hardhat, we will be using that address to interact with the functions of that address. For now, let's store the address in the app.service.ts file. The file should look like this
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';
import { ethers } from 'ethers';
import * as MyTokenJson from './assets/MyToken.json';

const CONTRACT_ADDRESS = "0xBEc9321DEDcB18e954cf63BF81A6688bA5E4415E" // paste your own contract address gotten from the terminal

@Injectable()
export class AppService {
  getContractAddress(): string {
    return CONTRACT_ADDRESS;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Open your app.controller.ts file, copy and paste the codes below
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('/contract-address')
  getContractAddress(): string {
    return this.appService.getContractAddress();
  }
}

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

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Refresh your swagger UI tab in your browser. You'll see the route to get contract address. Execute it and you will get 200 status response like the image below&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdo6njdl118rlpun1h96f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdo6njdl118rlpun1h96f.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next up, we will be using the ethers library that we installed so we can interact with the contract address.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;First up, we will get the total supply which is a default method generated from an ERC20 token.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In your app.controller.ts file, add a new route called /total-suppy, which will be an async operation, returning a promise. The updated file will look like the codes below&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Get('/contract-address')
  getContractAddress(): string {
    return this.appService.getContractAddress();
  }

  @Get('/total-supply')
  async getTotalSupply(): Promise&amp;lt;number&amp;gt; {
    return this.appService.getTotalSupply();
  }
}

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

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Next up, in your app.service.ts, we will be creating an asynchronous function called getTotalSupply. We will be using a package called &lt;a href="https://docs.celo.org/developer/celo-ethers-wrapper" rel="noopener noreferrer"&gt;celo-ethers-wrapper&lt;/a&gt; to be able to make ethers.js to be compatible with the celo network. In your backend directory of your project, install the package using &lt;code&gt;yarn add @celo-tools/celo-ethers-wrapper&lt;/code&gt;. 
Update your app.service.ts with the codes below
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';
import { ethers } from 'ethers';
import * as MyTokenJson from './assets/MyToken.json';
import { CeloProvider } from '@celo-tools/celo-ethers-wrapper'

const CONTRACT_ADDRESS = "0xBEc9321DEDcB18e954cf63BF81A6688bA5E4415E" // paste your own contract address gotten from the terminal

@Injectable()
export class AppService {
  getContractAddress(): string {
    return CONTRACT_ADDRESS;
  }

  async getTotalSupply(): Promise&amp;lt;number&amp;gt; {
    // Connecting to Alfajores testnet
    const provider = new CeloProvider('https://alfajores-forno.celo-testnet.org')
    await provider.ready
    const contract = new ethers.Contract(CONTRACT_ADDRESS, MyTokenJson.abi, provider );
    return contract.totalSupply();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Refresh your swagger UI tab on your browser. After executing your /total-supply route, you should get an output like this&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkikt2690r5enn2gwcbbf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkikt2690r5enn2gwcbbf.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
The return value we get is a Big Number. How do we convert it to a string?&lt;br&gt;
Update your getTotalSupply async function with the lines of code below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const totalSupplyBigNumber = await contract.totalSupply();
    const totalSupplyString = ethers.utils.formatEther(totalSupplyBigNumber);
    const totalSupplyNumber = parseFloat(totalSupplyString);
    return totalSupplyNumber;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Head to the swagger UI tab in browser, refresh the page and execute the total supply route. You'll get a return value of 0 at the response body because we have not minted any token on our contract.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghg5zkrnrldbhi7oen92.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghg5zkrnrldbhi7oen92.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Minting tokens requires a signer to sign the transaction and that signer has to be the owner or the deployer of the contract. We will use the celoWallet from the &lt;a href="https://github.com/celo-tools/celo-ethers-wrapper" rel="noopener noreferrer"&gt;celo-ethers-wrapper&lt;/a&gt; to be able to sign transactions and make calls.
To mint tokens in the backend, we will need to make a POST request.
In the app.controller.ts file, we need to first import Post and create a new async method route called mintTokens.
Your updated file should look like that
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Controller, Get, Post } from '@nestjs/common';
import { AppService } from './app.service';


@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}m

  @Get('/contract-address')
  getContractAddress(): string {
    return this.appService.getContractAddress();
  }

  @Get('/total-supply')
  async getTotalSupply(): Promise&amp;lt;number&amp;gt; {
    return this.appService.getTotalSupply();
  }

  @Post('/mint-tokens')
  async mintTokens(){
    return this.appService.mintTokens();
  }
}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In the app.service.ts file, import the CeloWallet from celo-ethers-wrapper and create an .env file in the backend directory which stores the private key of the account you used to deploy the smart contract because that is the signer account. Make sure you install dotenv with &lt;code&gt;yarn add dotenv&lt;/code&gt;.
Your updated file should look like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Injectable } from '@nestjs/common';
import { ethers } from 'ethers';
import * as MyTokenJson from './assets/MyToken.json';
import { CeloProvider } from '@celo-tools/celo-ethers-wrapper'
import { CeloWallet } from "@celo-tools/celo-ethers-wrapper";
import * as dotenv from 'dotenv';
dotenv.config()


const CONTRACT_ADDRESS = "0xBEc9321DEDcB18e954cf63BF81A6688bA5E4415E" // paste your own contract address gotten from the terminal
const WALLET_ADDRESS = "0x122851EB3915cc769dECBf95a566e7fC8aAc2125" // paste your own wallet address

@Injectable()
export class AppService {
  getContractAddress(): string {
    return CONTRACT_ADDRESS;
  }

  async getTotalSupply(): Promise&amp;lt;number&amp;gt; {
    // Connecting to Alfajores testnet
    const provider = new CeloProvider('https://alfajores-forno.celo-testnet.org')
    await provider.ready
    const contract = new ethers.Contract(CONTRACT_ADDRESS, MyTokenJson.abi, provider );
    const totalSupplyBigNumber = await contract.totalSupply();
    const totalSupplyString = ethers.utils.formatEther(totalSupplyBigNumber);
    const totalSupplyNumber = parseFloat(totalSupplyString);
    return totalSupplyNumber;
  }

  async mintTokens(){
    // Connecting to Alfajores testnet
    const provider = new CeloProvider('https://alfajores-forno.celo-testnet.org')
    await provider.ready
    const wallet = new CeloWallet(process.env.PRIVATE_KEY, provider);
    const contract = new ethers.Contract(CONTRACT_ADDRESS, MyTokenJson.abi, wallet );
    const mint = await contract.mint(WALLET_ADDRESS, 100000); 
    return mint;
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In your swagger UI tab, refresh it and execute the mintTokens route which is a POST request. You'll get an output like this&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fja2vwsojvlquzpebzsic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fja2vwsojvlquzpebzsic.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This indicates that the POST request was successful and your tokens are minted based on the parameter you supplied in your mintFunction method.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next up, let's check the number of tokens we have by executing the /total-supply GET request. You should get an output like this base on the amount of times you execute the mintTokens POST request.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fny3e4cjoxxdgnpbxnu42.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fny3e4cjoxxdgnpbxnu42.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In my response body, I got the value of 3e+13 which is the E- notation version of 3*10^13.&lt;/p&gt;

&lt;p&gt;You can view the details of your contract by searching up the contract address in the &lt;a href="https://alfajores.celoscan.io/" rel="noopener noreferrer"&gt;celo alfajores explorer&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is the transaction details from my contract address &lt;a href="https://alfajores.celoscan.io/address/0xbec9321dedcb18e954cf63bf81a6688ba5e4415e" rel="noopener noreferrer"&gt;0xbec9321dedcb18e954cf63bf81a6688ba5e4415e&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This is the end of this tutorial and I hope you learned one or two from this tutorial and it helped in one way or the other. Let me know what you think. Cheers&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>celo</category>
      <category>hardhat</category>
      <category>nestjs</category>
      <category>erc20</category>
    </item>
    <item>
      <title>How to connect wallet to dApp with Next.js on Polkadot</title>
      <dc:creator>Jerry Musaga </dc:creator>
      <pubDate>Mon, 01 May 2023 01:53:43 +0000</pubDate>
      <link>https://forem.com/jerrymusaga/how-to-connect-wallet-to-dapp-with-nextjs-on-polkadot-2jfg</link>
      <guid>https://forem.com/jerrymusaga/how-to-connect-wallet-to-dapp-with-nextjs-on-polkadot-2jfg</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;In decentralized applications, before a user gets to interact with the functionalities of an application, the user needs to connect the wallet address to the dApp to store the user's signature in the application. &lt;br&gt;
In this tutorial, we will be using a package called polkadot extension dapp for connecting the wallet to the dapp.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;This is a quick guide and there won't be any CSS in the guide. So to follow up this tutorial, you need to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;have &lt;a href="https://nodejs.org/en/download" rel="noopener noreferrer"&gt;node.js&lt;/a&gt; installed or  &lt;a href="https://github.com/nvm-sh/nvm" rel="noopener noreferrer"&gt;nvm&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;have a basic knowledge on &lt;a href="https://nextjs.org/" rel="noopener noreferrer"&gt;next.js&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Let's get started...
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Open up your terminal and initialize a new next.js project using the command &lt;code&gt;yarn create next-app&lt;/code&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypkdpf6lhvsuy0bbmnln.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fypkdpf6lhvsuy0bbmnln.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Make sure to opt for the options in the image above&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;In your terminal, navigate into your newly created project and open it up in your code editor.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In your code editor, open up the index.tsx file, clear the codes in there and open the code below into it&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export default function Home() {
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h2&amp;gt;Hey Polki, Welcome to Polkadot &amp;lt;/h2&amp;gt;
      &amp;lt;button&amp;gt;Connect wallet&amp;lt;/button&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In your terminal, run the command &lt;code&gt;yarn run dev&lt;/code&gt; and you will get an output like the image below&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg7dbxmzm1lfiz9m1yj0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg7dbxmzm1lfiz9m1yj0.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In your browser, navigate to &lt;a href="http://localhost:3000/" rel="noopener noreferrer"&gt;localhost&lt;/a&gt; and you will see the output of the page like the image below&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F94ls04gg9jqpuw32rj11.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F94ls04gg9jqpuw32rj11.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrate the dapp connect wallet functionality
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Head over to &lt;a href="https://polkadot.js.org/extension/" rel="noopener noreferrer"&gt;polkadot-extension&lt;/a&gt; and then &lt;a href="https://chrome.google.com/webstore/detail/talisman-polkadot-wallet/fijngjgcjhjmmpcmkeiomlglpeiijkld" rel="noopener noreferrer"&gt;Talisman&lt;/a&gt;, install these wallet extensions for polkadot and create an account.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next up in your terminal, we will be installing these packages&lt;br&gt;
&lt;code&gt;yarn add @polkadot/extension-dapp @polkadot/extension-inject&lt;/code&gt; and follow up this link &lt;a href="https://polkadot.js.org/docs/extension" rel="noopener noreferrer"&gt;polkadot-extension-dapp&lt;/a&gt; to know more about it. &lt;br&gt;
After installation is complete,you should see an output like this&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx087sp5bdlu6fpu18fa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdx087sp5bdlu6fpu18fa.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We will be using dynamic import for the newly installed package. You can read more on dynamic imports here &lt;a href="https://nextjs.org/docs/advanced-features/dynamic-import" rel="noopener noreferrer"&gt;dynamic-import&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;In your index.tsx file, add the following import and lines to your code
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from 'react';
import dynamic from 'next/dynamic'

const web3Accounts = dynamic(() =&amp;gt; import('@polkadot/extension-dapp'), { ssr: false });
const web3Enable = dynamic(() =&amp;gt; import('@polkadot/extension-dapp'), { ssr: false });

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Let's create some states in our dapp and since we are using typescript, we need to add up types to our state using the inject extension that we installed. So add the following lines below to your code
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types'; 

...

const [account, setAccount] = useState&amp;lt;InjectedAccountWithMeta[]&amp;gt;([]);
const [selectedAccount, setSelectedAccount] = useState&amp;lt;InjectedAccountWithMeta&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;So far, all the codes in our index.tsx file should look like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import { useState } from 'react';
import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
import dynamic from 'next/dynamic'

const web3Accounts = dynamic(() =&amp;gt; import('@polkadot/extension-dapp'), { ssr: false });
const web3Enable = dynamic(() =&amp;gt; import('@polkadot/extension-dapp'), { ssr: false });



export default function Home() {
  const [account, setAccount] = useState&amp;lt;InjectedAccountWithMeta[]&amp;gt;([]);
  const [selectedAccount, setSelectedAccount] = useState&amp;lt;InjectedAccountWithMeta&amp;gt;();
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h2&amp;gt;Hey Polki, Welcome to Polkadot &amp;lt;/h2&amp;gt;
      &amp;lt;button&amp;gt;Connect wallet&amp;lt;/button&amp;gt;
    &amp;lt;/&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Next up in index.tsx file, we will create an asynchronous function which will handle the functionality of the wallet connection on your dapp. 
Copy and paste these lines of codes below
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;async function connectWallet(){
    const { web3Enable,web3Accounts } = await import("@polkadot/extension-dapp");
    const extensions = web3Enable("Polki");

    if(!extensions) {
      throw Error("No Extension Found");
    }

    const allAccounts = await web3Accounts();

    console.log(allAccounts);

    if(allAccounts.length === 1){
      setSelectedAccount(allAccounts[0]);
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Finally add these last piece of codes below the return fragment
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      {
        account.length === 0 ? &amp;lt;button onClick={connectWallet}&amp;gt;Connect Wallet&amp;lt;/button&amp;gt; : null
      }

      {
        selectedAccount ? selectedAccount.address : null
      }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;All your codes should now look like this
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import { useState } from 'react';
import { InjectedAccountWithMeta } from '@polkadot/extension-inject/types';
import dynamic from 'next/dynamic'

const web3Accounts = dynamic(() =&amp;gt; import('@polkadot/extension-dapp'), { ssr: false });
const web3Enable = dynamic(() =&amp;gt; import('@polkadot/extension-dapp'), { ssr: false });



export default function Home() {
  const [account, setAccount] = useState&amp;lt;InjectedAccountWithMeta[]&amp;gt;([]);
  const [selectedAccount, setSelectedAccount] = useState&amp;lt;InjectedAccountWithMeta&amp;gt;();

  async function connectWallet(){
    const { web3Enable,web3Accounts } = await import("@polkadot/extension-dapp");
    const extensions = web3Enable("Polki");

    if(!extensions) {
      throw Error("No Extension Found");
    }

    const allAccounts = await web3Accounts();

    console.log(allAccounts);

    if(allAccounts.length === 1){
      setSelectedAccount(allAccounts[0]);
    }
  }
  return (
    &amp;lt;&amp;gt;
      &amp;lt;h2&amp;gt;Hey Polki, Welcome to Polkadot &amp;lt;/h2&amp;gt;
      {
        account.length === 0 ? &amp;lt;button onClick={connectWallet}&amp;gt;Connect Wallet&amp;lt;/button&amp;gt; : null
      }

      {
        selectedAccount ? selectedAccount.address : null
      }
    &amp;lt;/&amp;gt;
  )
}

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

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Make sure your terminal is still running and head over to the browser. Click on connect wallet button and you will get a pop up from your polkadot extension, requesting for permission to connect to your dapp. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyzzqj0tp2rptep3ie5rk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyzzqj0tp2rptep3ie5rk.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on yes to grant it permission and viola, there you go, your wallet address connected to your dapp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6crcc0a6j90h9un7ma4y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6crcc0a6j90h9un7ma4y.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I hope you enjoyed this tutorial and learned something from it. This is just to show how the connect button works and you can use this as a guide whenever you are trying to add that functionality in your Next.js project. Go and build your web3 applications on Polkadot. Cheers&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>polkadot</category>
      <category>web3</category>
      <category>nextjs</category>
      <category>dapp</category>
    </item>
    <item>
      <title>How to quickly create a React Starter template using Celo-composer.</title>
      <dc:creator>Jerry Musaga </dc:creator>
      <pubDate>Tue, 21 Feb 2023 09:30:18 +0000</pubDate>
      <link>https://forem.com/jerrymusaga/how-to-quickly-create-a-react-starter-template-using-celo-composer-381a</link>
      <guid>https://forem.com/jerrymusaga/how-to-quickly-create-a-react-starter-template-using-celo-composer-381a</guid>
      <description>&lt;h2&gt;
  
  
  Overview
&lt;/h2&gt;

&lt;p&gt;With Celo-Composer, building fullstack dApps on celo blockchain network is extremely easy and quick. In this tutorial, you will learn how to &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;setup metamask &lt;/li&gt;
&lt;li&gt;add Celo Alfajores Testnet network to metamask&lt;/li&gt;
&lt;li&gt;fund your testnet account&lt;/li&gt;
&lt;li&gt;generate a React.js template&lt;/li&gt;
&lt;li&gt;run your frontend on localhost and connect wallet&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;A look at the output on localhost&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--D5RKUWzq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k70ld8si5pnmuujlvj1a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--D5RKUWzq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k70ld8si5pnmuujlvj1a.png" alt="Image description" width="880" height="505"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisite
&lt;/h2&gt;

&lt;p&gt;To fully follow up with this tutorial, you will need to have &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://nodejs.org/en/download/"&gt;Node&lt;/a&gt; or &lt;a href="https://github.com/nvm-sh/nvm"&gt;Nvm&lt;/a&gt; installed on your system&lt;/li&gt;
&lt;li&gt;general understanding on running commands on the terminal&lt;/li&gt;
&lt;li&gt;good knowledge on &lt;a href="https://reactjs.org/"&gt;React&lt;/a&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Setting up Metamask and connecting to Celo
&lt;/h2&gt;

&lt;p&gt;I'd recommend going through this, &lt;a href="https://docs.celo.org/blog/tutorials/3-simple-steps-to-connect-your-metamask-wallet-to-celo"&gt;3-simple steps to connect your metamask wallet to celo&lt;/a&gt; for a detailed explanation to this, which is from the Celo documentation tutorials.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After setting up metamask extension, to easily connect to the Celo Alfajores network, go to &lt;a href="https://chainlist.org/"&gt;chainlist&lt;/a&gt; which is a site that has a list of EVM networks. &lt;/li&gt;
&lt;li&gt;Tick on the checkbox, Include Testnets and search for Celo Alfajores Tesnet. Connect your wallet and then select Add to Metamask.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--U6JshQiV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jh3lwnsstbwxeyvq2ly9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--U6JshQiV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jh3lwnsstbwxeyvq2ly9.png" alt="Image description" width="880" height="479"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To fund your wallet address, visit &lt;a href="https://faucet.celo.org/"&gt;celo-faucet&lt;/a&gt;, copy your wallet address from metamask and paste it in the Account Address so that your account can get funded with Celo.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Generate React template
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Open the terminal and paste this command
&lt;code&gt;npx @celo/celo-composer create&lt;/code&gt;
This is a command line tool which will help us in quickly generating a template for dApp development and in this tutorial, we will be opting for React, which is the frontend framework we will be using.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--wbwaQd8j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9dy71q7vrm7az64kzhn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--wbwaQd8j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9dy71q7vrm7az64kzhn.png" alt="Image description" width="737" height="378"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After selecting React, we will be opting for &lt;a href="https://docs.celo.org/developer/rainbowkit-celo"&gt;Rainbowkit-celo&lt;/a&gt; which is a component that makes it easy for us to integrate wallet connection into any dApps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cQD_HX7s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pre62o596oy0xfb2511r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cQD_HX7s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pre62o596oy0xfb2511r.png" alt="Image description" width="727" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After selecting Rainbowkit-celo, you can either opt for &lt;a href="https://hardhat.org/"&gt;Hardhat&lt;/a&gt; or &lt;a href="https://trufflesuite.com/"&gt;Truffle&lt;/a&gt; which will be for smart contract development or you could just opt for None.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--UIWDULB3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4z551aqfnu7hi4pdnzt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--UIWDULB3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i4z551aqfnu7hi4pdnzt.png" alt="Image description" width="725" height="228"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, we will be selecting either No or Yes to creating a &lt;a href="https://thegraph.com/docs/en/developing/creating-a-subgraph/"&gt;subgraph&lt;/a&gt;, which will help in querying data from the celo blockchain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JzjMF2X4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dktly4evsqmp3aqmfxqw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JzjMF2X4--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dktly4evsqmp3aqmfxqw.png" alt="Image description" width="730" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Next, You'll be providing a project name for the dApp and voila, your React template will be generated and you can start building your dApp.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;On your terminal, navigate to your project's directory using this command &lt;code&gt;cd [project-name]/packages/react-app&lt;/code&gt; and &lt;br&gt;
run &lt;code&gt;yarn&lt;/code&gt; to install all the dependencies needed to run the application.&lt;br&gt;
When the installation is successful, you will get an output like this&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ytz_PJfK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqj297m747qykzigs4z4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ytz_PJfK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqj297m747qykzigs4z4.png" alt="Image description" width="598" height="84"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next up, run this command &lt;code&gt;yarn run dev&lt;/code&gt; to start up the server in your localhost&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--qw0ZgEtO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atdtc8s5bjrwrlumg3c6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--qw0ZgEtO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/atdtc8s5bjrwrlumg3c6.png" alt="Image description" width="752" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Copy the local host url &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt; and open it up on the browser. And there you have it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xarCEHqW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb7pjxro50r7hpok6po3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xarCEHqW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xb7pjxro50r7hpok6po3.png" alt="Image description" width="880" height="481"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>celo</category>
      <category>celocomposer</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
