0

I'm trying to deploy a smart contract and get this error each time

Warning! Error encountered during contract execution [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);
    }
}

Then I generated abi and bin with

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

I generate my Go library with

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

I try to deploy it this way

    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")

But each time I run this function I get this error, here is the etherscan of my wallet https://goerli.etherscan.io/address/0x7a7da62d3e43beb63c30a341362039cddf71babd

Does anyone have any idea what is going on?

2 Answers 2

0

There could be a problem with the triggering of Create in the EVM code. You can increase your gas limit above 1000000 and try again.

See:

contract creation code storage out of gas

How to fix: Warning! Error encountered during contract execution [Out of gas]

1
  • Thanks for your response, I tried it doesn't work unfortunately
    – t0mpl
    Commented Oct 25, 2022 at 14:13
0

I tried at quiet hours and it worked, I've seen on Reddit that there was unusual gas fees for goerli and that's the reason people had trouble deploy.

goerli gas fees chart from 19/10/22 to 26/10/22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.