I am trying to compile my smart contracts using truffle pet-shop. I have the following contract in directory election/contracts/election.sol ;

pragma solidity >=0.4.0 <0.6.0;
contract Election{
    string public candidate;
    constructor() public{

The migration file to deploy contracts in directory election/migrations/2_deploy_contracts1.js is as follows;

var Election1=artifacts.require("election.sol");

I am using the following command to migrate the contracts:

truffle migrate

And I am getting the following results:

Compiling your contracts...
> Compiling .\contracts\Election.sol
> Compiling .\contracts\election.sol
> Artifacts written to D:\Notes\BCS\Semester 8\FYP\Practise Coding\dapp university 2 hr video code\election\build\contracts
> Compiled successfully using:
   - solc: 0.5.8+commit.23d335f2.Emscripten.clang

Starting migrations...
> Network name:    'development'
> Network id:      5777
> Block gas limit: 0x6691b7

Error: Error: Migration D:\Notes\BCS\Semester 8\FYP\Practise Coding\dapp university 2 hr video code\election\migrations\2_deploy_contracts1.js invalid or does not take any parameters
    at Object.run (C:\Users\mk141\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\truffle-migrate\index.js:92:1)
    at process._tickCallback (internal/process/next_tick.js:68:7)
Truffle v5.0.30 (core: 5.0.30)
Node v10.16.1

Its also compiling Election.sol because I renamed election.sol to Election.sol and it stores election.sol in cache perhaps.

As you can see above its giving Error:Migration 2_deploy_contracts invalid or does not take any parameters at Object.run() and i don't know how to resolve it.

  • 1
    Remove build/ directory and try again. – Ismael Aug 4 '19 at 15:14
  • It's giving the same error. First time when i migrated it gives no error. But now it's giving that error. Even i created a new pet-shop box and created the new contract and migration file in it – Zeeshan Ahmad Khalil Aug 4 '19 at 15:26
  • But your comment is helpful in many other things – Zeeshan Ahmad Khalil Aug 5 '19 at 9:30

I was making a mistake in 2_deploy_contracts1.js file. There is module.exports instead of module.export. So the new 2_deploy_contracts1.js file will be;

var Election1=artifacts.require("election.sol");

Also, I was using the following command to migrate again;

truffle migrate

Instead, I should use the following command if I am migrating again;

truffle migrate --reset

We use this command because we already migrated our smart contracts in the built folder. This command will remove all previously migrated files in the built folder and add new migrated files of smart contracts.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.