Skip to content

Instantly share code, notes, and snippets.

@yupeshekhonov
Last active January 27, 2023 10:33
Show Gist options
  • Save yupeshekhonov/f7caa217727d286aec2e743736f9ea51 to your computer and use it in GitHub Desktop.
Save yupeshekhonov/f7caa217727d286aec2e743736f9ea51 to your computer and use it in GitHub Desktop.
Error in Solidity 0.8.4

Создать контракт с таким кодом

// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.4;

import {CollectionHelpers, CollectionHelpersEvents} from  "@unique-nft/solidity-interfaces/contracts/CollectionHelpers.sol";
import {UniqueNFT, CrossAddress} from "@unique-nft/solidity-interfaces/contracts/UniqueNFT.sol";

contract CollectionManager is CollectionHelpersEvents {
    CollectionHelpers helpers = CollectionHelpers(0x6C4E9fE1AE37a41E93CEE429e8E1881aBdcbb54F);

    function createCollection(
        address owner,
        address managerContract,
        string calldata name,
        string calldata description,
        string calldata symbol,
        string calldata baseURI
    ) public payable virtual returns (address){
        address collectionAddress = helpers.createNFTCollection{value: helpers.collectionCreationFee()}(name, description, symbol);
        
        helpers.makeCollectionERC721MetadataCompatible(collectionAddress, baseURI);

        UniqueNFT collection = UniqueNFT(collectionAddress);

        collection.addCollectionAdminCross(CrossAddress(managerContract, 0));
        collection.changeCollectionOwnerCross(CrossAddress(owner, 0));

        return collectionAddress;
    }
}

И таким конфигом (hardhat.config.ts)

import dotenv from 'dotenv'
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
dotenv.config()
const { RPC_OPAL, PRIVATE_KEY } = process.env;

const config: HardhatUserConfig = {
  solidity: {
    version: "0.8.4",
    settings: {
      optimizer: {
        enabled: true,
      },
    },
  },
  // defaultNetwork: "unq",
  networks: {
    hardhat: {},
    opal: {
      url: RPC_OPAL,
      accounts: [`${PRIVATE_KEY}`]
    },
  }
};

export default config;

Попробовать его скомпилировать.

yarn hardhat compile --verbose

CompilerError: Stack too deep, try removing local variables.
  --> contracts/CollectionManager.sol:25:60:
   |
25 |         collection.changeCollectionOwnerCross(CrossAddress(owner, 0));
   |                                                            ^^^^^


Error HH600: Compilation failed

For more info go to https://hardhat.org/HH600 or run Hardhat with --show-stack-traces
error Command failed with exit code 1.

Версия Solidity 0.8.17 и такие настройки решают проблему:

solidity: {
    version: "0.8.17",
    settings: {
      metadata: {
        // Not including the metadata hash
        // https://github.com/paulrberg/solidity-template/issues/31
        bytecodeHash: "none",
      },
      optimizer: {
        enabled: true,
        runs: 800,
      },
      viaIR : true,
    },
  },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment