# Truffle

## Installing

In order to use Truffle, we just need one command to install Truffle.

```
$ npm install -g truffle
```

You can confirm the installed truffle's version by typing **`truffle version`** on a terminal.

## Create a Project

The first step is to create a project using Truffle. Let's create a project called "MetaCCN".

* Create a new directory for your Truffle project and initialize it.

```
$ mkdir MetaCCN
$ cd MetaCCN
$ truffle init
```

* Once this operation is completed, you'll now have a project structure with the following items.

```
contracts/: Directory for Solidity contracts
migrations/: Directory for scriptable deployment files
test/: Directory for test files for testing your application and contracts
truffle-config.js: Truffle configuration file
```

## Create Your Contract

You can write your own smart contract in contracts/ directory.

## Compile Contract

To compile a Truffle project, change to the root of the directory where the project is located and then type the following into a terminal.

```
$ truffle compile
```

## Config Truffle for Mainnet

### truffle-config.js

```
const HDWalletProvider = require('@truffle/hdwallet-provider');
const privateKey= require('./secrets.json').privateKey;

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",     // Localhost (default: none)
      port: 8765,            // Standard Huygen port (default: none)
      network_id: "*",       // Any network (default: none)
    },
    mcpnet: {
      provider: () => new HDWalletProvider([privateKey], `https://mcpnet.ccn.org`),
      network_id: 971,
      confirmations: 10,
      timeoutBlocks: 200,
      skipDryRun: true
    },
  },

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

  // Configure your compilers
  compilers: {
    solc: {
      version: "^0.8.0", // A version or constraint - Ex. "^0.8.0"
    }
  }
}
```

### secrets.json

```
{
    "privateKey": "8dd7404640b7f48e90967ad86e6402cfc39163cd391e32e07042f6f5c0a9639d"
}
```

Notice, it requires private key to be passed in for Provider, this is the private key for the account you'd like to deploy from. Create a new secrets.json file in root directory and enter private key to get started. You have enough CCN in the account corresponding to this private key.

Run this command in root of the project directory:

```
$ truffle migrate --network mcpnet
```

## **Reference**

{% embed url="<https://trufflesuite.com/docs/truffle/getting-started/running-migrations.html>" %}


---

# 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://docs.oortech.com/oort/developers/mainnet-developers/smart-contract-developers/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.
