我创建了一个集成了松露和React框架的项目,然后在truffle-config.js中配置了以太坊的rinkeby测试网络。但是,当我将合同迁移到rinkeby网络时,出现了问题。
truffle compile
truffle migrate --network rinkeby
然后出现一些错误
TypeError: Cannot read property '_alreadyWrapped' of undefined
at Object.wrap (C:\Users\Lsy\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\wrapper.js:13:1)
at Object.wrap (C:\Users\Lsy\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\index.js:9:1)
at Object.create (C:\Users\Lsy\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\provider\index.js:14:1)
at TruffleConfig.get [as provider] (C:\Users\Lsy\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\config\dist\configDefa
ults.js:189:1)
at Object.detect (C:\Users\Lsy\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\environment\environment.js:19:1)
at C:\Users\Lsy\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\commands\migrate.js:192:1
Truffle v5.1.1 (core: 5.1.1)
Node v12.13.0
项目目录如下所示:
truffle-config.js
const path = require("path");
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs')
let secrets;
console.log(path.join(__dirname, "secrets.json"));
if (fs.existsSync(path.join(__dirname, "secrets.json"))){
secrets = JSON.parse(fs.readFileSync(path.join(__dirname, "secrets.json"),'utf8'));
}else{
console.log("secrets.json doesn't exist!")
}
module.exports = {
contracts_build_directory: path.join(__dirname, "client/src/contracts"),
networks: {
ganache:{
host:"127.0.0.1",
port:7545,
network_id:"*"
},
develop: {
port: 8545
},
rinkeby:{
provider:()=>{
new HDWalletProvider(secrets.mnemonic,"https://rinkeby.infura.io/v3/"+secrets.infuraProjectId);
},
network_id: '4'
}
}
};
这个问题困扰了我很长时间,谁能帮助我!真的谢谢!
答案 0 :(得分:0)
您忘记了return语句:
rinkeby: {
provider: () => {
return new HDWalletProvider(secrets.mnemonic,"https://rinkeby.infura.io/v3/"+secrets.infuraProjectId);
},
network_id: 4
}