[英]Unable to deploy smart contract to testnet (Ropsten) using Truffle Infura
I'm trying to deploy a simple smart contract to Testnet Ropsten but always fails with the following error:我正在尝试向 Testnet Ropsten 部署一个简单的智能合约,但总是失败并出现以下错误:
Error: *** Deployment Failed ***
错误:*** 部署失败 ***
"Migrations" -- Transaction was not mined within 750 seconds, please make sure your transaction was properly sent.
“迁移”——交易在 750 秒内没有被挖掘,请确保您的交易已正确发送。 Be aware that it might still be mined..
请注意,它可能仍然被开采..
I've searched in many places, and it says to change the gas value, I tried almost every value but still got the same error.我在很多地方搜索过,它说要更改气体值,我几乎尝试了每个值,但仍然出现相同的错误。 Sometimes it says that the gas value is not enough and sometimes it's too much.
有时它说gas值不够,有时又说太多。
This is my code:这是我的代码:
require("dotenv").config();
const HDWalletProvider = require("truffle-hdwallet-provider");
const MNEMONIC = process.env.MNEMONIC;
module.exports = {
networks: {
development: {
host: "127.0.0.1",
port: 7545,
network_id: "*",
},
ropsten: {
provider: function () {
return new HDWalletProvider(
MNEMONIC,
`https://ropsten.infura.io/v3/${process.env.INFURA_API_KEY}`
);
},
network_id: 3,
gas: 5500000, // Here I tried from 1000000 to 5500000
},
},
compilers: {
solc: {
version: "0.8.10",
},
},
};
Contract:合同:
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.3;
contract HelloWorld {
function sayHello() public pure returns(string memory){
return("hello world");
}
}
Migrations:迁移:
const Migrations = artifacts.require("Migrations");
module.exports = function (deployer) {
deployer.deploy(Migrations);
};
const HelloWorld = artifacts.require("HelloWorld");
module.exports = function (deployer) {
deployer.deploy(HelloWorld, "hello");
};
I have my metamask wallet with 1 ether in red ropstem我的 metamask 钱包里有 1 个以太币在红色绳索里
Any idea on how to deploy a smart contract in a testnet?关于如何在测试网中部署智能合约的任何想法?
It might be because, you are not speciying address and gasPrice.这可能是因为,您没有指定地址和 gasPrice。 gasPrice varies depending on network activities.
gasPrice 因网络活动而异。 You can get the current gasPrice here: https://ethgas.watch/
您可以在此处获取当前的 gasPrice: https://ethgas.watch/
ropsten: {
provider: () =>
new HDWalletProvider({
mnemonic: {
phrase: MENMONICS,
},
providerOrUrl: `https://ropsten.infura.io/v3/${process.env.INFURA_API_KEY}`,
// first address
addressIndex: 0,
}),
network_id: 3,
gas: 5500000,
// this might varies depending on the network activity
gasPrice: 20000000000,
confirmations: 2, // number of blocks to wait between deployment
timeoutBlocks: 200, // number of blocks before deployment times out
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.