Using Thirdweb
How to deploy a smart contract on Mode with ThirdWeb CLI & Smart contract Dashboard
Last updated
How to deploy a smart contract on Mode with ThirdWeb CLI & Smart contract Dashboard
Last updated
Thirdweb is a complete web3 development framework that provides everything you need to connect your apps and games to decentralized networks. Mode 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 got Sepolia ETH and bridged to the Mode Testnet Network.
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.
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 the sake of this tutorial, we will be deploying an ERC-20 token and adding the Drop extension from Thirdweb. This will set up a basic ERC-20 token with the possibility to mint, burn, and airdrop tokens from the dashboard. Whatâs even better is that these contracts are all audited and ready to deploy!
Follow the following screenshot to create an example smart contract, or you can use your own code.
After a few seconds, you should now have a folder called âmy-mode-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.
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. 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 Mode network and also Create an API Key.
Follow the steps as shown below
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.
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:
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.
Select the Mode testnet network from the search list
A screen like the one below should appear; just fill in the fields with the names and values you want for your contract parameters. 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 Mode 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 Mode with the Thirdweb CLI!
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 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 Mode using the Thirdweb CLI. To learn more about Mode and how to turn your code into a business, join our Discord and say hello đ
If you want the next challenge, you can try registering a contract for the SFS following this guide: SFS - Registering a contract with Remix