0

I am executing “truffle migrate” command but I am getting one reference error related to ‘adoption’ variable:there is no error related to compilation

2_deploy_contracts.js

ReferenceError: adoption is not defined at module.exports (absolute path/2_deploy_contracts.js:5:20) at Migration._load (/usr/local/lib/node_modules/truffle/build/webpack:/packages/migrate/migration.js:56:1) at at process._tickCallback (internal/process/next_tick.js:188:7) Truffle v5.1.27 (core: 5.1.27) Node v8.10.0

The 2-deploy_contracts.js of this project is given below which does not have any adoption variable defined:

var attacker = artifacts.require("Attacker");
var victim   = artifacts.require("Victim");

module.exports = function(deployer){
   deployer.deploy(adoption);
   deployer.deploy(victim);
};

I have defined adoption variable in another 2_deploy_contracts.js file which is given below:

var adoption = artifacts.require("adoption");

module.exports = function(deployer){
   deployer.deploy(adoption);
};

Somebody please guide me why I am getting this reference error. I am running 'truffle migrate' from the root of the project

Zulfi.

1

The error tells you exactly what the issue is. In the line

deployer.deploy(adoption);

you are using a variable which was not declared previously. You can add

var adoption = artifacts.require("adoption");

to the top of the file if you have the adoption contract defined in that Truffle project. If you haven't defined it there, you will have to copy it over from your other project.

| improve this answer | |
  • Sorry, I am not using "adoption" variable in my current 2_deploy_contracts.js, I don't need this line: "deployer.deploy(adoption);" I needed this line in my PetShop project but I don't need this line in my current project which is not Petshop, why should I define it? – zak100 Jun 13 at 4:55
  • 1
    @zak100 Well if you don't need it, remove the line. Maybe it was supposed to say attacker? – Markus - soliditydeveloper.com Jun 13 at 6:07

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.