Nft
氣體估計錯誤並顯示以下消息 - 10000 NFT
我正在嘗試鑄造 10000 個 NFT 並創建我的智能合約。嘗試部署契約時出現以下錯誤。我不確定我做錯了什麼。我收到的錯誤是氣體估計錯誤,並顯示以下消息(見下文)。事務執行可能會失敗。是否要強制發送?所需氣體超過限額 (30000000)。
這是我的程式碼。
// SPDX-License-Identifier: GPL-3.0 /** These contracts have been used to create tutorials, please review them on your own before using any of the following code for production. */ pragma solidity >=0.7.0 <0.9.0; import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; contract NFT_Emojicardz is ERC721Enumerable, Ownable { using Strings for uint256; string public baseURI; string public baseExtension = ".json"; uint256 public cost = 0.75 ether; uint256 public maxSupply = 10000; uint256 public maxMintAmount = 10000; bool public paused = false; mapping(address => bool) public whitelisted; constructor( string memory _name, string memory _symbol, string memory _initBaseURI ) ERC721(_name, _symbol) { setBaseURI(_initBaseURI); mint(msg.sender,10000); } // internal function _baseURI() internal view virtual override returns (string memory) { return baseURI; } // public function mint(address _to, uint256 _mintAmount) public payable { uint256 supply = totalSupply(); require(!paused); require(_mintAmount > 0); require(_mintAmount <= maxMintAmount); require(supply + _mintAmount <= maxSupply); if (msg.sender != owner()) { if(whitelisted[msg.sender] != true) { require(msg.value >= cost * _mintAmount); } } for (uint256 i = 1; i <= _mintAmount; i++) { _safeMint(_to, supply + i); } } function walletOfOwner(address _owner) public view returns (uint256[] memory) { uint256 ownerTokenCount = balanceOf(_owner); uint256[] memory tokenIds = new uint256[](ownerTokenCount); for (uint256 i; i < ownerTokenCount; i++) { tokenIds[i] = tokenOfOwnerByIndex(_owner, i); } return tokenIds; } function tokenURI(uint256 tokenId) public view virtual override returns (string memory) { require( _exists(tokenId), "ERC721Metadata: URI query for nonexistent token" ); string memory currentBaseURI = _baseURI(); return bytes(currentBaseURI).length > 0 ? string(abi.encodePacked(currentBaseURI, tokenId.toString(), baseExtension)) : ""; } //only owner function setCost(uint256 _newCost) public onlyOwner() { cost = _newCost; } function setmaxMintAmount(uint256 _newmaxMintAmount) public onlyOwner() { maxMintAmount = _newmaxMintAmount; } function setBaseURI(string memory _newBaseURI) public onlyOwner { baseURI = _newBaseURI; } function setBaseExtension(string memory _newBaseExtension) public onlyOwner { baseExtension = _newBaseExtension; } function pause(bool _state) public onlyOwner { paused = _state; } function whitelistUser(address _user) public onlyOwner { whitelisted[_user] = true; } function removeWhitelistUser(address _user) public onlyOwner { whitelisted[_user] = false; } function withdraw() public payable onlyOwner { (bool success, ) = payable(msg.sender).call{value: address(this).balance}(""); require(success); } }
這是 3000 萬個氣體單位。
這是每個塊的限制。
如果您是一個區塊中唯一的交易,也許這可能會奏效。
否則你會打破gas限制。
最後一個重要的注意事項是塊本身的大小是有限的。每個區塊的目標大小為 1500 萬個 gas,但區塊大小會根據網路需求增加或減少,直至區塊限制為 3000 萬個 gas(目標區塊大小的 2 倍)。區塊內所有交易消耗的gas總量必須小於區塊gas限制。這很重要,因為它確保塊不能任意大。如果塊可以任意大,那麼由於空間和速度要求,性能較差的完整節點將逐漸無法跟上網路的速度。