Deploying Contract - Error with Box.sol and Truffle

I've got a problem using the npx truffle migrate --network development command while following the tutorial on your site (
The Box.sol Contract compiles successfully but then i get the following message:

Compiling your contracts...
> Compiling .\contracts\Box.sol
> Artifacts written to C:\Users\marco\boilerplates\contracttester\build\contracts
> Compiled successfully using:
   - solc: 0.8.17+commit.8df45f5f.Emscripten.clang

Starting migrations...
> Network name:    'development'
> Network id:      1675505810979
> Block gas limit: 6721975 (0x6691b7)


modules.exports = async function (deployer) {

ReferenceError: modules is not defined
    at C:\Users\marco\boilerplates\contracttester\migrations\2_deploy.js:3:1
    at Script.runInContext (node:vm:141:12)
    at Object.file (C:\Users\marco\boilerplates\contracttester\node_modules\truffle\build\webpack:\packages\require\dist\index.js:90:1)
    at Migration.<anonymous> (C:\Users\marco\boilerplates\contracttester\node_modules\truffle\build\webpack:\packages\migrate\dist\src\Migration.js:78:1)
    at (<anonymous>)
    at fulfilled (C:\Users\marco\boilerplates\contracttester\node_modules\truffle\build\webpack:\packages\migrate\dist\src\Migration.js:28:43)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
Truffle v5.7.5 (core: 5.7.5)
Node v16.19.0


// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Box {
    uint256 private _value;

    // Emitted when the stored value changes
    event ValueChanged(uint256 value);

    // Stores a new value in the contract
    function store(uint256 value) public {
        _value = value;
        emit ValueChanged(value);

    // Reads the last stored value
    function retrieve() public view returns (uint256) {
        return _value;


const Box = artifacts.require('Box');

modules.exports = async function (deployer) {
    await deployer.deploy(Box);

Since I'm still learning I have no idea what this error tells me. Any help would be appreciated.

you can also use

Makes process so easy and faster to compile and deploy and test codes.

1 Like

Thanks for the answer. I know remix but as far as i know you can't run automated tests in remix, can you? Or am I wrong with this?

Edit: I just checked. Is deploying through remix with my local ganache provider a possible solution? I would deploy it and than run tests with web3. I'll try that tomorrow. Sadly I have no more time today....

Another Edit: I tried it and it works. I deployed the contract with remix and my local ganache provider. After that i copied the contract address to my node.js testclass and created an instance of the contract with the same ganache provider. After that I can use the contract for my tests.
It's a little complicated but at this moment I'll take everything I can get :slight_smile:

1 Like

It should be module, not modules.


Oh snap of course. Tank you. What a rooke mistake. Now it works like a charm. Tested it with multiple Contracts. Now I use the compiled and deployed Contract to Interact with through web3 and run my tests