Ropsten网络不确定
我正在尝试将MetAmask上的Ropsten TestNet连接到我的项目。但是我有一个我几天无法解决的问题。我对要重定向的页面上的定义如下。
当我希望它是一个错误时,我希望它给我一条消息。我现在正好遇到这个错误。 '确保您在Corrent网络上。将网络设置为Ropsten Test Network的
publicDashboard.jsx
useEffect(() => {
const init = async () => {
try {
const web3 = await getWeb3();
const accounts = await web3.eth.getAccounts();
const networkId = await web3.eth.net.getId();
const deployedNetwork = Project.networks[networkId];
if(deployedNetwork === undefined)
throw new Error('Make sure you are on the corrent network. Set the network to Ropsten Test Network');
const contract = new web3.eth.Contract(
Project.abi,
deployedNetwork.address,
);
setWeb3(web3);
setAccounts(accounts);
setContract(contract);
} catch (error) {
window.alert(error);
history.push("/dashboard");
}
}
init();
if (isReady()) {
window.ethereum.on('accountsChanged', accounts => {
setAccounts(accounts);
});
}
}, [history]);
,这是我的Truffle-config.js文件。一切似乎正常。我不明白为什么它没有连接。你能帮我吗?
const path = require("path");
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
contracts_build_directory: path.join(__dirname, "src/contracts"),
networks: {
ropsten: {
provider: () => new HDWalletProvider(mnemonic, 'https://ropsten.infura.io/v3/08ac778579d74dbaa8d2e3d02e5c0092'),
network_id: 3, // Ropsten's id
gas: 5500000, // Ropsten has a lower block limit than mainnet
confirmations: 2, // # of confs to wait between deployments. (default: 0)
timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
skipDryRun: false // Skip dry run before migrations? (default: false for public nets )
},
},
mocha: {
// timeout: 100000
},
compilers: {
solc: {
//version: "0.8.13", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
}
},
}
};
而且我还编写了终端此代码“松露迁移 - 网络ropsten”。我没有看到任何错误。
I'm trying to connect the Ropsten TestNet on Metamask to my project. But I have a problem that I haven't been able to solve for days. I made a definition as follows on the page I want to redirect.
And I wanted it to give me a message when I wanted it to be an error. I am getting exactly that error right now.
'Make sure you are on the corrent network. Set the network to Ropsten Test Network'
publicdashboard.jsx
useEffect(() => {
const init = async () => {
try {
const web3 = await getWeb3();
const accounts = await web3.eth.getAccounts();
const networkId = await web3.eth.net.getId();
const deployedNetwork = Project.networks[networkId];
if(deployedNetwork === undefined)
throw new Error('Make sure you are on the corrent network. Set the network to Ropsten Test Network');
const contract = new web3.eth.Contract(
Project.abi,
deployedNetwork.address,
);
setWeb3(web3);
setAccounts(accounts);
setContract(contract);
} catch (error) {
window.alert(error);
history.push("/dashboard");
}
}
init();
if (isReady()) {
window.ethereum.on('accountsChanged', accounts => {
setAccounts(accounts);
});
}
}, [history]);
And this is my truffle-config.js file. Everything seems normal. I don't understand why it is not connecting. Can you help me with this?
const path = require("path");
const HDWalletProvider = require('@truffle/hdwallet-provider');
const fs = require('fs');
const mnemonic = fs.readFileSync(".secret").toString().trim();
module.exports = {
contracts_build_directory: path.join(__dirname, "src/contracts"),
networks: {
ropsten: {
provider: () => new HDWalletProvider(mnemonic, 'https://ropsten.infura.io/v3/08ac778579d74dbaa8d2e3d02e5c0092'),
network_id: 3, // Ropsten's id
gas: 5500000, // Ropsten has a lower block limit than mainnet
confirmations: 2, // # of confs to wait between deployments. (default: 0)
timeoutBlocks: 200, // # of blocks before a deployment times out (minimum/default: 50)
skipDryRun: false // Skip dry run before migrations? (default: false for public nets )
},
},
mocha: {
// timeout: 100000
},
compilers: {
solc: {
//version: "0.8.13", // Fetch exact version from solc-bin (default: truffle's version)
// docker: true, // Use "0.5.1" you've installed locally with docker (default: false)
// settings: { // See the solidity docs for advice about optimization and evmVersion
// optimizer: {
// enabled: false,
// runs: 200
// },
// evmVersion: "byzantium"
// }
}
},
}
};
And also I wrote the terminal this code "truffle migrate --network ropsten". I didn't see any error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于将来的参考,请勿发布以08AC7785开头的API密钥...这意味着任何人都可以使用它,请在可能的情况下删除API键。似乎您的
项目
名称空间无效。比使用HDWALLETPROVIDER更好的新解决方案是使用新的松露仪表板
命令与MetAmask连接,该MetAmask连接到您的硬件钱包for future reference, do not post your api key that starts with 08ac7785... This means that anyone can use it, delete the api key if possible. It also seems that your
Project
namespace is not valid. A better new solution than to use HDWalletProvider, is to use the newtruffle dashboard
command to connect with metamask, which is connected to your hardware wallet