Truffle development environment setup

We design and develop full-cycle blockchain solutions: from smart contract architecture to launching DeFi protocols, NFT marketplaces and crypto exchanges. Security audits, tokenomics, integration with existing infrastructure.
Showing 1 of 1 servicesAll 1306 services
Truffle development environment setup
Simple
~2-3 hours
FAQ
Blockchain Development Services
Blockchain Development Stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1218
  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1161
  • image_websites_belfingroup_462_0.webp
    Website development for BELFINGROUP
    853
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1047
  • image_logo-advance_0.png
    B2B Advance company logo design
    561
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    823

Truffle Development Environment Setup

Truffle Suite is one of the oldest smart contract development frameworks: compiler, migrations, test runner, and Ganache for local network. Despite Hardhat and Foundry taking most new projects, Truffle remains in production at hundreds of projects launched before 2021. Setup from scratch looks different from three-year-old tutorials.

Configuring truffle-config.js for Modern Projects

Key point — network and provider. To work with Infura or Alchemy:

const HDWalletProvider = require('@truffle/hdwallet-provider');

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545,
      network_id: "*", // Ganache
    },
    sepolia: {
      provider: () => new HDWalletProvider(
        process.env.MNEMONIC,
        `https://sepolia.infura.io/v3/${process.env.INFURA_KEY}`
      ),
      network_id: 11155111,
      gas: 5500000,
      confirmations: 2,
      timeoutBlocks: 200,
      skipDryRun: true
    }
  },
  compilers: {
    solc: {
      version: "0.8.20",
      settings: {
        optimizer: { enabled: true, runs: 200 },
        viaIR: true  // through Yul IR — better for complex contracts
      }
    }
  },
  plugins: ["truffle-plugin-verify"]
};

runs: 200 is a tradeoff between deployment cost and call cost. For contracts with high call frequency increase to 1000+.

Migrations: Order Matters

Migration files are numbered: 1_initial_migration.js, 2_deploy_token.js. Truffle tracks executed migrations via the Migrations contract on-chain. If a migration already ran — it's skipped on retry.

Typical migration with dependencies between contracts:

const Token = artifacts.require("MyToken");
const Staking = artifacts.require("StakingContract");

module.exports = async function(deployer, network, accounts) {
  await deployer.deploy(Token, "MyToken", "MTK", web3.utils.toWei("1000000"));
  const token = await Token.deployed();
  
  await deployer.deploy(Staking, token.address, accounts[0]);
};

Ganache Integration

Ganache 7.x runs as a package (@ganache/core) or CLI (ganache). For deterministic tests — fix the seed:

ganache --seed 42 --accounts 10 --defaultBalanceEther 1000

Or via ganache.fork for forking mainnet — like hardhat node --fork.

Tests in JavaScript and Mocha

Truffle uses Mocha + Chai. Contracts are available via artifacts.require. Async/await is supported:

const Token = artifacts.require("MyToken");

contract("MyToken", accounts => {
  it("mints initial supply to deployer", async () => {
    const token = await Token.deployed();
    const balance = await token.balanceOf(accounts[0]);
    assert.equal(balance.toString(), web3.utils.toWei("1000000"));
  });
});

Verify contract after deployment via truffle-plugin-verify:

truffle run verify MyToken --network sepolia

Timeline Estimates

Setting up Truffle from scratch: 2-3 hours. Includes network configuration, Ganache, basic migrations, test environment, and verification plugin.