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
}
}
};