Building an App using thirdweb
In this guide you will learn how to build an app on Base using the thirdweb platform.
To achieve this, you will deploy a smart contract for a NFT collection and create an NFT gallery app for viewing the metadata details of each NFT within the collection.
Objectives
By the end of this guide, you should be able to:
- Create an NFT collection and mint new NFTs using thirdweb.
- Develop an NFT gallery app using a prebuilt thirdweb templates.
Prerequisites
1. Setting Up a Coinbase Wallet
To begin developing an app on Base, you first need to set up a web3 wallet. We recommend using the Coinbase Wallet, which can be easily created by downloading the Coinbase Wallet browser extension.
2. Wallet Funding
Blockchain transactions, including deploying smart contracts, necessitate a gas fee. You must, therefore, fund your wallet with Ether (ETH) to cover these costs. This guide focuses on deploying a contract to the Base Goerli test network, and you can fund your wallet with Base Goerli ETH via the following options:
Detailed steps on wallet funding with Base Goerli ETH can be found under Network Faucets.
Creating an NFT Collection
Before developing an app, you need to create an NFT collection via thirdweb.
Follow these steps to set up your NFT collection:
- Visit the thirdweb dashboard.
- Click the Connect Wallet button located in the upper right corner to connect your wallet.
- From the dashboard, select Browse contracts to explore a list of deployable smart contracts.
- Navigate to the NFTs section and select the NFT Collection smart contract.
- Click the Deploy now button.
- Provide the required details for your NFT collection:
- Contract metadata (i.e. image, name, symbol, description)
- Network (Choose Base Goerli Testnet)
- Click Deploy Now.
For production / mainnet deployments select Base
(mainnet) as the network rather than Base Goerli
.
Post-deployment, you can manage your smart contract via the thirdweb dashboard.
Currently, your NFT Collection lacks NFTs. To populate our upcoming NFT Gallery app, we will need to create several NFTs.
Follow the steps below to mint new NFTs:
- Visit the thirdweb dashboard.
- From the dashboard, select View contracts to view all your previously deployed contracts.
- Select the NFT Collection smart contract you deployed.
- Navigate to the NFTs tab on the left-hand sidebar.
- Click Mint.
- Fill in the metadata details for the NFT (name, media, description, properties).
- Click Mint NFT.
Repeat these steps to mint as many NFTs as you'd like.
Building an NFT Gallery App
With an NFT Collection in place, it's time to construct an NFT Gallery App. The thirdweb CLI provides various prebuilt and starter templates for popular app use-cases, which can significantly expedite your app development process.
In this guide, we'll use the thirdweb CLI to generate a new app project using the NFT Gallery template.
Run the following command:
npx thirdweb create --template nft-gallery
By default, the template is configured for an NFT collection on the Ethereum Mainnet. We will modify the code to adapt our NFT collection on the Base Goerli Testnet.
Follow these steps to update the template:
- Open the project using your preferred code editor.
- Open the
src/consts/parameters.ts
file.- Update the
contractAddress
variable to your NFT collection's contract address (found on the thirdweb dashboard). - Update the
chain
variable tobase-goerli
. - Update the
blockExplorer
variable tohttps://goerli.basescan.org
.
- Update the
- Open the
src/main.tsx
file. - Replace the file contents with the following code:
import React from "react";
import ReactDOM from "react-dom/client";
import App from "./App";
import "./index.css";
import { ThirdwebProvider } from "@thirdweb-dev/react";
import { BaseGoerli } from "@thirdweb-dev/chains";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<ThirdwebProvider activeChain={BaseGoerli}>
<App />
</ThirdwebProvider>
</React.StrictMode>,
);
The above code imports and uses BaseGoerli
to be the activeChain
.
For production / mainnet deployments, update the information above so that the chain
variable is base
(step ii), the blockExplorer
is https://basescan.org
(step iii), and update both instances of BaseGoerli
to Base
in the example javascript code.
Running the Application
With the updated Base Goerli Testnet chain and your NFT collection's address, you can view your NFT collection from the application.
To start the application, run the following command from the root directory:
yarn dev
Conclusion
Congratulations on reaching the end of this guide! You've now learned how to create an NFT collection using Thirdweb, mint new NFTs, and build an NFT gallery app on the Base blockchain!
As a next step, check out other prebuilt smart contracts and starter templates provided by the thirdweb platform that can help you build your next onchain app on Base.