Build and Deploy Your Smart Contract  using thirdweb.

Build and Deploy Your Smart Contract using thirdweb.

ยท

3 min read

Table of contents

No heading

No headings in the article.

Hello geeks,

So a few days back I was building crowd Funding Dapp when I came across thirdweb which is a web3 development framework. It was very much easy to deploy our smart contract and it also provide a dashboard through which we can interact with our smart contract.

So without wasting any time let's start with how can we deploy our smart contract in a few steps on thirdweb.

Let's Go ๐Ÿš€

  1. First Create a folder let's say "web3" in vs code and in the terminal initiate this command:-

    npx thirdweb@latest create --contract

    After running the above command you need to select the framework and type of contract.

  2. After the installation, You will these folders

    Open contract.sol in the contracts folder and write your smart contract

    Just for an example we will be taking hotel room smart contract

     //SPDX-License-Identifier: MIT
     pragma solidity ^0.8.0;
     contract MoodDiary {
         string mood;
         //set mood
         function setMood(string memory _mood)public{
             mood = _mood;
         }
         function getMood() public view returns(string memory){
             return mood;
         }
     }
    
  3. Install .dotenv and create a .env file

    npm i dotenv

    Go to your metamask wallet and copy the private key which you will get in the account details of the metamask wallet. (Don't share private key to anyone)

    If you haven't set up a meta mask wallet then do check out this link.

    In the .env file make the variable PRIVATE_KEY and paste the private key as its value.

    Also, you should have some goerli faucets in your wallet. Here is the link where you can get goerli faucets.

  4. Go to hardhat.config.js file where we will update the network section. if you are using goerli faucets this is the update which you need to make.

     /** @type import('hardhat/config').HardhatUserConfig */
     module.exports = {
       solidity: {
         version: '0.8.9',
         defaultNetwork:'goerli',
         networks:{
           hardhat:{},
           goerli:{
             url:'https://rpc.ankr.com/eth_goerli',
             accounts:[`0x${process.env.PRIVATE_KEY}`]
           }
         },
         settings: {
           optimizer: {
             enabled: true,
             runs: 200,
           },
         },
       },
     };
    
  5. Go to the terminal and run this command to deploy your smart contract

    npm run deploy

    After deployment, you will find a link in the terminal and open that link. It will direct you to thirdweb dashboard of your smart contract where first you need to connect your wallet and click on deploy.

    After deployment, it will you to the dashboard where you will find all your functions and variable in your smart contract.

You can interact with it, and test your smart contract. It also provides contract address which you can use it to connect with front-end.

Hope y'all found this article Helpful. Do check out my other articles and connect with me on twitter.

Thank You.

ย