简体   繁体   English

无法使用 Truffle Infura 将智能合约部署到测试网 (Ropsten)

[英]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.

相关问题 我试图在 ropsten 中部署带有地址参数的智能合约,但该帐户被投诉无效 - I tried to deploy a smart contract with address argument in ropsten, but the account is complained to be invalid 通过应用程序访问在Ropsten网络上部署的智能合约 - Access a smart contract that is deployed on the Ropsten network from an App 如何使用 Brownie 在 Avalanche 测试网上验证合约 - How to verify a contract on Avalanche testnet using Brownie 有没有办法在部署之前预先部署从智能合约中部署的库? - Is there a way pre-deploy a library deployed from within a smart contract before it is deployed? 无法使用scrapyd deploy在centos7中部署portia spider - Unable to Deploy the portia spider in centos7 using scrapyd deploy 无法使用 XAMPP 部署 React 项目 - Unable to deploy React project using XAMPP 在rinkeby测试网络上部署固态智能合约的问题 - issues deploying solidity smart contract to rinkeby test network 无法使用WAMP服务器中的dist文件夹部署Angular 5 - Unable to deploy Angular 5 using dist folder in WAMP server 无法使用虚拟主机在Apache Web服务器中部署angularjs应用 - Unable to deploy angularjs app in apache webserver using virtual hosts 无法使用 Github 操作部署到 Google App Engine - 未提供凭据 - Unable to deploy to Google App Engine using Github Actions - credentials not supplied
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM