Truffle
松露遷移–network ropsten 問題
當我執行時,
truffle migrate --network ropsten
我看不到契約部署,而只是Compiling your contracts... =========================== > Everything is up to date, there is nothing to compile.
我不知道為什麼,但也刪除
./build
了我看不到遷移文件的部署,但只有Compiling your contracts... =========================== > Compiling ./contracts/A.sol > Compiling ./contracts/B.sol > Artifacts written to /Users/........./build/contracts > Compiled successfully using: - solc: 0.5.0+commit.1d4f565a.Emscripten.clang
很多指南顯示這樣的程式碼:
Running migration: 1_initial_migration.js Deploying Migrations… … 0xd01dd7... Migrations: 0xf741... Saving successful migration to network… … 0x78ed... Saving artifacts… Running migration: 2_deploy_contracts.js Deploying HelloWorld… … 0x0aa9... HelloWorld: [SAVE THIS ADDRESS!!] Saving successful migration to network… … 0xee95... Saving artifacts…
這裡是我的 truffle.js 程式碼:
var HDWalletProvider = require("truffle-hdwallet-provider"); const MNEMONIC = 'my mnemonic words from metamask' module.exports = { // See <http://truffleframework.com/docs/advanced/configuration> // for more about customizing your Truffle configuration! networks: { development: { host: "127.0.0.1", port: 7545, network_id: "*" // Match any network id }, ropsten: { provider: function() { return new HDWalletProvider(MNEMONIC, "ropsten.infura.io/v3/my-key") }, network_id: 3, gas: 4000000 //make sure this gas allocation isn't over 4M, which is the max } } };
那麼我該如何解決這個問題呢?
在 ropsten 提供程序下的 truffle.js(或 truffle-config.js)中,嘗試使用**https://**傳遞 Infura API URL 。所以它應該是這樣的:
// Inside truffle.js ... module.exports = { networks: { ... ropsten: { provider: function() { return new HDWalletProvider(MNEMONIC, "https://ropsten.infura.io/v3/my-key") }, network_id: 3, gas: 4000000 //make sure this gas allocation isn't over 4M, which is the max } } };
我遇到了同樣的問題,就我而言,問題是我使用了錯誤的 API 密鑰。在您的 Infura 儀表板中,檢查您是否使用了正確的一個,即用於 Ropsten 網路的那個。
正如 jfviray 所說,使用 https 傳遞 Infura API url。