Truffle migrate fails due to missing function but it exists in node modules

0 votes

While attempting to run a truffle migration, I get the following error:

Using network 'development'.

Running migration: 1_initial_migration.js
  Replacing Migrations...
  ... 0x1e30a241296f07f9e4e702f5066031ba128e163fd7858cfd09311ddff14bebf8
  Migrations: 0xe1b914764eeed3cceee23a6b8b43365318b219a9
Saving successful migration to network...
  ... 0x74086dea1bf5aab373d9091512fea7f84188c05f6c2c071eae45a7eb3f5abc5d
Saving artifacts...
Running migration: 1524796297_will_contract.js
Error encountered, bailing. Network state unknown. Review successful transactions manually.
TypeError: contract.detectNetwork is not a function
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-deployer/src/actions/deploy.js:6:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-deployer/src/deferredchain.js:20:1

It compiles fine but when the migration is run it claims that contract.detectNetwork is not found. This is weird because I can locate the method. It's in node_modules/truffle-contract/contract.js

detectNetwork: function() {
      var self = this;

      return new Promise(function(accept, reject) {
        // Try to detect the network we have artifacts for.
        if (self.network_id) {
          // We have a network id and a configuration, let's go with it.
          if (self.networks[self.network_id] != null) {
            return accept(self.network_id);
          }
        }

        self.web3.version.getNetwork(function(err, result) {
          if (err) return reject(err);

          var network_id = result.toString();

          // If we found the network via a number, let's use that.
          if (self.hasNetwork(network_id)) {
            self.setNetwork(network_id);
            return accept();
          }

          // Otherwise, go through all the networks that are listed as
          // blockchain uris and see if they match.
          var uris = Object.keys(self._json.networks).filter(function(network) {
            return network.indexOf("blockchain://") == 0;
          });

          var matches = uris.map(function(uri) {
            return BlockchainUtils.matches.bind(BlockchainUtils, uri, self.web3.currentProvider);
          });

          Utils.parallel(matches, function(err, results) {
            if (err) return reject(err);

            for (var i = 0; i < results.length; i++) {
              if (results[i]) {
                self.setNetwork(uris[i]);
                return accept();
              }
            }

            // We found nothing. Set the network id to whatever the provider states.
            self.setNetwork(network_id);

            accept();
          });

        });
      });
    }

My migration file is here:

var Will = artifacts.require("./Will.sol");

module.exports = function(deployer, accounts) {
 var password1 = "who";
 var  password2 = "dat";
 var  deadline = 10;
 deployer.deploy(password1, password2, deadline, {value: 100, from: accounts[0]}); 
};

the constructor function for the Will.sol file:

//Constructor function that initializes passwords, deadline, and defines destination account
    function Will(bytes32 password1, bytes32 password2, uint _deadline) payable {
        deadline = _deadline;
        pass1 = password1;
        pass2 = password2;
        owner = msg.sender;
    }

truffle.js:

 module.exports = {
      networks: {
        development: {
          host: "127.0.0.1",
          port: 8545,
          network_id: "*" // Match any network id
        }
      }
    };
Oct 3, 2018 in Blockchain by slayer
• 29,370 points
2,020 views

1 answer to this question.

0 votes
deployer.deploy(password1, password2, deadline, {value: 100, from: accounts[0]}); 

should be changed to

deployer.deploy(will, password1, password2, deadline, {value: 100, from: accounts[0]}); 

This should solve the problem.

answered Oct 3, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Not able to migrate contract in Truffle: Error: No network specified. Cannot determine current network

Make these entries in truffle.js file: module.exports = { ...READ MORE

answered Nov 30, 2018 in Blockchain by Omkar
• 69,220 points
1,198 views
+1 vote
0 answers
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,936 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,461 views
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 69,220 points
1,476 views
+1 vote
3 answers

Pass all .dat files in folder to function

os.listdir(path) return names, not fullpaths change parseBlockFile(file) to fullpath = os.path.join(path,file) if os.path.isfile(fullpath) ...READ MORE

answered Sep 5, 2018 in Blockchain by Saygum
2,364 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP