Truffle

松露:遷移到 ropsten - 靜默失敗

  • April 20, 2019

當我執行以下命令時,我沒有收到任何輸出:

truffle migrate --network ropsten

這只是在使用truffle init並創建單個契約創建新項目之後。

當我truffle develop從控制台執行並執行遷移命令時,一切正常。

這是我的 truffle.js 文件的內容:

var HDWalletProvider = require("truffle-hdwallet-provider");

var mnemonic = "my twelve word mnemonic......";

module.exports = {
 networks: {
   ropsten: {
     provider: function() {
       return new HDWalletProvider(mnemonic, "https://ropsten.infura.io/xxxxxxxxxxxxx")
     },
     network_id: 3
   },
   development: {
     host: "localhost",
     port: 8545,
     network_id: "*" // Match any network id
   }
 }
};

我在 Ubuntu 16.04 和最新版本的松露 4.1.8 上。

(是的,我已經用水龍頭的乙太幣為我在 Ropsten 上的賬戶注資)

這就是我在 Kovan 上部署的方式,例如,更改可以在每個測試網上部署的 infura 連結。完全適合我:

const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require ('./compile'); //That files come from the compile.js you can see it below.

const provider = new HDWalletProvider(
   '12 words mneumonic',
   'https://kovan.infura.io/XXXXXXXXXXXX'
);

const web3 = new Web3(provider);

const deploy = async ()=> { //Create that function to use async & await
   const accounts = await web3.eth.getAccounts();

   console.log('Attempting to deploy from account', accounts[0]);

   const result = await new web3.eth.Contract(JSON.parse(interface))
       .deploy({data: bytecode})
       .send({ gas: '30000000', from: accounts[0]});

       console.log('Contract deployed to', result.options.address);
       console.log(interface);//We pass the ABI through the console to be able to use it to build the javascript object that emulates the contract on our react code.

};
deploy();

在這裡,我將 compile.js 留給您,以備不時之需。

   const path = require('path'); // Helps to find the path to the contract across whatever OS you are using form compile.js to xxx.sol files
   const fs = require('fs'); // Load the FileSystem Module.
   const solc = require('solc');

   const contractPath = path.resolve(__dirname, 'contracts', 'Contracts_Remix.sol'); //Creation of cross SO's path.

   const source = fs.readFileSync(contractPath, 'utf8'); 
   //We compile the source code, of 1 single contract and showed the bytecode and the ABI by console to examine it.
   console.log(solc.compile(source),1); 
   module.exports = solc.compile(source).contracts[':Your_contract_name']; 
//We only call the contract we want to deploy.

希望能幫助到你!

我遇到了同樣的問題,但就我而言,我錯誤地將我的 infura 端點環境變數設置為我的密鑰而不是我的項目 ID。如果它有助於其他人閱讀本文,請確保您的 infura 端點是正確的!

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