Building with AppChain
Deploying smart contracts

Deploying Smart Contracts

Using Thirdweb

How to Deploy a Smart Contract on AppChain with Thirdweb CLI & Smart Contract Dashboard

Thirdweb is a complete web3 development framework that provides everything you need to connect your apps and games to decentralized networks. AppChain is now integrated with Thirdweb, allowing you to use all these fantastic features to deploy and interact with your smart contracts quickly.

This guide assumes you have Sepolia ETH and have bridged it to the AppChain Testnet Network.

1. Download the Thirdweb CLI

We’ll go through the steps of installing and running the Thirdweb CLI, but if you encounter any issues with these steps, please refer to the official documentation.

To download the Thirdweb CLI globally, open a terminal and run the following command:

npm i -g thirdweb

Now try running:

thirdweb --version

If the CLI is installed correctly, you will be prompted to go to the installed version.

2. Create the Local Environment

Let’s create a new project to work on our local machine using the command:

npx thirdweb create

You will be prompted with a menu with different options to help you set up your environment for coding the smart contract. For this tutorial, we will deploy an ERC-20 token and add the Drop extension from Thirdweb. This setup will allow a basic ERC-20 token with features to mint, burn, and airdrop tokens from the dashboard. What’s even better is that these contracts are all audited and ready to deploy!

After a few seconds, you should now have a folder called “my-appchain-token” or whatever you named your project.

To modify your smart contract, you can launch Visual Studio Code (or your preferred code editor) and access the designated project folder. We will leave it as is since we want to focus on showing the deployment process. We already have a fully functional smart contract code thanks to Thirdweb’s templates.

3. Create a ThirdWeb API Key

Thirdweb services require an API key, so let’s create one. There is an official tutorial here, but let’s go through it quickly.

To get an API key, go to https://thirdweb.com/dashboard/settings/api-keys (opens in a new tab).

Connect your wallet, and you will be prompted with a message to sign from Metamask (you can use other wallets if you prefer). Once your wallet is connected, you should be able to switch to AppChain network and also create an API Key.

It’s very important that you now save your Client ID and Secret Key securely. Don’t lose this because if you do, you must create a new API key.

4. Deploy

Now, when your contract is ready to deploy, run the following command at the root of your project:

npx thirdweb deploy

You should be prompted with something similar to this:

IMAGE

If your browser doesn’t automatically pop up with the link to deploy your contract, just copy the link shown in the terminal and paste it into a browser.

A screen like the one below should appear — just fill in the fields with the names and values you want for your contract parameters.

thirdweb-select-network

Select the AppChain network from the search list.

When you are done, just hit Deploy Now. This will cost you gas paid in ETH. This transaction might fail if you don’t have enough ETH on AppChain for gas.

Also, make sure to tick the box to add a dashboard for our contract. This will give us some exciting features to interact with our contract later on.

You will also have to sign a transaction to approve the dashboard, but this step is gasless.

That’s it! You have successfully deployed a smart contract to AppChain with the Thirdweb CLI!

5. Smart Contract Dashboard

To track all your smart contracts and easily interact with them, Thirdweb provides us with a contracts dashboard. Just go to https://thirdweb.com/dashboard/contracts (opens in a new tab) and you will see all your deployed contracts.

Now just click on the smart contract you want to see the whole dashboard and start playing around!

For example, you can go to the explorer tab and see all the read-and-write methods your contract has and even use them. It’s super easy to just look at variables and manually test out some methods.

One of the features we liked the most was the “Build” tab in your smart contract dashboard. This section will have a lot of examples of code snippets to connect with your smart contract programmatically from an app. You can choose between several languages and frameworks, such as JavaScript, React, and Python.

Congratulations! Now you have created and deployed a smart contract on AppChain using the Thirdweb CLI.

Last updated on