Solidity

部署那麼貴嗎?

  • October 26, 2022

我正在嘗試部署智能合約並每次都收到此錯誤

警告!合約執行過程中遇到的錯誤

$$ contract creation code storage out of gas $$

pragma solidity ^0.8.4;
// it has trouble with workspace
import "../node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721Royalty.sol";
import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol";
import "../node_modules/@openzeppelin/contracts/security/Pausable.sol";
import "../node_modules/@openzeppelin/contracts/access/AccessControl.sol";
import "../node_modules/@openzeppelin/contracts/utils/Counters.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";

contract BaseCollection is ERC721, ERC721Enumerable, ERC721URIStorage, ERC721Royalty, Ownable, Pausable, AccessControl {
   using Counters for Counters.Counter;

   bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE");
   bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
   Counters.Counter private _tokenIdCounter;

   constructor(
       string memory name,
       string memory symbol
   ) ERC721(name, symbol) {
       _grantRole(DEFAULT_ADMIN_ROLE, msg.sender);
       _grantRole(PAUSER_ROLE, msg.sender);
       _grantRole(MINTER_ROLE, msg.sender);
   }

   function pause() public onlyRole(PAUSER_ROLE) {
       _pause();
   }

   function unpause() public onlyRole(PAUSER_ROLE) {
       _unpause();
   }

   function safeMint(address to, string memory uri) public onlyRole(MINTER_ROLE) {
       uint256 tokenId = _tokenIdCounter.current();
       _tokenIdCounter.increment();
       _safeMint(to, tokenId);
       _setTokenURI(tokenId, uri);
   }

   function _beforeTokenTransfer(address from, address to, uint256 tokenId)
       internal
       whenNotPaused
       override(ERC721, ERC721Enumerable)
   {
       super._beforeTokenTransfer(from, to, tokenId);
   }

   // The following functions are overrides required by Solidity.

   function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage, ERC721Royalty) {
       super._burn(tokenId);
   }

   function tokenURI(uint256 tokenId)
       public
       view
       override(ERC721, ERC721URIStorage)
       returns (string memory)
   {
       return super.tokenURI(tokenId);
   }

   function supportsInterface(bytes4 interfaceId)
       public
       view
       override(ERC721, ERC721Enumerable, AccessControl, ERC721Royalty)
       returns (bool)
   {
       return super.supportsInterface(interfaceId);
   }
}

然後我生成了 abi 和 bin

solc --optimize --abi ./contracts/contract.sol -o ./abi/collection --overwrite
solc --optimize --bin ./contracts/contract.sol -o ./bin

我生成我的 Go 庫

abigen --bin=./smart-contracts/bin/BaseCollection.bin --abi=./smart-contracts/abi/collection/BaseCollection.abi --pkg=contract_collection --out=./core/repositories/contracts/collection/collection.go --type Collection

我嘗試以這種方式部署它

   auth, err := bind.NewKeyedTransactorWithChainID(privateKey, big.NewInt(5))
   if err != nil {
       log.Fatal(err)
   }

   auth.Nonce = big.NewInt(int64(nonce))
   auth.Value = big.NewInt(0)      // in wei
   auth.GasLimit = uint64(1000000) // in units
   auth.GasPrice = gasPrice
   address, tx, instance, err := contract_collection.DeployCollection(auth, client, "test", "yes")

但是每次我執行這個函式我都會收到這個錯誤,這是我錢包的 etherscan https://goerli.etherscan.io/address/0x7a7da62d3e43beb63c30a341362039cddf71babd

有誰知道發生了什麼?

CreateEVM 程式碼中的觸發可能存在問題。您可以將您的 gas 限制增加到 1000000 以上,然後重試。

看:

合約創建程式碼儲存氣體

如何解決:警告!合約執行過程中遇到的錯誤$$ Out of gas $$

我在安靜的時間嘗試了它,它奏效了,我在 Reddit 上看到 goerli 有不尋常的汽油費,這就是人們難以部署的原因。

19/10/22 至 26/10/22 的 goerli gas 費用走勢圖

引用自:https://ethereum.stackexchange.com/questions/138085