I have a marketplace contract which inherits from openzeppelins ownable.sol and i want to check access to the listNFT function to only be done by the owner of the contract. I tried the onlyOwner modifier which didn't work raising 'the caller not owner' error. Then i tried to understand the exact values of msg.sender and owner() and build my own event to track the values of msg.sender and owner. You can see the relevant code here.
# Event to keep track of owner and caller
event FunctionCall(
address caller,
address owner
);
// List the NFT on the marketplace
function listNft( uint256 _tokenId, uint256 _price) public payable nonReentrant {
# Emit event to inspect caller and owner
emit FunctionCall(msg.sender ,owner());
require(_price > 100, "Price must be at least 100 wei");
# This line doesn't let me through and evaluates to false
# require(msg.sender == owner(), "Must be owner");
...more code
}
When i call the contract without the require owner statement I can inspect the events on polygonscan which gives the following
The event shows that msg.sender and owner are the same address, how can the require statement afterwards evaluate to false?
I tested casting msg.sender and owner() to address(msg.sender) and address(owner()) but it didn't work. What am I missing?