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


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

module.exports = {
  networks: {
    development: {
      host: "",     // Localhost (default: none)
      port: 8765,            // Standard Huygen port (default: none)
      network_id: "*",       // Any network (default: none)
    mcpnet: {
      provider: () => new HDWalletProvider([privateKey], ``),
      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"


    "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


Last updated