# Using Truffle

There are a few technical requirements before we start. Please install the following:

* [Node.js v8+ LTS and npm](https://nodejs.org/en/) (comes with Node)
* [Git](https://git-scm.com/)

Once we have those installed, we only need one command to install Truffle:

Copy

```
npm install -g truffle
```

To verify that Truffle is installed properly, type **`truffle version`** on a terminal. If you see an error, make sure that your npm modules are added to your path.

> If you're new to Truffle then please follow the [Getting Started](https://www.trufflesuite.com/docs/truffle/quickstart) by truffle, To setup the truffle environment.

#### **truffle-config** <a href="#truffle-config" id="truffle-config"></a>

* Go to truffle-config.js
* Update the truffle-config with Ctex-network-crendentials.

Copy

```
Explainconst HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8545,            // Standard Ethereum port (default: none)
      network_id: "*",       // Any network (default: none)
    },
    ctex : {
      provider: () => new HDWalletProvider(mnemonic, `https://testnet-rpc.ctexscan.com`),
      network_id: 74152,
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },

  // Set default mocha options here, use special reporters etc.
  mocha: {
    // timeout: 100000
  },

  // Configure your compilers
  compilers: {
    solc: {
    }
  }
}
```

Notice, it requires mnemonic to be passed in for CTEX Chain network, this is the seed phrase for the account you'd like to deploy from. Create a new .secret file in root directory and enter your 12 word mnemonic seed phrase to get started. To get the seedwords from metamask wallet you can go to Metamask Settings, then from the menu choose Security and Privacy where you will see a button that says reveal seed words.

#### **Deploying on ctex Chain Network** <a href="#deploying-on-matic-network" id="deploying-on-matic-network"></a>

* Add IGT to your wallet using <https://faucet.ctexscan.com/>

Run this command in root of the project directory:

Copy

```
$ truffle migrate --network ctex
```

Contract will be deployed on CTEX Testnet, it look like this:

Copy

```
Explain2_deploy_contracts.js
=====================

   Replacing 'MyContract'
   ------------------
   > transaction hash:    0xc921b127afd0ff2e1e5127367dbaa10cb79f019a22749dd651fc339fb361171e
   > Blocks: 10            Seconds: 2
   > contract address:    0xF0B2F5AbE5A52B5BF85B2320A730D1Ed714c1af3
   > block number:        11578
   > block timestamp:     1287126898
   > account:             0x384E2C3a9354EB3590F4e0789c9B800a7456fbe8
   > balance:             5 CTEX
   > gas used:            1896986
   > gas price:           5 gwei
   > value sent:          0 CTEX
   > total cost:          0 CTEX

   Pausing for 2 confirmations...
   ------------------------------
   > confirmation number: 5 (block: 11585)
initialised!

   > Saving migration to chain.
   > Saving artifacts
   -------------------------------------
   > Total cost:                   0 CTEX


Summary
=======
> Total deployments:   3
> Final cost:          0 CTEX
```

> Remember your address, transaction\_hash and other details provided would differ, Above is just to provide an idea of structure.

**Congratulations!** You have successfully deployed **Helloctex** Smart Contract. Now you can interact with the Smart Contract.

You can check the deployment status here:[ ](https://testnet-rpc.ctexscan.com)<https://testnet-rpc.ctexscan.com>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://ctex-network.gitbook.io/developer-documentation/depolying-ctex-chain/using-truffle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
