The Ultimate Guide to the CLI
In this guide, we will show you how you can use the CLI to create a full web3 application. The CLI is a tool that helps you perform the most common actions of building a full-stack web3 application.
Creating A Smart Contract
Creating smart contracts with proper configuration can be a lengthy task. The CLI helps you create new Solidity projects using either Hardhat or Foundry/Forge and allows you to start with pre-configured contracts with just one command:
npx thirdweb create contract
This kicks off an interactive series of questions to create a new Solidity project and set up your smart contract with the tools you prefer.
You can choose the project name, project type (Hardhat or Forge), type of contract to start with (ERC20, ERC721, ERC1155, or empty contract), and any extensions related to the type of the contract selected:
Now your chosen project is created with @thirdweb-dev/contracts
package already installed; so that you can utilize any of the functionality available inside the ContractKit!
Compiling Smart Contracts & Detecting Features
The CLI can compile your contract and detect any standards you've used in your custom contracts (such as ERC-20, ERC-721, Permissions, etc.).
This helps you identify what functionality will be unlocked for you in the dashboard and SDK when you deploy your smart contract to the blockchain
You can do that by running the following command in the terminal:
npx thirdweb build
This will compile your contract and show you all the detected extensions, like so:
Deploying Smart Contracts to the Blockchain
Deploy allows you to ship your smart contract to the blockchain of your choice without ever exposing your private key.
Once you've created your contract with the create
command and are satisfied with the implemented features shown by the build
command, you're ready to run deploy
to kickstart the deployment process:
npx thirdweb deploy
The CLI will then detect the project type (Hardhat, Truffle, or Solc), and perform the following actions:
- Compile all the contracts in the current directory.
- Allow you to select which contract(s) you want to deploy.
- Upload your contract source code (ABI) to IPFS.
- Open the deploy flow in the dashboard for you to select one of our supported networks to deploy to.
Releasing Smart Contracts
If you're building a protocol or smart contract standard that is intended for other developers to deploy, you can use the release
command.
Using the release
command, you publish a new version of your smart contract to our on-chain registry, where anyone can view and deploy it from the explore page.
To release your contract, run the following command in your project directory:
npx thirdweb release
This will compile the contract and upload the contract data to IPFS. Then you will be redirected to thirdweb dashboard in your browser to further the process.
Creating a Web3 Application
Now your smart contract is deployed to the blockchain, you can create a new web application to interact with it. Using the create
command, you can create frontend applications with the SDK installed and pre-configured:
npx thirdweb create app
After running the above command, you will be asked some basic preferences about your app, for example, the name, framework and the language you choose to use.
Deploying Your Application
The CLI also has built-in decentralized storage capabilities that allow you to upload and host your application (or any other file) on IPFS.
Using the CLI, you can now deploy your site to IPFS with just a single command!
yarn deploy
Under the hood, this runs the thirdweb upload
command and uploads the build output directory of your web application to IPFS, and generates a URL where your application is hosted.
Conclusion
In this guide, we saw how you can use thirdweb CLI during your dApp development process and how it can make development significantly easier for you.
If you have any questions regarding this guide, please join our Discord server and share them with us!