0

I have an internal function which is called from an external function. At the 2 require(msg.sender == ContractOwner ... ) the result of the compare is always false, or at least it is ignored and the 2nd part after the or (||) operator is executed. In the constructor of the contract ContractOwner (type: address) is set to msg.sender.

Even if I replace msg.sender == ContractOwner by true or 1 == 1, the 2nd part after the || is executed.

I also tried placing extra ( ) around the or construction. I thought that should always return true because msg.sender == ContractOwner is true.

function publicMint(uint256 _numTokens) external payable { require(isPublicsaleActive, "Public sale paused"); require(_numTokens * publicPrice * 1 ether <= msg.value, "Insufficient funds"); randomMint(_numTokens); } function randomMint(uint256 _numTokens) internal { uint256 reservedAmount = whitelistReserved[msg.sender]; require(!(isPresaleActive || isWhitelistsaleActive) || _numTokens <= reservedAmount, "Can't mint more NFTs than reserved" ); // --------------------------------------------------------------------------------- require(msg.sender == ContractOwner || _numTokens <= MAX_MINT_PER_TRANSACTION, string(abi.encodePacked("Max mint ", MAX_MINT_PER_TRANSACTION, " per transaction"))); require(msg.sender == ContractOwner || _numTokens + mintedPerWallet[msg.sender] <= MAX_MINT_PER_WALLET, string(abi.encodePacked(MAX_MINT_PER_WALLET - mintedPerWallet[msg.sender], " mints left for this wallet"))); // --------------------------------------------------------------------------------- require(totalSupply + _numTokens <= MAX_TOKENS, "Mint amount exceeds the maximum supply"); for (uint256 i = 1; i <= _numTokens; ++i) { _safeMint(msg.sender, IDs[totalSupply]); individualTokenURI[IDs[totalSupply]][0] = initialBaseUri; totalSupply += 1; } mintedPerWallet[msg.sender] += _numTokens; if (isPresaleActive || isWhitelistsaleActive && reservedAmount >= _numTokens) {whitelistReserved[msg.sender] = reservedAmount - _numTokens;} } 

1 Answer 1

1

Sorted out that "string(abi.encodePacked("Max mint ", MAX_MINT_PER_TRANSACTION, " per transaction"))" was the reason of reverting. I replaced it with just a string and the everything worked as supposed. I can't see a fault in it and also tested it in a test contract where it works fine. So halve solved, but good for now.

// SPDX-License-Identifier: MIT pragma solidity ^0.8.9; contract test { address public ContractOwner; uint256 public constant MAX_MINT_PER_TRANSACTION = 5; constructor() { ContractOwner = msg.sender; } function _test() external payable { operator(); } function operator() internal view { address Test = msg.sender; require(msg.sender == ContractOwner || 1 + 1 >= 3, string(abi.encodePacked("Max mint ", MAX_MINT_PER_TRANSACTION, " per transaction"))); Test = msg.sender; } } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.