# 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
   ```
