Deploying Your First Smart Contract using ThirdWeb

posted 2 min read

Welcome to this beginner-friendly guide where I'll walk you through deploying your first smart contract using ThirdWeb.

Don't worry if you’re new to blockchain, I’ll explain everything in detail, step-by-step!

First things first, why should one choose ThirdWeb?

ThirdWeb simplifies smart contract deployment across various blockchains, such as Ethereum, Arbitrum, and Solana, eliminating the need for complex network configurations.

Now let's move on to:

Setting up MetaMask wallet

  1. First, go to MetaMask and create a wallet (if you don’t have one already).

  2. Choose the blockchain network for deploying your contract. In this guide, I’ve opted for the Sepolia.

    a. Add the Scroll Sepolia Testnet network to MetaMask. Refer to Scroll User Guide to make things easier.

    b. Now fund your wallet with testnet tokens. Head to Faucets - Claim FREE Testnet Tokens! - by AdiSuyash to obtain Scroll Sepolia Testnet tokens.

  3. Cool, you are all set with the wallet, the blockchain network, and testnet tokens too!

  4. To let you know, the procedures for adding any network to MetaMask are generally the same!

Sign up for a ThirdWeb account

  1. Head over to Thirdweb and create a new account using the same MetaMask Wallet that you created in the previous steps.

  2. Viola, you're all set with the ThirdWeb and MetaMask Wallet!

Now, let's proceed towards setting up the local development environment.

️ Setting up the local development evnironment

  1. Open up a folder in VS Code (or any code editor) and run the command: npx thirdweb create contract in the terminal.

  2. Next, choose forge as the framework. This step sets up the foundational structure for the smart contract.

  3. Next, install Foundry. Foundry is a smart contract development toolchain/framework. Head over to Foundry's documentation and install it as per their instructions.

  4. Next, we'll write our smart contract. In the root directory of the project, locate src/Contract.sol. Open it and copy-paste the following Solidity code:

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

contract SimpleContract {
    uint256 public counter;
    address public owner;

    constructor() {
        counter = 0;
        owner = msg.sender;
    }

    modifier onlyOwner() {
        require(msg.sender == owner, "Caller is not the owner");
        _;
    }

    function increment() public {
        counter++;
    }

    function decrement() public {
        require(counter > 0, "Counter cannot be negative");
        counter--;
    }

    function reset() public onlyOwner {
        counter = 0;
    }

    function getCounter() public view returns (uint256) {
        return counter;
    }
}

Deploying your smart contract

  1. Once you've written the contract code, deploy it by running the command npx thirdweb deploy in the terminal. This command initiates the deployment process, where ThirdWeb handles everything behind the scenes.

  2. After running the above command, you'll be automatically navigated to the ThirdWeb dashboard where you need to choose the blockchain network to which you want to deploy the contract. For this guide, let's go with Scroll Sepolia Network.

  3. Congrats! You've successfully deployed your first smart contract using ThirdWeb.

If you encounter any issues, feel free to DM me: AdiSuyash!

If you read this far, tweet to the author to show them you care. Tweet a Thanks

More Posts

How To Write Smart Contract With Scrypt.

Olukosi Ismaila - Dec 29, 2024

Using Docker As Stand-Alone Host For Deploying All-in-One Website or Code Base

Gift Balogun - Oct 17, 2024

Creating RESTful API Using Spring Boot for The First Time

didikts - Oct 14, 2024

JavaScript Tricks for Efficient Developers and Smart Coding

Mainul - Nov 30, 2024
chevron_left