Using Hardhat
Guide on deploying a smart contract on DuckChain using Hardhat, a popular framework for deploying and verifying smart contracts.
Initial Setup:
Get some test TON from the DuckChain testnet faucet.
Install Hardhat and its dependencies:
npm install --save-dev ethers hardhat @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers dotenv
Initialize the project:
npx hardhat init
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
Create
Storage.sol
in thecontracts
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; } }
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; });
Install Hardhat toolbox if not already installed:
npm install --save-dev @nomicfoundation/hardhat-toolbox
Compile and deploy the contract:
npx hardhat compile npx hardhat run scripts/deploy-storage.js --network DuckChainTestnet
Last updated