Building an onchain app using thirdweb
In this tutorial, you'll learn how to build an app on Funki using the thirdweb platform.
You'll deploy a smart contract for an NFT collection and create an NFT gallery app to display the metadata details of each NFT within the collection.
Objectives
By the end of this tutorial, you'll be able to:
- Create an NFT collection and mint new NFTs using thirdweb.
- Develop an NFT gallery app using a prebuilt thirdweb template.
Prerequisites
1. Setting Up a Web3 wallet
To begin developing an app on Funki, you first need to set up a web3 wallet. We recommend using the Coinbase Wallet or Metamask Wallet, which can be easily created by downloading the Coinbase Wallet browser extension.
- Install MetaMask Wallet
- Install Coinbase Wallet
2. Wallet Funding
Blockchain transactions, including deploying smart contracts, necessitate a gas fee. Therefore, you will need to fund your wallet with ETH to cover those gas fees.
For this tutorial, you will be deploying a contract to the FunkiSepolia. You can fund your wallet with Funki Sepolia ETH using one of the faucets listed on the Funki Network Faucets page.
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 Funki Sepolia Sandbox)
- Click Deploy Now.
For production / mainnet deployments select FunkiMainet
as the network rather than Funki Sepolia Sandbox
.
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 set metadata for 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 +Set NFT Metadata.
- Fill in the metadata details for the NFT (name, media, description, properties).
- Click Set NFT Metadata.
Repeat these steps to set NFT Metadata as many NFTs as you'd like.
Building an NFT Gallery App
Now that we have our NFT Collection, let's build an NFT Gallery App. The thirdweb CLI offers a variety of prebuilt and starter templates for popular app use-cases, significantly speeding up your development process.
For this tutorial, we'll use the thirdweb CLI to create a new app project with the NFT Gallery template.
Execute the following command:
npx thirdweb create --template nft-gallery
By default, the template is configured for an NFT collection on the Ethereum Mainnet. We'll modify the code to adapt our NFT collection to the FunkiSepolia.
Follow these steps to update the template:
- Open the project in your preferred code editor.
- Locate and open the
src/consts/parameters.ts
file.- Change the
contractAddress
variable to your NFT collection's contract address (found on the thirdweb dashboard). - Set the
chain
variable tofunkiSepolia
. - Update the
blockExplorer
variable tohttps://testnet.funkiscan.io/
.
- Change the
- Open the
src/main.tsx
file. - Replace the entire contents of the file 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 { FunkiSepolia } from "@thirdweb-dev/chains";
ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
<React.StrictMode>
<ThirdwebProvider activeChain={FunkiSepolia}>
<App />
</ThirdwebProvider>
</React.StrictMode>,
);
The above code imports and uses FunkiSepolia
to be the activeChain
.
For production / mainnet deployments, update the information above so that the chain variable is Funki (step ii), the blockExplorer is https://funkiscan.io (step iii), and update both instances of FunkiSepolia
to FunkiMainnet
in the example javascript code.
Running the Application
Now that you've updated the FunkiSepolia chain and your NFT collection's address, you're ready to view your NFT collection in the application.
To launch the application, execute the following command in the root directory:
yarn dev
Conclusion
Congratulations on completing this tutorial! You've successfully learned how to create an NFT collection using Thirdweb, mint new NFTs, and build an NFT gallery app on the Funki blockchain.
For your next project, explore other prebuilt smart contracts and starter templates offered by the thirdweb platform. These resources can help you develop your next onchain app on Funki with ease and efficiency.