Thursday, September 28, 2023
CryptoMasInfo
No Result
View All Result
  • Home
  • Crypto News
  • Bitcoin
  • Altcoin
  • Blockchain
  • DeFi
  • Ethereum
  • Dogecoin
  • Mining
  • ETF
  • More
    • Market & Analysis
    • NFT
    • WEB-3.0
    • XRP
CryptoMasInfo
No Result
View All Result
Home WEB-3.0

Web3 for Frontend Developers – Getting Started With Moralis Web3UI Kit

Adm1n by Adm1n
November 1, 2022
in WEB-3.0
0
Web3 for Frontend Developers – Getting Started With Moralis Web3UI Kit
191
SHARES
1.5k
VIEWS
Share on FacebookShare on Twitter


Introduction

The web3 ecosystem has prioritized back-end improvement of blockchain-based initiatives, whereas giving little to no contribution to the front-end stack.

The frontend is the event of the graphical consumer interface (UI) of an software. It describes how knowledge is being offered and interacted with by the consumer on the browser; principally how the applying performs basically.

On this article, we’ll be discussing the Web3UI Kit, the primary web3 front-end library, and we’ll additionally construct a dApp dashboard with it and Moralis React SDK.

Stipulations

This text is project-based and it’s best to have the next earlier than persevering with with this tutorial:

What We’re Constructing With Web3UI Equipment?

We’ll construct a dApp dashboard that shows all of the NFTs and steadiness of a related consumer on the Mainnet, Kovan, Rinkeby, Goerli, and the Ropsten Testnet.

After finishing this tutorial, you may have an understanding of how you can arrange and construct a web3 frontend with Web3UI Equipment parts.

How It Works

Take a look at the fundamental move of how our dApp dashboard will perform beneath:

1. Customers will log in by connecting their pockets:

Login page for the user to connect their wallet

2. Related customers can be redirected to their dashboard:

connected users can access the Web3 dApp dashboard and view their balances

Demo

Beneath, is a demo video of the dApp dashboard we’ll construct on this tutorial:

Demonstration of Web3 dApp dashboard that we'll build with Web3UI Kit components and React, displaying a token balance of the connected user on the Mainnet, Kovan, Rinkeby, Goerli, and the Ropsten Testnet

You may as well take a look at the stay model of what we’re constructing here.

What Is Web3UI Equipment?

Moralis Web3UI Kit is the first web3 frontend library used to develop the dApp frontend

Web3UI Equipment is an open supply, light-weight, reusable web3 UI element. It was developed and presently maintained by the Moralis workforce. It is just like the Web2 UI element library,Chakra UI and Material UI, however with extra functionalities.

Web3UI Equipment Parts

The Moralis Web3UI Equipment gives a straightforward to make use of consumer interface element that may make your dApp improvement sooner.

Beneath, are a few of the Web3UI Kits that we’ll use to construct our web3 dashboard:

1. BannerStrip

The Web3UI <BannerStrip /> is a prime nav element that can be utilized to show an vital discover to the consumer.

Ilustration of how Web3UI Kit BannerStrip works in React

2. NFTBalance

The Web3UI <NFTBalance /> is a UI element that fetches and shows all of the NFTs owned by a selected tackle on a specified blockchain.

Illustration of how Web3UI Kit NFTBalance works in React

3. ConnectButton

The Web3UI <ConnectButton /> is an authentication button that permits the consumer to attach or disconnect their pockets from our dApp. Moralis will deal with all of the authentication logic beneath the hood.

Illustration of how Web3UI Kit ConnectButton works in React

4. useNotification

When an occasion or motion takes place in our dApp, the Web3UI useNotification() hook can be utilized to emit and show a brand new notification to the consumer by means of the <Notification /> element.

Illustration of how Web3UI Kit useNotification works in React

5. Widget

The Web3UI <Widget /> element is a field that can be utilized to show a dataset label and its worth.

Illustration of how Web3UI Kit Widget works in React

6. Todo

The Web3UI Equipment gives a <Todo /> checklist UI element with CRUD performance out of the field. You possibly can implement a useful todo checklist in your dApp with only some strains of code.

Illustration of how Web3UI Kit Todo works in React

7. Hero

The Web3UI equipment <Hero> element can be utilized to rapidly create a hero part for a dApp touchdown web page.

Illustration of how Web3UI Kit Hero works in React

8. Credentials

The Web3UI <Credentials /> element can be utilized to toggle the visibility of delicate knowledge on the entrance finish, corresponding to passwords or tokens.

Illustration of how Web3UI Kit Credentials works in React

9. Typography

You possibly can enhance the font of your dApp with the Web3UI Equipment <Typography /> element.

Illustration of how Web3UI Kit Typography works in React

You possibly can take a look at the whole Web3UI Equipment parts checklist here.

Constructing the dApp Dashboard

On this part, we’ll mix all of the Web3UI Equipment parts we have mentioned above to construct our web3 dashboard.

Step 1 – Putting in Moralis Web3UI Equipment in React

Run the command beneath to create a React app with yarn and Create React App (CRA):

yarn create react-app my-web3-dashboard

Navigate to the newly created folder with the command beneath:

cd my-web3-dashboard

Subsequent, run the command beneath to put in Moralis React SDK and Web3UI Kit:

yarn add moralis react-moralis web3uikit

Begin your React server with the command beneath:

yarn begin

Step 2 – Initializing Moralis SDK in React

After establishing your Moralis server and putting in the Moralis SDK (see right here), the following step is to determine a connection between our React app and our Moralis server, by means of the Moralis SDK.

Create a .env file on the root of your undertaking and retailer your Moralis server particulars, like this:

REACT_APP_SERVER_URL=https://XXXXXX.usemoralis.com:2053/server
REACT_APP_APP_ID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Change the placeholders along with your Moralis credentials. Subsequent, we have to restart our server after updating the src/.env file.

Use the quick key beneath to cease your server:

ctrl + c

Begin your server once more with:

yarn run begin

Subsequent, we’ll replace our App.js file with the code beneath:

import { NotificationProvider } from "web3uikit";
import { MoralisProvider } from "react-moralis";
import { Dashboard } from "./element/Dashboard";

perform App() {
  return (
    <MoralisProvider
      serverUrl={course of.env.REACT_APP_MORALIS_SERVER_URL}
      appId={course of.env.REACT_APP_MORALIS_APP_ID}
    >
      <NotificationProvider>
        <Dashboard />
      </NotificationProvider>
    </MoralisProvider>
  );
}

export default App;

Step 3 – Creating the ConnectButton Element

On this step, we’ll create the join pockets element, in order that we will log in to the dashboard with our pockets (e.g. Metamask).

In your src folder:

  • Create a brand new parts folder
  • Within the parts folder, create a brand new ConnectWallet.jsx file with the next code:
import React from "react";
import { ConnectButton, Hero } from "web3uikit";

export const ConnectWallet = () => {
  return (
    <part className='not-connected'>
      <Hero
        backgroundURL='https://moralis.io/wp-content/uploads/2021/06/blue-blob-background-2.svg'
        title='My Web3 Dashboard 🚀'
        peak='70vh'
      >
        <ConnectButton signingMessage='Join pockets' />
      </Hero>
    </part>
  );
};

Within the code above, we’re rendering the <Hero /> and the <ConnectButton /> element.

That is the output of the <ConnectWallet /> element we used above:

building a web3UI login interface for users to connect with their wallet using Metamask

Now, the consumer is ready to join with any of their digital wallets:
User prompted to connect their wallet

The pockets modal is from the <ConnectButton /> element.

Step 4 – Constructing the dApp Dashboard

On this step, we’ll construct the dashboard parts that’ll show the next:

The steadiness of the related consumer on the Mainnet, Kovan, Rinkeby, Goerli, and Ropsten Testnets

A toggle card that shows the pockets tackle of a related consumer

A todo checklist so as to add and delete duties

The NFTs owned by the related consumer

Out of your parts folder:

  • Create a brand new Dashboard.jsx file with the code beneath:
import Moralis from "moralis";
import React, { useEffect } from "react";
import { useMoralis, useMoralisWeb3Api } from "react-moralis";
import {
  BannerStrip,
  NFTBalance,
  ConnectButton,
  useNotification,
  Widget,
  Todo,
  Credentials,
  Typography,
} from "web3uikit";
import { ConnectWallet } from "./ConnectWallet";

export const Dashboard = () => {
  const dispatch = useNotification();
  const Web3Api = useMoralisWeb3Api();
  const { isAuthenticated, consumer } = useMoralis();
  
  const userAddress = consumer?.get("ethAddress");

  
  const [mainnetBalance, setMainnetBalance] = React.useState("0");
  const [kovanBalance, setKovanBalance] = React.useState("0");
  const [rinkebyBalance, setRinkebyBalance] = React.useState("0");
  const [goerliBalance, setGoerliBalance] = React.useState("0");
  const [ropstenBalance, setRopstenBalance] = React.useState("0");

  
  const handleNewNotification = ({ sort, title, message, place }) => {
    dispatch();
  };

  
  const fetchTokenBalances = async (chain) => {
    const choices = { chain, tackle: userAddress };
    const consequence = await Web3Api.account.getNativeBalance(choices);
    return consequence.steadiness;
  };

  
  const fetchBalances = async () => {
    const balances = await Promise.all([
      fetchTokenBalances("mainnet"),
      fetchTokenBalances("kovan"),
      fetchTokenBalances("rinkeby"),
      fetchTokenBalances("goerli"),
      fetchTokenBalances("ropsten"),
    ]);

    
    const mainnetBalance = balances[0];
    const kovanBalance = balances[1];
    const rinkebyBalance = balances[2];
    const goerliBalance = balances[3];
    const ropstenBalance = balances[4];

    
    const mainnetBalanceEther = Moralis.Items.FromWei(mainnetBalance);
    const kovanBalanceEther = Moralis.Items.FromWei(kovanBalance);
    const rinkebyBalanceEther = Moralis.Items.FromWei(rinkebyBalance);
    const goerliBalanceEther = Moralis.Items.FromWei(goerliBalance);
    const ropstenBalanceEther = Moralis.Items.FromWei(ropstenBalance);

    
    setMainnetBalance(mainnetBalanceEther);
    setKovanBalance(kovanBalanceEther);
    setRinkebyBalance(rinkebyBalanceEther);
    setGoerliBalance(goerliBalanceEther);
    setRopstenBalance(ropstenBalanceEther);
  };

  useEffect(() => {
    if (isAuthenticated) {
      
      const notificationData = {
        varieties: "information",
        title: "Pockets Related 🤝",
        place: "bottomR",
      };

      
      handleNewNotification(notificationData);

      
      fetchBalances();
    }
  }, [isAuthenticated]);

  return (
    <React.Fragment>
      <header>
        {}
        <BannerStrip
          textual content={
            isAuthenticated
              ? "Welcome again 👋"
              : "You aren't related to the dApp. Please connect with the dApp to see your NFT steadiness."
          }
          peak='40px'
          className='dapp-header-banner'
        />

        {}
        <part className='container topnav'>
          <Typography variant='h2'>My Web3 Dashboard</Typography>
          <ConnectButton signingMessage='Join pockets' />
        </part>
      </header>
      <most important>
        {isAuthenticated ? (
          <part className='container'>
            {}
            <part className='wallet-balance-widget'>
              <Widget
                title='MAINNNET'
                information={`${mainnetBalance.slice(0, 10)} ETH`}
              />
              <Widget
                title='RINKEBY'
                information={`${rinkebyBalance.slice(0, 10)} ETH`}
              />
              <Widget title='KOVAN' information={`${kovanBalance.slice(0, 10)} ETH`} />
              <Widget
                title='GOERLI'
                information={`${goerliBalance.slice(0, 10)} ETH`}
              />
              <Widget
                title='ROPSTEN'
                information={`${ropstenBalance.slice(0, 10)} ETH`}
              />
            </part>

            {}
            <part className='my-secret-credential'>
              <Credentials
                icon='information'
                textual content={userAddress}
                title='Pockets Handle:'
              />
            </part>

            {}
            <part className='todo-container'>
              <Todo
                label='Enter IP'
                onChange={perform noRefCheck() {}}
                todos={[]}
              />
            </part>

            {}
            <part className='my-nfts-section'>
              <NFTBalance tackle={userAddress} chain='rinkeby' />
            </part>
          </part>
        ) : (
          
          <ConnectWallet />
        )}
      </most important>

      <footer className='container'>
        Powered by <a href='https://moralis.io'>Moralis Web3UIKit</a>
      </footer>
    </React.Fragment>
  );
};

Within the code above:

  • The dashboard contents will solely be accessible if a pockets is related.

We test whether or not or not a pockets is related with the Moralis isAuthenticated state.

  • We’re fetching the steadiness of the related consumer from all of the chains utilizing promise.all() and changing it from wei to ether.

  • We’re additionally displaying all of the consumer’s NFTs within the rinkeby community.

Change your index.css content material with the next strains of code:

Related articles

BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

S21 Miner Makes its Debut at WDMS for the First Time, with BitFuFu Among the First Public Online Sales Platforms – CryptoSlate

September 28, 2023
BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

ANVI selects Reltime to bring Web3 Mobile Financial Services to … – PR Newswire

September 28, 2023
* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

physique {
  font-family: Arial;
}

.container {
  padding: 20px;
}

.not-connected > * > h1 {
  z-index: 0 !vital;
}

.topnav {
  show: flex;
  justify-content: space-between;
  align-items: heart;
  margin-top: 50px;
  margin-bottom: 20px;
}

.wallet-balance-widget {
  show: flex;
  hole: 20px;
  margin: 30px 0;
}

.todo-container {
  margin: 30px 0;
  width: 100%;
}

.todo-container part {
  padding: 0;
}


.my-nfts-section > part {
  show: flex;
  flex-wrap: wrap;
  justify-content: heart;
  align-items: heart;
  margin: 30px 0;
}

footer {
  text-align: heart;
  margin-top: 50px;
}

When a pockets is related, our dApp dashboard ought to look one thing like this:

building a Web3 dApp dashboard to display connected user's balance on both Mainnet and Testnet using Web3UI Kit and React

You Made It 👏

Our dApp dashboard is code prepared; you may go forward and join your pockets to entry the dashboard or observe the The way it Works.

You’ll find the whole React supply code for our tutorial here.

Conclusion

This text demonstrates how you can set up and construct your dApp frontend with the Moralis Web3UIKit.

The Web3UIKit is an open supply frontend library for constructing Web3 initiatives interface and it is maintained by Moralis. You possibly can contribute to the Web3UI Equipment from their official repository here.

The place Do You Go Subsequent?

Now that you understand how to construct an NFT minting good contract and how you can work together with it from a React software:

  • Be taught The way to Construct a Web3 Login With Web3.js Library here.

  • Be taught The way to Construct Your Personal NFT Explorer With Moralis React SDK here.

  • Be taught The way to Construct and Deploy an NFT Minting dApp With Solidity and React here.


This text is part of the Hashnode Web3 blog, the place a workforce of curated writers are bringing out new sources that will help you uncover the universe of web3. Verify us out for extra on NFTs, DAOs, blockchains, and the decentralized future.



Source link

Tags: DevelopersFrontendKitMoralisStartedWeb3Web3UI
Share76Tweet48

Related Posts

BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

S21 Miner Makes its Debut at WDMS for the First Time, with BitFuFu Among the First Public Online Sales Platforms – CryptoSlate

by Adm1n
September 28, 2023
0

S21 Miner Makes its Debut at WDMS for the First Time, with BitFuFu Among the First Public Online Sales Platforms  CryptoSlate...

BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

ANVI selects Reltime to bring Web3 Mobile Financial Services to … – PR Newswire

by Adm1n
September 28, 2023
0

ANVI selects Reltime to bring Web3 Mobile Financial Services to ...  PR Newswire Source link

BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

Prime Bank empowering the nation with digital innovations – The Business Standard

by Adm1n
September 27, 2023
0

Prime Bank empowering the nation with digital innovations  The Enterprise Normal Source link

BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

Need to create ‘interoperable, commercially viable’ solutions as 5G matures: GSMA’s Mats Granryd – ETTelecom

by Adm1n
September 27, 2023
0

Need to create ‘interoperable, commercially viable’ solutions as 5G matures: GSMA’s Mats Granryd  ETTelecom Source link

BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

Is Pepe Going on Another Bull Run? PEPE Surges 5% While Crypto … – Cryptonews

by Adm1n
September 26, 2023
0

Is Pepe Going on Another Bull Run? PEPE Surges 5% While Crypto ...  Cryptonews Source link

Load More
  • Trending
  • Comments
  • Latest
Binance’s CZ Confirms Participating as Equity Investor in Musk’s Twitter Takeover

Binance’s CZ Confirms Participating as Equity Investor in Musk’s Twitter Takeover

October 28, 2022
USDC Lost 20% Of Its Market Capitalization In The Last 30 Days

USDC Lost 20% Of Its Market Capitalization In The Last 30 Days

October 26, 2022
Quant, XRP, and THESE Cryptos are still set to PUMP into 2022

Quant, XRP, and THESE Cryptos are still set to PUMP into 2022

October 29, 2022
Cathie Wood’s ARK Fintech Innovation ETF Buys More Coinbase

Cathie Wood’s ARK Fintech Innovation ETF Buys More Coinbase

October 25, 2022
Ripple Launches Test Phase For Ethereum Based Smart Contracts On The XRPL

Ripple Launches Test Phase For Ethereum Based Smart Contracts On The XRPL

0
3 Crypto Predictions for 2023

3 Crypto Predictions for 2023

0
Cool Cats Lands On Its Feet And Does It In Style

Cool Cats Lands On Its Feet And Does It In Style

0
Waves price analysis: WAVES loses value at $3.49 after a bearish run

Waves price analysis: WAVES loses value at $3.49 after a bearish run

0
BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

Bitcoin, Ethereum Rally Following Latest ETH Futures ETF Application, Where Next? – DailyFX

September 28, 2023
BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

Toncoin (TON): Does the Reward Outweigh the Risks? – InvestorsObserver

September 28, 2023
BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

S21 Miner Makes its Debut at WDMS for the First Time, with BitFuFu Among the First Public Online Sales Platforms – CryptoSlate

September 28, 2023
Texas takes the cake in U.S. Bitcoin mining, here’s how

Texas takes the cake in U.S. Bitcoin mining, here’s how

September 28, 2023

Recent News

BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

Bitcoin, Ethereum Rally Following Latest ETH Futures ETF Application, Where Next? – DailyFX

September 28, 2023
BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

Toncoin (TON): Does the Reward Outweigh the Risks? – InvestorsObserver

September 28, 2023
BlockJoy Secures Nearly $11 Million From Gradient Ventures, Draper Dragon, Active Capital and More To Launc… – The Daily Hodl

S21 Miner Makes its Debut at WDMS for the First Time, with BitFuFu Among the First Public Online Sales Platforms – CryptoSlate

September 28, 2023

Categories

  • Altcoin
  • Bitcoin
  • Blockchain
  • Crypto News
  • DeFi
  • Dogecoin
  • ETF
  • Ethereum
  • Market & Analysis
  • Mining
  • NFT
  • WEB-3.0
  • XRP

Crypto Calculator

Cryptocurrency Prices 

© 2022 CryptoMasInfo

No Result
View All Result
  • Home
  • Crypto News
  • Bitcoin
  • Altcoin
  • Blockchain
  • DeFi
  • Ethereum
  • Dogecoin
  • Mining
  • ETF
  • More
    • Market & Analysis
    • NFT
    • WEB-3.0
    • XRP

© 2022 CryptoMasInfo