我正在尝试将我的合同部署到goerli测试网,但hardhat不断抛出这个错误:

Error: cannot estimate gas; transaction may fail or may require manual gas limit [ See: https://links.ethers.org/v5-errors-UNPREDICTABLE_GAS_LIMIT ] (reason="execution reverted", method="estimateGas", transaction={"from":"0xb5E8683Aa524069C5714Fc2D8c3e64F78f2862fb","data":"0x6103e86009556... (I shortened it down)","accessList":null}, error={"name":"ProviderError","_stack":"ProviderError: HttpProviderError\n    at HttpProvider.request (C:\\Programming\\Personal Projects\\NFT Minting Dapp\\smart-contract\\node_modules\\hardhat\\src\\internal\\core\\providers\\http.ts:78:19)\n    at LocalAccountsProvider.request (C:\\Programming\\Personal Projects\\NFT Minting Dapp\\smart-contract\\node_modules\\hardhat\\src\\internal\\core\\providers\\accounts.ts:187:34)\n    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async EthersProviderWrapper.send (C:\\Programming\\Personal Projects\\NFT Minting Dapp\\smart-contract\\node_modules\\@nomiclabs\\hardhat-ethers\\src\\internal\\ethers-provider-wrapper.ts:13:20)","code":3,"_isProviderError":true,"data":"0xbfc6c337000000000000000000000000fd7bfa171b5b81b79c245456e986db2f32fbfadb"}, code=UNPREDICTABLE_GAS_LIMIT, version=providers/5.7.2)
    at Logger.makeError (C:\Programming\Personal Projects\NFT Minting Dapp\smart-contract\node_modules\@ethersproject\logger\src.ts\index.ts:269:28)
    at Logger.throwError (C:\Programming\Personal Projects\NFT Minting Dapp\smart-contract\node_modules\@ethersproject\logger\src.ts\index.ts:281:20)
    at checkError (C:\Programming\Personal Projects\NFT Minting Dapp\smart-contract\node_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:78:20)
    at EthersProviderWrapper.<anonymous> (C:\Programming\Personal Projects\NFT Minting Dapp\smart-contract\node_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:642:20)
    at step (C:\Programming\Personal Projects\NFT Minting Dapp\smart-contract\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:48:23)
    at Object.throw (C:\Programming\Personal Projects\NFT Minting Dapp\smart-contract\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:29:53)
    at rejected (C:\Programming\Personal Projects\NFT Minting Dapp\smart-contract\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:21:65)
    at processTicksAndRejections (node:internal/process/task_queues:95:5) {
  reason: 'execution reverted',
  code: 'UNPREDICTABLE_GAS_LIMIT',
  method: 'estimateGas',
  transaction: {
    from: '0xb5E8683Aa524069C5714Fc2D8c3e64F78f2862fb',
    data: '0x6103e86009556... (I shortened it down)',
    accessList: null
  }

这是我的合同:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.15;

/// @title John's ERC721A Contract
/// @author John Pioc (www.johnpioc.com)
/// @notice This contract can be used to mint ERC721A standard NFTs with industry standard functionality - whitelisted addresses, reveals, NFT metadata, etc.

import "erc721a/contracts/ERC721A.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";
import {DefaultOperatorFilterer} from "./DefaultOperatorFilterer.sol";

error CallerIsNotUser();
error InvalidWhitelistAllocation();
error MintingTooMany();
error InsufficientFunds();
error MintingOverCollectionSize();
error SaleIsClosed();
error MintingOverWhitelistAllocation();
error InvalidProof();
error URIQueryForNonexistentToken();

contract NFT is ERC721A, Ownable, DefaultOperatorFilterer {

    using Strings for uint256;

    enum SaleState {
        CLOSED,
        WHITELIST,
        PUBLIC
    }

    uint256 public collectionSize = 1000;
    uint256 public publicMintPrice = 0.1 ether;
    uint256 public publicMaxMintAmount = 3;
    uint256 public whitelistAllocation = 500;
    uint256 public whitelistMintPrice = 0.05 ether;
    uint256 public whitelistMaxMintAmount = 1;
    bytes32 public whitelistMerkleRoot;
    string public unrevealedUri = "https://exampleUnrevealedUri.com";
    string public baseUri = "https://exampleUri.com/";
    bool public isRevealed;
    SaleState public saleState;

    /// @notice Modifier to verify that caller doesn't come from a contract
    modifier callerIsUser() {
        if (tx.origin != msg.sender) revert CallerIsNotUser();
        _;
    }

    constructor() ERC721A ("NFT", "NFT") {
        isRevealed = false;
        saleState = SaleState.CLOSED;
    }

    /// @notice Function to mint NFTs during the public sale
    /// @param _mintAmount Number of NFTs to mint
    function publicMint(uint64 _mintAmount) public payable callerIsUser {
        if (_numberMinted(msg.sender) - _getAux(msg.sender) + _mintAmount > publicMaxMintAmount) revert MintingTooMany();
        if (totalSupply() + _mintAmount > collectionSize) revert MintingOverCollectionSize();
        if (saleState != SaleState.PUBLIC) revert SaleIsClosed();
        if (msg.value < _mintAmount * publicMintPrice) revert InsufficientFunds();

        _safeMint(msg.sender, _mintAmount);
    }

    /// @notice Function to mint NFTs during the whitelist sale
    /// @param _merkleProof Merkle Proof for caller's address
    /// @param _mintAmount Number of NFTs to mint
    function whitelistMint(bytes32[] calldata _merkleProof, uint64 _mintAmount) public payable callerIsUser {
        if (_getAux(msg.sender) + _mintAmount > whitelistMaxMintAmount) revert MintingTooMany();
        if (totalSupply() + _mintAmount > whitelistAllocation) revert MintingOverWhitelistAllocation();
        if (saleState != SaleState.WHITELIST) revert SaleIsClosed();
        if (msg.value < _mintAmount * whitelistMintPrice) revert InsufficientFunds();

        bytes32 leaf = keccak256(abi.encodePacked(msg.sender));
        if(!(MerkleProof.verify(_merkleProof, whitelistMerkleRoot, leaf))) revert InvalidProof();

        _setAux(msg.sender, _getAux(msg.sender) + _mintAmount);
        _safeMint(msg.sender, _mintAmount);
    }

    /// @notice Sets a new collection size
    /// @dev Only owner can call this function
    /// @param _collectionSize New Collection Size
    function setCollectionSize(uint256 _collectionSize) public onlyOwner {
        collectionSize = _collectionSize;
    }

    /// @notice Sets a new public mint price
    /// @dev Only owner can call this function
    /// @param _publicMintPrice New public mint price
    function setPublicMintPrice(uint256 _publicMintPrice) public onlyOwner {
        publicMintPrice = _publicMintPrice;
    }

    /// @notice Sets a new public max mint amount
    /// @dev Only owner can call this function
    /// @param _publicMaxMintAmount New public max mint amount
    function setPublicMaxMintAmount(uint256 _publicMaxMintAmount) public onlyOwner {
        publicMaxMintAmount = _publicMaxMintAmount;
    }

    /// @notice Sets a new whitelist allocation
    /// @dev Only owner can call this function. New whitelist allocation cannot be greater than collection size
    /// @param _whitelistAllocation New whitelist allocation
    function setWhitelistAllocation(uint256 _whitelistAllocation) public onlyOwner {
        if (_whitelistAllocation > collectionSize) revert InvalidWhitelistAllocation();
        whitelistAllocation = _whitelistAllocation;
    }

    /// @notice Sets a new whitelist mint price
    /// @dev Only owner can call this function
    /// @param _whitelistMintPrice New whitelist mint price
    function setWhitelistMintPrice(uint256 _whitelistMintPrice) public onlyOwner {
        whitelistMintPrice = _whitelistMintPrice;
    }

    /// @notice Sets a new whitelist max mint amount
    /// @dev Only owner can call this function
    /// @param _whitelistMaxMintAmount New whitelist max mint amount
    function setWhitelistMaxMintAmount(uint256 _whitelistMaxMintAmount) public onlyOwner {
        whitelistMaxMintAmount = _whitelistMaxMintAmount;
    }

    /// @notice Sets a new whitelist merkle root
    /// @dev Only owner can call this function
    /// @param _whitelistMerkleRoot New whitelist merkle root
    function setWhitelistMerkleRoot(bytes32 _whitelistMerkleRoot) public onlyOwner {
        whitelistMerkleRoot = _whitelistMerkleRoot;
    }

    /// @notice Sets a new unrevealed URI
    /// @dev Only owner can call this function
    /// @param _unrevealedUri New unrevealed URI
    function setUnrevealedUri(string memory _unrevealedUri) public onlyOwner {
        unrevealedUri = _unrevealedUri;
    }

    /// @notice Sets a new base URI
    /// @dev Only owner can call this function
    /// @param _baseUri New base URI
    function setBaseUri(string memory _baseUri) public onlyOwner {
        baseUri = _baseUri;
    }

    /// @notice Toggles reveal from false to true, vice versa
    /// @dev Only owner can call this function. Starts at false
    function toggleRevealed() public onlyOwner {
        isRevealed = !isRevealed;
    }

    /// @notice Sets a new sale state
    /// @dev Only owner can call this function. 0 = CLOSED, 1 = WHITELIST, 2 = PUBLIC
    /// @param _saleState new sale state
    function setSaleState(uint256 _saleState) public onlyOwner {
        saleState = SaleState(_saleState);
    }

    /// @notice Generates and returns the token URI for a given token ID
    /// @param _tokenId An NFT's token ID
    function tokenURI(uint256 _tokenId) public view override returns (string memory) {
        if (!_exists(_tokenId)) revert URIQueryForNonexistentToken();
        if (!isRevealed) return unrevealedUri;

        return string(abi.encodePacked(baseUri, _tokenId.toString(), ".json"));
    }

    /// @notice Withdraws all ETH from contract to owner's address
    /// @dev Only owner can call this function
    function withdraw() public payable onlyOwner {
        (bool os,) = payable(owner()).call{value: address(this).balance}("");
        require(os);
    }

    /// @notice All functions below are mandatory add-ons as per the Default Operator Filterer protocol

    function transferFrom(address from, address to, uint256 tokenId) public payable override onlyAllowedOperator(from) {
        super.transferFrom(from, to, tokenId);
    }

    function safeTransferFrom(address from, address to, uint256 tokenId) public payable override onlyAllowedOperator(from) {
        super.safeTransferFrom(from, to, tokenId);
    }

    function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data)
        public
        payable
        override
        onlyAllowedOperator(from)
    {
        super.safeTransferFrom(from, to, tokenId, data);
    }
}

这是我的配置文件:

import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
import "@nomiclabs/hardhat-waffle";
import "dotenv/config";
import "@typechain/hardhat";

const GOERLI_RPC_URL = process.env.GOERLI_RPC_URL;
const PRIVATE_KEY = process.env.PRIVATE_KEY;
const ETHERSCAN_API_KEY = process.env.ETHERSCAN_API_KEY;

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.17",
    settings: {
      optimizer: {
        enabled: true,
        runs: 200
      }
    }
  },
  networks: {
    goerli: {
      url: GOERLI_RPC_URL,
      accounts: [PRIVATE_KEY!],
      chainId: 5,
      allowUnlimitedContractSize: true,
    }
  },
  etherscan: {
    apiKey: {
      goerli: ETHERSCAN_API_KEY!
    }
  }
};

export default config;

这是我的部署脚本:

// imports
import { ethers, run, network } from 'hardhat';

// async main
async function main() {
  const contractFactory = await ethers.getContractFactory("NFT");
  const contract = await contractFactory.deploy();
  console.log(`Contract deployed to ${contract.address}`);

  if (network.config.chainId === 5 && process.env.ETHERSCAN_API_KEY) {
    console.log("Waiting for block confirmations...")
    await contract.deployTransaction.wait(6)
    await verify(contract.address, [])
  }
}

// async function verify(contractAddress, args) {
const verify = async (contractAddress: string, args: any[]) => {
  console.log("Verifying contract...")
  try {
    await run("verify:verify", {
      address: contractAddress,
      constructorArguments: args,
    })
  } catch (e: any) {
    if (e.message.toLowerCase().includes("already verified")) {
      console.log("Already Verified!")
    } else {
      console.log(e)
    }
  }
}

// main
main()
  .then(() => process.exit(0))
  .catch((error) => {
    console.error(error)
    process.exit(1)
  })

我运行命令:

npx hardhat run scripts/deploy.ts --network goerli

通过运行该命令,它会抛出错误。我再次检查了它是否抓取了环境变量和所有内容。实际上,我从我的一个repo中分叉了所有这些代码,当时部署脚本在那里工作,但现在不是了

安全帽投掷';提供程序错误:HttpProviderError';当我运行部署脚本时的更多相关文章

  1. 详解php与ethereum客户端交互

    本篇文章给大家讲述了php与ethereum客户端交互的相关知识点,对此有需要的朋友可以跟着学习下。

  2. 使用ethers.js部署Solidity智能合约的方法

    Ethers.js则是一个轻量级的web3.js替代品,在本文中,我们将学习使用ethers.js部署Solidity智能合约的方法,感兴趣的朋友一起看看吧

  3. TypeError:无法读取未定义的的财产(读取&#39;JsonRpcProvider&#39;);

    我的修复方法是将package.json中的“ethers”降级到5.4版,然后是文件夹,最后是npm安装,再次安装ethers。步骤1:在package.json中步骤2:删除node_modules步骤3:npm安装

  4. 文件已使用加载器处理:*/node_modules/babel-loader/lib/index.js。您可能需要一个额外的加载器来处理这些加载器的结果

    /usr/bin/env节点|varfs=require;|var_=要求;我在执行区块链项目时遇到此错误我试图解决它,但这里没有解决方案。所以我不得不在这里提出一个问题。

  5. 安全帽投掷&#39;提供程序错误:HttpProviderError&#39;当我运行部署脚本时

    我正在尝试将我的合同部署到goerli测试网,但hardhat不断抛出这个错误:这是我的合同:这是我的配置文件:这是我的部署脚本:我运行命令:通过运行该命令,它会抛出错误。我再次检查了它是否抓取了环境变量和所有内容。实际上,我从我的一个repo中分叉了所有这些代码,当时部署脚本在那里工作,但现在不是了

  6. 使用JavaScript与solidity合约交互

    我开始从事一个简单的项目,我在区块链方面没有太多经验。我想使用JavaScript连接到Solidity合约。连接合同并获取地址是可行的,但当我调用getInfo时,我会收到以下错误:以下是代码。

  7. Star: Ubuntu下配置和编译cpp-ethereum客户端启动GPU加速交易

    因为以太坊是基于P2P网络所以没有中心节点,所以用户仅安装Ethereum客户端即可连入Ethereum公共网络或者在自己的testnet下运行Ethereum。这里我们讲一下配合使用ethminer和geth实现GPU挖矿,目的是有些建立的私链,由于交易量增多,geth客户端的挖矿,只适合cpu,速率很低,我们为了提高交易速度,选择GPU提高交易速度。

  8. 【以太坊】ubuntu安装以太坊ethereum的测试网络ropsten-net以及雷电网络raiden-network环境

    ubuntu安装以太坊ethereum的测试网络ropsten-net以及雷电网络raiden-network环境前言为了保证环境稳定,我从头开了一个虚拟机。

  9. Ubuntu 16.04下安装以太坊编译环境以及设置合约功能支持geth 1.6以及solc 0.4.16版本以上

    本文解决了下面几个问题:1.geth升级到1.6版本后,不再使用eth.getCompilers()或者admin.setSolc()等通过JS的方式实时编译,而是采用了ABI合约接口的二进制表示。通过转化为json方式到geth的console平台进行编译具体看下面文章说明:https://ethereum.stackexchange.com/questions/15435/how-to-compile-solidity-contracts-with-geth-v1-6/154362.最新的solc0.

  10. 基于Ubuntu系统搭建以太坊go-ethereum源码的开发环境

    第一、先安装geth的CLI环境sudoapt-getinstallgeth,这个很重要第二、下载源代码第三、依赖环境注:(重要)先通过此链接配置GO语言的开发环境:https://github.com/ethereum/go-ethereum/wiki/Installing-Go#ubuntu-1404EthereumGo是使用Go语言开发的,需要Go和C的编译器sudoapt-getinsta

随机推荐

  1. 如何扩展ATmega324PB微控制器的以下宏寄存器?

    我目前正在学习嵌入式,我有以下练习:展开以下宏寄存器:如果有人解决了这个问题,我将不胜感激,以便将来参考

  2. Python将ONNX运行时设置为返回张量而不是numpy数组

    在python中,我正在加载预定义的模型:然后我加载一些数据并运行它:到目前为止,它仍在正常工作,但我希望它默认返回Tensor列表,而不是numpy数组。我对ONNX和PyTorch都是新手,我觉得这是我在这里缺少的基本内容。这将使转换中的一些开销相同。

  3. 在macOS上的终端中使用Shell查找文件中的单词

    我有一个文本文件,其中有一行:我需要找到ID并将其提取到变量中。我想出了一个RexEx模式:但它似乎对我尝试过的任何东西都不起作用:grep、sed——不管怎样。我的一个尝试是:我为这样一个看似愚蠢的问题感到抱歉,但我在互联网上找不到任何东西:我在SO和SE上读了几十个类似的问题,并在谷歌上搜索了几个教程,但仍然无法找到答案。欢迎提供任何指导!

  4. react-chartjs-2甜甜圈图中只有标题未更新

    我正在使用react-chartjs-2在我的网站中实现甜甜圈图。下面是我用来呈现图表的代码。我将甜甜圈图的详细信息从父组件传递到子组件,所有道具都正确传递。当我在beforeDraw函数外部记录props.title时,它会记录正确的值,但当我在beforeDraw函数内部记录props.title时,它将记录标题的前一个值,从而呈现标题的前值。我在这里做错了什么?

  5. 如何在tkinter中使用Python生成器函数?

    生成器函数承诺使某些代码更易于编写。但我并不总是知道如何使用它们。假设我有一个斐波那契生成器函数fib(),我想要一个显示第一个结果的tkinter应用程序。当我点击“下一步”按钮时,它会显示第二个数字,依此类推。我如何构建应用程序来实现这一点?我可能需要在线程中运行生成器。但如何将其连接回GUI?

  6. 如何为每次提交将存储库历史记录拆分为一行?

    我正在尝试获取存储库的历史记录,但结果仅以单行文本的形式返回给我。

  7. 尝试在颤振项目上初始化Firebase时出错

    当尝试在我的颤振项目上初始化firebase时,我收到了这个错误有人知道我能做什么吗?应用程序分级Gradle插件Gradle项目颤振相关性我已经将firebase设置为Google文档已经在另一个模拟器上尝试过,已经尝试过创建一个全新的模拟器,已经在不同的设备上尝试过了,已经尝试了特定版本的firebase,已经尝试添加但没有任何效果,已经在youtube上看到了关于它的每一个视频,该应用程序在android和iOS两个平台上都抛出了这个错误

  8. 在unix中基于当前日期添加新列

    我试图在unix中基于时间戳列在最后一个单元格中添加一个状态列。我不确定如何继续。

  9. 麦克斯·蒙特利。我一直得到UncaughtReferenceError:当我在终端中写入node-v时,节点未定义

    如果这是您应该知道的,请确认:我已将所有shell更改为默认为zsh。当我在终端中写入node-v时,我一直收到“UncaughtReferenceError:nodeisnotdefined”。但它显示节点已安装。我是个新手,在这方面经验不足。

  10. 如何在前端单击按钮时调用后端中的函数?

    那么如何在后端添加一个新的端点,点击按钮调用这个函数。

返回
顶部