8

我无法迁移 truffle compile 附带的标准合同。这是我的工作:

truffle init
truffle compile
open other terminal and run testrpc
truffle migrate

前三步运行平稳,但是当我运行 truffle migrate 时,它​​出现了

Error: No network specified. Cannot determine current network.
    at Object.detect (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43157:23)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:200497:19
    at finished (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43085:9)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:198408:14
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:68162:7
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:163793:9
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160353:16
    at replenish (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160873:25)
    at iterateeCallback (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160863:17)
    at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:160838:16

我的版本列表:

node 9.1.0
truffle 4.0.1
testrpc 6.0.3

谢谢!

4

2 回答 2

30

您应该在配置文件中指定网络,该文件truffle.js位于项目文件夹的根目录中。

module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    }
  }
};

松露配置#networks

于 2017-11-19T10:41:19.300 回答
2

简单的解决方案:

问题:当您在终端中运行推荐“truffle init”时,此配置将在今天到来。没有定义与以太坊 cli 通信的配置(如 geth 或 testrpc )

// module.exports = {
//   // See <http://truffleframework.com/docs/advanced/configuration>
//   // to customize your Truffle configuration!
// };

所以,你必须在truffle.js中像下面这样改变它

module.exports = {
  networks: {
    development: {
      host: "127.0.0.1",
      port: 8545, // your rpc port (like geth rpc port or testrpc port )
      network_id: "*"    
    }
  }
};
于 2018-02-11T05:41:01.520 回答