Tutorial
Basic Setup (main.jsx)

Basic Setup (main.jsx)

main.jsx
 
import React from "react";
import ReactDOM from "react-dom/client";
import { BrowserRouter as Router } from "react-router-dom";
import { ChainId, ThirdwebProvider } from "@thirdweb-dev/react";
 
const root = ReactDOM.createRoot(document.getElementById("root"));
 
root.render(
  <ThirdwebProvider desiredChainId={ChainId.Goerli}>
    <Router>
      <App />
    </Router>
  </ThirdwebProvider>
);
 
  • React:
    import React from "react";
  • React is a popular JavaScript library for building user interfaces, especially for single-page applications. It allows developers to create reusable UI components and manage the state of their applications efficiently.
  • ReactDOM:
    import ReactDOM from "react-dom/client";
  • ReactDOM is the library that allows React to interact with the DOM (Document Object Model) in a web browser. It provides methods to render React components into the DOM and manage updates efficiently.
  • react-router-dom:
    import { BrowserRouter as Router } from "react-router-dom";
  • react-router-dom is a library for handling client-side navigation in React applications. It provides components like BrowserRouter (aliased as Router here) to manage the browser history and enable navigation between different parts of your application without requiring a page refresh.
  • @thirdweb-dev/react:
    import { ChainId, ThirdwebProvider } from "@thirdweb-dev/react";
  • @thirdweb-dev/react is a package that provides tools for interacting with the Thirdweb blockchain platform, which simplifies the process of building decentralized applications (dApps) on top of Ethereum.
  • ChainId is an enum that lists the supported blockchain networks that can be connected to, such as Ethereum Mainnet, Goerli Testnet, etc.
  • ThirdwebProvider is a component that wraps your application and provides access to the Thirdweb blockchain platform, enabling you to interact with smart contracts and manage user authentication.
  • ReactDOM.createRoot and root.render:
    const root = ReactDOM.createRoot(document.getElementById("root"));
    root.render(
      // ...
    );
  • ReactDOM.createRoot is a method that creates a new root instance, which is responsible for rendering your React application into the DOM. It takes a DOM element as an argument, which will be the root element for your application.
  • root.render is a method that renders the React components passed to it within the root element specified when creating the root instance.
  • Application structure:
    <ThirdwebProvider desiredChainId={ChainId.Goerli}>
      <Router>
        <App />
      </Router>
    </ThirdwebProvider>
  • The application is wrapped with ThirdwebProvider and BrowserRouter (Router) components. ThirdwebProvider connects your app to the desired blockchain network (Goerli Testnet in this case) and provides access to Thirdweb features. Router enables client-side navigation within your application. The App component represents the main part of your application, containing the UI and logic.