Using thirdweb

thirdwebarrow-up-right is a development framework that allows you to build web3 functionality into your applications.

In this guide, we'll give you an overview of using the thirdweb CLIarrow-up-right to deploy a contract to the Ancient8 Testnet.

By the end of this lesson you should be able to:

  • Create a project with a smart contract using thirdweb

  • Deploy smart contracts using thirdweb

  • Interact with deployed smart contracts using thirdweb

Prerequisitesarrow-up-right

The interactive thirdweb command line interfacearrow-up-right has everything you need to create, build and deploy smart contracts and apps to Ancient8 Testnet.

We recommend using npx to always get the latest version. Alternatively, you can install the CLI as a global command on your machine:

npm i -g @thirdweb-dev/cli

Creating a projectarrow-up-right

You can use the thirdweb CLIarrow-up-right to create a new project that contains a smart contract, alternatively, you can deploy a prebuilt contract for NFTs, Tokens or Marketplace directly from the thirdweb Explorearrow-up-right page.

To create a new project using the CLI, run:

npx thirdweb create contract

This will kick off an interactive series of questions to help you get started:

  • Give your project a name

  • Select Hardhat as the framework

  • Select ERC721 as the base contract

  • Select None for optional extensionsarrow-up-right

Exploring the projectarrow-up-right

The create command generates a new directory with your project name. Open this directory in your text editor.

Inside the contracts folder, you'll find a Contract.sol file; this is our smart contract written in Solidity!

If we take a look at the code, you can see that our contract is inheriting the functionality of ERC721Basearrow-up-right, by:

  1. Inheritingarrow-up-right the contract; by declaring that our contract is ERC721Base

This inheritance pattern lets us use functionality from other contracts inside of ours, modify it, and add custom logic.

For example, our contract currently implements all of the logic inside the ERC721Base.solarrow-up-right contract; which implements the ERC721Aarrow-up-right standard with several useful extensionsarrow-up-right.

Deploying the contractarrow-up-right

You can use the thirdweb CLIarrow-up-right to deploy a smart contract to Ancient8.

To deploy your smart contracts, from the root directory of your project, run:

Running this command will:

  • Compile all the contracts in the current directory.

  • Allow you to select which contract(s) you want to deploy.

  • Uploads your contract source code (ABIarrow-up-right) to IPFSarrow-up-right

  • Open the deploy flow in the dashboard

From the dashboard, you will need to first enter the values for our contract's constructor:

  • _name: The name of our contract

  • _symbol: The symbol or "ticker" given to our contracts tokens

  • _royaltyRecipient: The wallet address that will receive the royalties from secondary sales

  • _royaltyBps: The basis points (bps) that will be given to the royalty recipient for each secondary sale, e.g. 500 = 5%

Finally, select the Ancient8 Testnet as the networkarrow-up-right you want to deploy to, and click Deploy Now.

circle-info

INFO

For production / mainnet deployments select Ancient8 Mainnet as the network rather than Ancient8 Testnet.

Once your contract is deployed, you'll be redirected to a dashboardarrow-up-right for managing your contract.

Interacting with your contractarrow-up-right

Thirdweb provides SDKs for various programming languages, including Reactarrow-up-right, React Nativearrow-up-right, TypeScriptarrow-up-right, Pythonarrow-up-right, Goarrow-up-right, and Unityarrow-up-right.

To interact with your smart contract, you can use the thirdweb CLIarrow-up-right to create a web application that is pre-configured with the thirdweb React SDKarrow-up-right.

To create a web application preconfigured with the thirdweb SDK, run:

This will kick off an interactive series of questions to help you get started:

Exploring the projectarrow-up-right

The create command generates a new directory with your project name. Open this directory in your text editor.

Inside the index.tsxarrow-up-right file, you'll find the ThirdwebProviderarrow-up-right wrapping the entire application.

This wrapper allows us to use all of the React SDKarrow-up-right's hooks and UI Componentsarrow-up-right throughout the application, as well as configure an activeChain; which declares which chain our smart contracts are deployed to.

Since we deployed our smart contract to the Ancient8 Testnet, we'll set the activeChain to Ancient8 Testnet:

Interacting with the contractarrow-up-right

To connect to your smart contract in the application, provide your smart contract address (which you can get from the dashboardarrow-up-right) to the useContractarrow-up-right hook like so:

You can now call any function on your smart contract with useContractReadarrow-up-right and useContractWritearrow-up-right hooks.

For example, you can call useContractRead to get the name of the contract:

The thirdweb SDK also provides hooks for various interfaces and extensionsarrow-up-right that make reading and writing data easier. For example, we could use the ERC721 hooksarrow-up-right to fetch the metadata for our NFT contract.

For more information on interacting with smart contracts using the thirdweb SDK, visit the thirdweb developer documentationarrow-up-right.

Deploying the projectarrow-up-right

To host your application on IPFSarrow-up-right, run the following command:

This command uses Storagearrow-up-right to:

  • Create a production build of your application

  • Upload the build to IPFS

  • Generate a URL where your app is permanently hosted.

That's it! You now have a web application that interacts with smart contracts deployed to Ancient8 Testnet!

Last updated