0
votes

intial_deploy_contract.js file

const DappToken = artifacts.require('DappToken.sol')
const DaiToken = artifacts.require('DaiToken.sol')
const TokenFarm = artifacts.require('TokenFarm.sol')

module.exports = async function(deployer, network, accounts) {
  //Deploy Mock DAI Token
  await deployer.deploy(DaiToken)
  const daiToken = await DaiToken.deployed()

  //Deploy Dapp Token
  await deployer.deploy(DappToken)
  const dappToken = await DappToken.deployed()

  //Deploy TokenFarm
  await deployer.deploy(TokenFarm, dappToken.address, daiToken.address)
  const TokenFarm = await TokenFarm.deployed()

  //Transfer all tokens to TokenFarm(1 million)
  await dappToken.transfer(tokenFarm.address, '1000000000000000000000000')

  //Transfer 100 Mock DAI tokens to investor
  await daiToken.transfer(accounts[1], '100000000000000000000')

 };'

TokenFarm.sol File

 pragma solidity ^0.5.0;

 import "./DappToken.sol";
 import "./DaiToken.sol";

 contract TokenFarm {
   //All code goes here...
   string public name = "Dapp Token Farm";
   DappToken public dappToken;
   DaiToken public daiToken;

  constructor(DappToken _dappToken, DaiToken _daiToken) public {
      //Storing reference to the DappToken and DaiToken
      dappToken = _dappToken;
      daiToken = _daiToken;
  }
}

The file gets compile successfully but when migrated using truffle migrate --reset it is showing the ReferenceError as

ReferenceError: Cannot access 'TokenFarm' before initialization at module.exports (C:\Users\NIHAL SINGH\Desktop\defi_tutorial\migrations\2_deploy_contracts.js:15:25) at processTicksAndRejections (internal/process/task_queues.js:93:5) at Migration._load (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:55:1)
at Migration.run (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\Migration.js:171:1)
at Object.runMigrations (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:150:1)
at Object.runFrom (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:110:1) at Object.runAll (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:114:1) at Object.run (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\migrate\index.js:79:1) at runMigrations (C:\Users\NIHAL SINGH\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:269:1)

1

1 Answers

0
votes

You have defined the TokenFarm (uppercase T) on this line

const TokenFarm = artifacts.require('TokenFarm.sol')

Then you're trying to re-assign it on this line

const TokenFarm = await TokenFarm.deployed()

Solution: Assign to another const name (for example tokenFarm - lowercase T) instead of re-assigning the already existing TokenFarm.

const tokenFarm = await TokenFarm.deployed()