Dapp本地测试用Ganache-cli 能够正常交互,truffle migrate --network ropsten
部署到ropsten后出现合约交互(transact)一直失败,测试已检查Metamask连接网络的chainID 和url都匹配无误。
版本:truffle 5.15, soildity 0.5.16 npm 6.14.3
代码如下:
const dotenv=require('dotenv');
const result=dotenv.config();
if (result.error){
throw result.error;
}
console.log(result.parsed);
var NonceTrackerSubprovider = require("web3-provider-engine/subproviders/nonce-tracker");
var HDWalletProvider = require("truffle-hdwallet-provider");
var infura_apikey=myprojectID;
var mnemonic_ropsten=process.env.mnemonic_ropsten;//存储在.env文件中
module.exports = {
networks: {
development: {//本地测试
host: "127.0.0.1",
port: 7545,
network_id: "*", // Match any network
gas : 3000000000
},
ropsten:{
provider :new HDWalletProvider(mnemonic_ropsten,"https://ropsten.infura.io/v3/"+myprojectID),
network_id: 3,
gas: 7003605,
gasPrice: 100000000000,
networkCheckTimeout: 600000
}
}
};