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 Truffle ?
  • Step-by-Step Guide to Deploy Contract
  • 1. Install Truffle
  • 2. Initialize Truffle Project
  • 3. Write the Contract
  • 4.Compile the Contract
  • 5.Write the Deployment Script
  • 6.Configure the Network
  • 7.Deploy the Contract
  1. GETTING STARTED
  2. Developer Guide
  3. Deploy Smart Contracts
  4. TEP-1155

Using Truffle

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

What is Truffle ?

Truffle is a development framework for Ethereum and Ethereum-compatible blockchains such as TAN-chain. It provides a suite of tools for smart contract development, including a built-in compiler, a testing framework, and scripts to deploy contracts.

Step-by-Step Guide to Deploy Contract

Follow these steps to deploy a TEP1155 contract using Truffle:

1. Install Truffle

Ensure you have Node.js and npm installed. Then, install Truffle globally:

npm install -g truffle

2. Initialize Truffle Project

Create a new directory for your project:

mkdir TEP1155Project
cd TEP1155Project

Initialize the project with Truffle:

truffle init

This command creates a basic Truffle project structure with the following directories:

  • contracts: Where your smart contracts go.

  • migrations: Where deployment scripts go.

  • test: Where your test scripts go.

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.Compile the Contract

Run the following command to compile your contract:

truffle compile

This command compiles the contracts in the contracts directory and generates the necessary artifacts in the build/contracts directory.

5.Write the Deployment Script

Create a new file 1_deploy_contracts.js in the migrations directory and add the following content:

const TEP1155NFT = artifacts.require("TEP1155NFT");

module.exports = function(deployer) {
  deployer.deploy(TEP1155NFT);
};

6.Configure the Network

Install truffle-hdwallet-provider and dotenv:

npm install truffle-hdwallet-provider dotenv

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 truffle-config.js file to include the Taral-chain network configuration. For example:


const HDWalletProvider = require("truffle-hdwallet-provider");
require("dotenv").config();

const mnemonic = process.env.YOUR_PRIVATE_KEY;

module.exports = {

  networks: {
    
    taral: {
      provider: () => new HDWalletProvider(mnemonic,"devnet-rpc1.tanledger.com"),
      network_id: 4442,
      chainId:4442
    }
   
  },

  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
      version: "0.8.20", // Fetch exact version from solc-bin (default: truffle's version)
   
    }
  },
};

7.Deploy the Contract

Run the following command to deploy the contract to the specified network:

truffle migrate --network tan

Congratulations!! You have successfully deployed your TEP1155 token contract on the TAN-chain network using Truffle. This guide covered the entire process from setting up the Truffle project to deploying the contract.

PreviousUsing Remix ideNextUsing Hardhat

Last updated 4 months ago

🚀
👨‍💻
📃