Truffle

陷入松露編譯

  • August 1, 2018

當我truffle compile在編譯契約後執行它時永遠卡住了。我正在導入 openzeppelin 庫並使用 infura 、 ropsten 和 metamask 在測試網上部署合約。. 這是輸出

Compiling ./contracts/Migrations.sol...
Compiling ./contracts/obaidminttoken.sol...
Compiling zeppelin-solidity/contracts/math/SafeMath.sol...
Compiling zeppelin-solidity/contracts/ownership/Ownable.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/BasicToken.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/ERC20.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/ERC20Basic.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/MintableToken.sol...
Compiling zeppelin-solidity/contracts/token/ERC20/StandardToken.sol...
Writing artifacts to ./build/contracts

這是我的 truffle.js 文件

require('dotenv').config();
const HDWalletProvider = require("truffle-hdwallet-provider");
module.exports = {
 networks: {
   development: {
     host: "localhost",
     port: 7545,
     gas: 6500000,
     network_id: "5777"
   },
   ropsten: {
       provider: new HDWalletProvider(process.env.MNENOMIC, "https://ropsten.infura.io/v3/" + process.env.INFURA_API_KEY),
       network_id: 3,
       gas: 4500000
   },
 }
};

檢查文件名是否與契約名稱相同,例如。如果合約名稱是:Voting,請命名文件voting.sol

如果這不起作用,請嘗試刪除下的 json 文件build/contracts/truffle compile再次執行。

有關更多資訊,請查看https://github.com/trufflesuite/truffle-migrate/issues/14

通過將 HDWallet 提供程序包裝在 truffle.js 文件中解決了這個問題。這是更新的 truffle.js 程式碼

require('dotenv').config();
const HDWalletProvider = require("truffle-hdwallet-provider");
module.exports = {
 networks: {
   development: {
     host: "localhost",
     port: 7545,
     gas: 6500000,
     network_id: "5777"
   },
   ropsten: {
       provider:function() { return new HDWalletProvider(process.env.MNENOMIC, "https://ropsten.infura.io/v3/" + process.env.INFURA_API_KEY);},
       network_id: 3,
       gas: 4500000
   },
 }
};

引用自:https://ethereum.stackexchange.com/questions/55612