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
projecta 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 Newin the Projects section. - Select
Projectfrom the dropdown menu. - Enter a project name and add
localhost:5173underAllowed Domains. ClickCreate. - A
Client IDandSecret IDwill be generated. Copy both to a secure location—we’ll only need theClient ID.
Create an .env file
- Create an
.envfile 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-
useOwnedNFTsFull reference: https://portal.thirdweb.com/references/typescript/v5/erc721/getOwnedNFTs -
Use the
useReadContracthook 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
updatemetadatafunction to update themetadataon your contract by passing in the information you want to update.Full reference: https://portal.thirdweb.com/references/typescript/v5/erc721/updateMetadata