Solidity
將智能合約部署到 Rinkeby
當我嘗試將智能合約部署到
Rinkeby
using時出現以下錯誤Truffle
:Error: Unknown arguments format passed to new HDWalletProvider. Please check your configuration and try again
注意:我在本地使用 部署相同的契約沒有任何問題
Truffle
,只是到Rinkeby
.這是我的程式碼:
require('dotenv').config(); const HDWalletProvider = require('@truffle/hdwallet-provider'); module.exports = { networks: { development: { host: "127.0.0.1", port: 8545, network_id: "*", }, rinkeby: { provider: () => new HDWalletProvider(process.env.RINKEBY_MNENOMIC, "https://rinkeby.infura.io/v3/${process.env.INFURA_API_KEY}"), host: "127.0.0.1", network_id: 4, gas: 4612388, gasPrice: 10000000000 }, }, // Configure your compilers compilers: { solc: { version: "0.6.2", } } }
我想知道這是否是某種版本問題,因為我看到我以前的契約使用了
'truffle-hdwallet-provider'
,而這個契約正在使用'@truffle/hdwallet-provider'
同時,我的
.env
文件包含以下內容:#MNENOMIC="word1 word2 word3, ...word12" RINKEBY_MNENOMIC="word1 word2 word3, ...word12" PRODUCTION_MNENOMIC="word1 word2 word3, ...word12" INFURA_API_KEY="xxxxxxxxxxxxxxxxxxxx"
那麼這裡可能會發生什麼?這個
Unknown arguments format passed to new HDWalletProvider
錯誤是怎麼回事?
看起來這是一個版本的事情。
根據 Truffle 的官方
readme
(可在此處獲得:https ://github.com/trufflesuite/truffle/tree/develop/packages/hdwallet-provider#truffle-usage ),現在執行此操作的方法如下:rinkeby: { provider: () => new HDWalletProvider({ mnemonic: { phrase: rinkebyMnemonic }, providerOrUrl: "https://rinkeby.infura.io/v3/" + infuraKey, numberOfAddresses: 1, shareNonce: true, }), network_id: '4', }
您也可以嘗試使用以下命令安裝錢包處理程序:
#~>npm install truffle-hdwallet-provider
然後在您的 truffle-confi.json 上有以下內容:
var mnemonicPhrase = "word1 word2 word3 ....word12"; var HDWalletProvider = require("truffle-hdwallet-provider"); module.exports = { networks: { development: { host: "127.0.0.1", port: 7545, network_id: "*" // Match any network id }, rinkeby: { // must be a thunk, otherwise truffle commands may hang in CI provider: () => new HDWalletProvider(mnemonicPhrase, "https://rinkeyb.infura.io/v3/YOUR-INFURA-PROJECT-KEY"), network_id: '4', } }, compilers: { solc: { version: '0.8.9', optimizer: { enabled: true, runs: 200 } } }, };
然後嘗試使用 truffle 執行:truffle migrate –network rinkeby
您還可以將 infura “https://rinkeyb.infura.io/v3/YOUR-INFURA-PROJECT-KEY”替換為 Alchemy “https://eth-rinkeby.alchemyapi.io/v2/YOUR-ALCHEMY-JEY”