Skip to main content

Deploying a smart contract with thirdweb

thirdweb is an end-to-end framework for smart contract development and deployment.

It enables developers to deploy, standard contracts such as ERC-20, ERC-721, or ERC-1155, etc. without writing a line of code. More of this is discussed in the via thirdweb Explore section.

Furthermore, developers looking to develop and deploy custom smart contracts can use the Solidity SDK provided by thirdweb, among others such as TypeScript SDK and Unity SDK. However, for this guide, we will mainly talk about the thirdweb Explore and the Solidity SDK.

Features:

  • Explore: Ready to deploy pre-built contracts.
  • Build (Solidity SDK): Write custom smart contracts.
  • Deploy: Support for contract deployment built for any use case.
  • Publish: Publish your contracts onchain.
  • Interact: Interact with smart contracts and integrate smart contracts directly into your app.

Deploying pre-built contracts via thirdweb Explore

In case you want to deploy a pre-built contract without any customization, thirdweb offers a convenient way to do so with Explore. Check out the following video for a quick introduction to Explore:

note

Before you try out the following guides, please ensure that your wallet is connected to Lisk's Network and it has sufficient funds in it. For more information, see the Wallet funds section.

The following videos describe step-by-step, how to deploy different tokens with pre-built contracts on Lisk.

via Solidity SDK

Prerequisites

Node.js v18+

Download and install Node v18+.

If you are using nvm to manage your node versions, you can just run nvm install 18.

Installing and Configuring thirdweb

To develop custom contracts, it is required to download and configure thirdweb.

  1. To install thirdweb run the following command:
    npm i -g thirdweb
  2. Set up your thirdweb API key.

Logging in with your API key

  1. The next step is to log in to thirdweb via CLI, so to do that type the following:
    thirdweb login
  2. Once, you execute the aforementioned command, the terminal will open a browser window where it will ask you to authenticate the device:
    .......

    💎 thirdweb v0.13.60 💎

    Automatically attempting to open a link to authenticate with our dashboard...

    If the browser doesn't open, please use this link to authenticate:

    https://thirdweb.com/cli/login?payload=%7B%22payload%22%3A%7B%22type%22%3A%22evm%22%2C%22domain%22%3A%22thirdweb.com%22%2C%22address%22%3A%220x4fA5f77Fadcc319c626b28Ea6260FB0c3Ba6e41C%22%2C%22statement%22%3A%22Please%20ensure%20that%20the%20domain%20above%20matches%20the%20URL%20of%20the%20cuhdksjahjkdhkshajkdhkshakjhsjhdsajkhhdhs

    ⠙ Waiting for a response from the dashboard
  3. Once you authenticate via the browser, the terminal will log the following message:
    Successfully linked your account to this device 
  4. You can verify your login status by re-running the thirdweb login command.
    💎 thirdweb v0.13.60 💎

Creating a project

The first step of deploying smart contracts to Lisk is to set up your development environment by creating a project. The thirdweb supports two of the most popular smart contracts development frameworks such as Foundry and Hardhat.

For this guide, we are using Foundry for smart contract development. However, you can use Hardhat if you are more comfortable with that. The project creation steps are similar for both Foundry and Hardhat.

  1. For Foundry, install its prerequisites on your system before proceeding with the creation of a thirdweb project.

  2. Once, the aforementioned is installed, proceed with the following:

    npx thirdweb create
  3. Choose Contract as the type of your project and give an appropriate name to your project.

    .......

    💎 thirdweb v0.13.60 💎

    ✔ What type of project do you want to create? › Contract
    ✔ What is your project named? … thirdweb-contracts
  4. Next, choose Forge as the framework, NFT as the name of the contract, ERC721 as the type of smart contract, and None for the extensions option.

    info

    In case you want to use the Hardhat framework, choose Hardhat instead of Forge in the following dialogue.

    ✔ What framework do you want to use? › Forge
    ✔ What will be the name of your new smart contract? … NFT
    ✔ What type of contract do you want to start from? › ERC721
    ✔ What extensions do you want to add to your contract? › None
  5. thirdweb will install all the relevant dependencies and set up a contract project for you.

    Execution logs of the thirdweb contract project creation
    Creating a new thirdweb contracts project in /Users/XYZ/Lightcurve-Code/L2/thirdweb-contracts.

    Downloading files. This might take a moment.
    Installing packages. This might take a couple of minutes.

    yarn install v1.22.19
    warning ../../../package.json: No license field
    info No lockfile found.
    [1/4] 🔍 Resolving packages...
    [2/4] 🚚 Fetching packages...
    [3/4] 🔗 Linking dependencies...
    [4/4] 🔨 Building fresh packages...
    success Saved lockfile.
    ✨ Done in 9.73s.

    Initialized a git repository.

    Success! Created thirdweb-contracts at /Users/XYZ/Lightcurve-Code/L2/thirdweb-contracts

    Inside that directory, you can run several commands:

    yarn build
    Compiles your contracts and detects thirdweb extensions implemented on them.

    yarn deploy
    Deploys your contracts with the thirdweb deploy flow.

    yarn publish
    Publishes your contracts with the thirdweb publish flow.

    We suggest that you begin by typing:

    cd thirdweb-contracts
  6. Foundry applications created with thirdweb have a similar directory structure to the following:

    .
    ├── .github
    ├── .cache
    ├── lib
    ├── node_modules
    ├── out
    ├── src
    │   └── NFT.sol
    ├── test
    │ └── Contract.t.sol
    ├── .gitignore
    ├── .gitmodules
    ├── foundry.toml
    └── README.md

Creating the smart contract

For ease and security, thirdweb already provides base contracts, which can be easily customized via code. Since we chose to create an ERC721 token earlier, an NFT.sol file will be present in the src/ folder. The NFT.sol will already have the base code required for an NFT contract.

src/NFT.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@thirdweb-dev/contracts/base/ERC721Base.sol";

contract NFT is ERC721Base {
constructor(
address _defaultAdmin,
string memory _name,
string memory _symbol,
address _royaltyRecipient,
uint128 _royaltyBps
)
ERC721Base(
_defaultAdmin,
_name,
_symbol,
_royaltyRecipient,
_royaltyBps
)
{}
}

Building the smart contract

Once the smart contract's code is ready, it must be built using thirdweb.

  1. To do that, simply run:
    npx thirdweb build
  2. If the smart contract doesn't have any errors, you will see the following output on the terminal:
    .......

    💎 thirdweb v0.13.62 💎

    ✔ Detected project type: foundry
    ✔ Compilation successful
    ✔ Choose which contracts to run detection on · NFT


    🔎 Detected extension on NFT
    ✔️ ERC721
    ✔️ ERC721Burnable
    ✔️ ERC721Supply
    ✔️ ERC721AQueryable
    ✔️ ERC721Mintable
    ✔️ ERC721BatchMintable
    ✔️ Royalty
    ✔️ ContractMetadata
    ✔️ Ownable
    ✔️ Fallback

    ℹ Suggested extensions
    - ERC721Enumerable - https://portal.thirdweb.com/interfaces/erc721enumerable
    - ERC721LazyMintable - https://portal.thirdweb.com/interfaces/erc721lazymintable
    - ERC721SignatureMintV1 - https://portal.thirdweb.com/interfaces/erc721signaturemintv1
    - ERC721SignatureMintV2 - https://portal.thirdweb.com/interfaces/erc721signaturemintv2
    - ERC721TieredDrop - https://portal.thirdweb.com/interfaces/erc721tiereddrop
    - ERC721ClaimCustom - https://portal.thirdweb.com/interfaces/erc721claimcustom
    - ERC721ClaimZora - https://portal.thirdweb.com/interfaces/erc721claimzora
    - ERC721ClaimConditionsV1 - https://portal.thirdweb.com/interfaces/erc721claimconditionsv1
    - ERC721ClaimConditionsV2 - https://portal.thirdweb.com/interfaces/erc721claimconditionsv2
    - ERC721ClaimPhasesV1 - https://portal.thirdweb.com/interfaces/erc721claimphasesv1
    - ERC721ClaimPhasesV2 - https://portal.thirdweb.com/interfaces/erc721claimphasesv2
    - ERC721SharedMetadata - https://portal.thirdweb.com/interfaces/erc721sharedmetadata
    - ERC721LoyaltyCard - https://portal.thirdweb.com/interfaces/erc721loyaltycard
    - ERC721UpdatableMetadata - https://portal.thirdweb.com/interfaces/erc721updatablemetadata
    - Permissions - https://portal.thirdweb.com/interfaces/permissions

    ℹ Once you're done writing your contracts, you can run the following command to deploy them:

    yarn deploy

Deploying the smart contract

All checks passed, which means that the smart contract is ready to be deployed using thirdweb.

  1. To do that, simply run:

    npx thirdweb deploy
  2. If the smart contract doesn't have any errors, you will see the following output on the terminal:

    .......

    💎 thirdweb v0.13.60 💎

    ✔ Detected project type: foundry
    ✔ Compilation successful
    ✔ Choose which contract(s) to deploy · NFT
    ✔ Upload successful
    ✔ Open this link to deploy your contracts: https://thirdweb.com/contracts/deploy/QmSJExQJfPYFuaRZuDu9XRR2jUu9yp3kaFX3Sdc1KRWxiP
  3. The terminal will also open a browser window, directing towards a unique URL, as highlighted above.

  4. Fill out the form as suggested in the Fill Parameter section.

  5. Once you fill out the details of the ERC721 smart contract, click on the Deploy Now button and it will deploy the contract to the chosen network of your wallet.

info

If you want to test your Foundry-based contract, follow the steps mentioned in the Testing the Smart Contract guide.

Interacting with the Smart Contract

Once the contract is deployed, you can interact with it via Explore. The following videos describe step-by-step, how to interact with different token contracts on Lisk.