> For the complete documentation index, see [llms.txt](https://docs.tan.live/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.tan.live/getting-started/developer-guide/deploy-smart-contracts/tep-721/using-truffle.md).

# Using Truffle

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

## 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.<br>

## Step-by-Step Guide to Deploy Contract

Follow these steps to deploy a TEP721 contract using Truffle:<br>

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

**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.<br>

## 3.Write the Contract

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

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

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

contract TEP721NFT is ERC721, Ownable {
    uint256 private _nextTokenId;

    constructor()
        ERC721("TEP721NFT", "TPFT")
        Ownable(msg.sender)
    {}

    function safeMint(address to) public onlyOwner {
        uint256 tokenId = _nextTokenId++;
        _safeMint(to, tokenId);
    }
}
```

## 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.<br>

## 5.Write the Deployment Script

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

```
const TEP721NFT = artifacts.require("TEP721NFT");

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

## 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 TAN-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,"https://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 TEP-721 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.
