Tan Docs
  • 📚INTRODUCTION
  • 📖BASIC KNOWLEDGE
    • 🌐⛓️What is Blockchain
    • EVM
    • 💻Node
  • WELCOME TO TAN NETWORK
    • 💡About TAN
    • 🪙TAN (Native Coin of Tan)
    • 🫂Community
  • 🚀GETTING STARTED
    • 👨‍💻Developer Guide
      • 💻Nodes And Validators
        • ⬇️Install TAN-Chain
        • 👨‍🏫Full Node Instructions
        • 🔏How to Stake TAN?
        • Become a Validator🤝
        • 🔓How to Unstake TAN?
      • RPC
      • TAN Testnet
      • TAN explorers
      • 📃Deploy Smart Contracts
        • TEP-20
          • Using Remix ide
          • Using Truffle
          • Using Hardhat
        • TEP-721
          • Using Remix ide
          • Using Truffle
          • Using Hardhat
        • TEP-1155
          • Using Remix ide
          • Using Truffle
          • Using Hardhat
    • 🦊Add TAN to Metamask
    • 🪙Get Testnet Funds
    • Core Concepts
      • Genesis File
      • Consensus
      • Proof of Stake(Pos)
      • ⚙️TAN Consensus(BPoS)
        • 💰Validators Reward
        • Burn Subsidy
        • Ecosystem Incetives
      • Scalability
  • Governance
    • TAN Improvement Proposal
  • ❓FAQ's
Powered by GitBook
On this page
  • What is Hardhat ?
  • Step-by-Step Guide to Deploy Contract
  • 1.Install Hardhat
  • 2.Initialize Hardhat Project
  • 3.Write the Contract
  • 4.Write the Deployment Script
  • 5.Configure Network
  • 6.Deploy the Contract
  1. GETTING STARTED
  2. Developer Guide
  3. Deploy Smart Contracts
  4. TEP-1155

Using Hardhat

Here is a detailed explanation of what Hardhat is and a step-by-step guide on how to deploy a TEP1155 contract using hardhat:

What is Hardhat ?

Hardhat is a development environment for Ethereum and Ethereum-compatible blockchains. It provides a comprehensive toolset for smart contract development, testing, debugging, and deployment.

Step-by-Step Guide to Deploy Contract

Follow these steps to deploy a TEP1155 contract using Hardhat:

1.Install Hardhat

Ensure you have Node.js and npm installed. Then, create a new directory for your project and initialize it with Hardhat:

mkdir TEP1155Project
cd TEP1155Project
npm init -y
npm install --save-dev hardhat

2.Initialize Hardhat Project

Run the following command to initialize a Hardhat project:

npx hardhat

Follow the prompts to create a new Hardhat project, selecting the appropriate options for your needs.

3.Write the Contract

Create a new file TEP1155NFT.sol in the contracts directory and add your TEP1155NFT code:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.20;

import "@openzeppelin/contracts/token/ERC1155/ERC1155.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract TEP1155NFT is ERC1155, Ownable {
    constructor(address initialOwner) ERC1155("") Ownable(initialOwner) {}

    function mint(address account, uint256 id, uint256 amount, bytes memory data)
        public
        onlyOwner
    {
        _mint(account, id, amount, data);
    }

    function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data)
        public
        onlyOwner
    {
        _mintBatch(to, ids, amounts, data);
    }
}

4.Write the Deployment Script

Create a new file deploy.js in the scripts directory to write your deployment script:

async function main() {

  const [deployer] = await ethers.getSigners();
  console.log("Deploying the contracts with the account:",await deployer.getAddress());
  console.log("Account balance:", (await deployer.getBalance()).toString());
  
  const TEP1155NFT = await ethers.getContractFactory("TEP1155NFT");
  const token = await TEP1155NFT.deploy();
  await token.deployed({ gasLimit: 6000000 });

  console.log("TEP1155NFT address:", token.address);
}
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error);
    process.exit(1);
  });

5.Configure Network

Make sure to install the suggested versions of the packages:

npm install --save-dev @nomiclabs/hardhat-ethers@^2.2.3 @nomiclabs/hardhat-waffle@^2.0.6 @openzeppelin/contracts@^5.0.2 @uniswap/v3-periphery@^1.0.1 bignumber.js@^9.1.2 dotenv@^16.4.5 ethereum-waffle@^4.0.10 [email protected] hardhat@^2.22.4

Create a `.env` file in the root of your project directory to store your private key.

// In .env file

YOUR_PRIVATE_KEY = "YOUR_PRIVATE_KEY"

Update the hardhat.config.js file to include network configurations:

require("@nomiclabs/hardhat-waffle");

/** @type import('hardhat/config').HardhatUserConfig */
const privateKey = process.env.YOUR_PRIVATE_KEY;;
module.exports = {
  solidity: {
   version: "0.8.20",
   settings: {
    optimizer:{
      enabled:true,
      runs:1000,
      details:{yul:false},  
    }
   }
  },
  networks: {
    taral: {
      chainId: 4442,
      url: "https://devnet-rpc1.tanledger.coms",
      accounts: [privateKey],
    },
  },
};

6.Deploy the Contract

Run the deployment script with Hardhat:

npx hardhat run scripts/deploy.js --network tan

Congratulations!! You have successfully deployed your TEP1155 token contract using Hardhat. This guide covered the entire process from setting up the Hardhat project to deploying the contract.

PreviousUsing TruffleNext🦊Add TAN to Metamask

Last updated 4 months ago

🚀
👨‍💻
📃