DuckChain’s Diary
  • 1. DuckChain overview
    • 1.1 What’s DuckChain?
    • 1.2 Background
    • 1.3 Vision
    • 1.4 Solutions
  • 2. Users & Developers
    • 2.1 DuckChain for Users
    • 2.2 DuckChain for Developers
    • 2.3 Developer Hub
      • 2.3.1 Network Information
        • Mainnet
        • Testnet
        • Bridges
        • Other General Contracts
      • 2.3.2 Builder Guide
        • Gas
        • EVM Wallet
        • Deploying Smart Contracts
          • Using Hardhat
          • Using Foundry
          • Run a DuckChain Node
          • Links and Tools
    • 2.4 Ecosystem
  • 3. DuckChain Architecture
    • 3.1 Overview
    • 3.2 Framework
    • 3.3 Pool Infrastructure
      • Decentralized Oracle Layer (DOL)
      • Decentralized Asset Verify Layer
      • Unified Gas System
      • Cross-Chain Interoperability
      • DuckChain Execution Layer
      • Driving Value with Pool Infrastructure
    • 3.4 DuckChain’s Interoperability
    • 3.5 Safety
  • 4. DuckChain AI Module
    • 4.1 Overview
    • 4.2 Key Features
    • 4.3 Technical Infrastructure
  • 5. Roadmap
    • 5.1 The Duck Journey
    • 5.2 Future Plans
  • 6. $DUCK: Governance and Ecosystem Token
    • 6.1 Overview
    • 6.2 Token Allocation
    • 6.3 $DUCK Release Schedule
    • 6.4 Token Utility
  • 7. Community
    • 7.1 Social & Community Links
    • 7.2 Feedback and Engagement
    • DuckChain Featured In News
  • 8. Appendices
    • 8.1 Glossary
    • 8.2 FAQs
Powered by GitBook
On this page
  1. 2. Users & Developers
  2. 2.3 Developer Hub
  3. 2.3.2 Builder Guide
  4. Deploying Smart Contracts

Using Hardhat

Guide on deploying a smart contract on DuckChain using Hardhat, a popular framework for deploying and verifying smart contracts.

Initial Setup:

  1. Get some test TON from the DuckChain testnet faucet.

  2. Install Hardhat and its dependencies:

    npm install --save-dev ethers hardhat @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers dotenv
  3. Initialize the project:

    npx hardhat init
  4. Open hardhat.config.js and add the following:

    require("dotenv").config();
    require("@nomicfoundation/hardhat-toolbox");
    
    module.exports = {
      solidity: "0.8.9",
      paths: {
        artifacts: "./src",
      },
      networks: {
        DuckChainTestnet: {
          url: `https://testnet-rpc.duckchain.io`,
          accounts: [process.env.ACCOUNT_PRIVATE_KEY],
        },
      },
    };

Add Contract Code and Deployment Script

  1. Create Storage.sol in the contracts folder with the following code:

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.9;
    
    contract Storage {
        uint256 _count = 0;
    
        function set(uint256 count) public {
            _count = count;
        }
    
        function get() public view returns (uint256){
            return _count;
        }
    }
  2. Create a deployment script deploy-storage.js:

    const hre = require("hardhat");
    
    async function main() {
        const deployedContract = await hre.ethers.deployContract("Storage");
        await deployedContract.waitForDeployment();
        console.log(
            `Storage contract deployed to https://testnet-scan.duckchain.io/address/${deployedContract.target}`
        );
    }
    
    main().catch((error) => {
        console.error(error);
        process.exitCode = 1;
    });
  3. Install Hardhat toolbox if not already installed:

    npm install --save-dev @nomicfoundation/hardhat-toolbox
  4. Compile and deploy the contract:

    npx hardhat compile
    npx hardhat run scripts/deploy-storage.js --network DuckChainTestnet
PreviousDeploying Smart ContractsNextUsing Foundry

Last updated 5 months ago