Install thirdweb
Thirdweb is a CLI tool that you need to install to create and manage your Web3 applications.Create Application
thirdweb offers SDKs for various programming languages, such as React, React Native, TypeScript, Python, Go, and Unity.-
In your CLI run the following command:
-
Input your preferences for the command line prompts:
- Give your
project
a name - Choose your
network
: We will choose EVM for Moonbeam - Choose your preferred
framework
: Next.js, CRA, Vite, React Native, Node.js, or Express - Choose your preferred
language
: JavaScript or TypeScript - We are choosing Vite and TypeScript for this particular example.
- Give your
- Use the React or TypeScript SDK to interact with your application’s functions. See the section on “interact with your contract”
Get a Thirdweb Client ID
- Open the Thirdweb Dashboard and click
Add New
in the Projects section. - Select
Project
from the dropdown menu. - Enter a project name and add
localhost:5173
underAllowed Domains
. ClickCreate
. - A
Client ID
andSecret ID
will be generated. Copy both to a secure location—we’ll only need theClient ID
.
Create an .env file
- Create an
.env
file on your root folder. - Add the following:
Interact With a Contract
Initialize SDK On Celo
Wrap your application in theThirdwebProvider
component and change the activeChain
to Celo
Get Contract
To connect to your contract, use the SDK’sgetContract
method.
Calling Contract Functions
-
For extension-based functions, use the built-in supported hooks. The following is an example using the NFTs extension to access a list of NFTs owned by an address-
useOwnedNFTs
Full reference: https://portal.thirdweb.com/references/typescript/v5/erc721/getOwnedNFTs -
Use the
useReadContract
hook to call any read functions on your contract by passing in the name of the function you want to use.Full reference: https://portal.thirdweb.com/references/typescript/v5/useReadContract -
Use the
updatemetadata
function to update themetadata
on your contract by passing in the information you want to update.Full reference: https://portal.thirdweb.com/references/typescript/v5/erc721/updateMetadata