由于缺少功能,松露迁移失败,但它存在于node_modules中

时间:2018-04-27 21:40:29

标签: ethereum solidity smartcontracts truffle ether

在尝试运行松露迁移时,我收到以下错误:

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

它编译得很好,但是当迁移运行时,它声称找不到contract.detectNetwork。这很奇怪,因为我可以找到方法。它在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();
          });

        });
      });
    }

我的迁移文件在这里:

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

Will.sol文件的构造函数:

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

1 个答案:

答案 0 :(得分:2)

Adam提供的解决方案100%正确。

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

应该是

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