I think I saw it somewhere before but can't find it again. I need to allow only the contract owner to mint ERC721 token in the contract. Correct me, I think it has to do with using require. I could try to code it but I'd like to follow best practices thus I'm looking for opinions.

1 Answer 1


You can either use Ownable https://docs.openzeppelin.com/contracts/2.x/access-control#ownership-and-ownable and use onlyOwner modifier on your function;

function mint() onlyOwner {

or you can use:

require(msg.sender == owner, "Must be owner");

variable address owner should be initialized beforehand.

msg.sender is the sender of the transaction

Ownable has a lot of features, like transferOwnership, renounceOwnership, getter and events

  • Awesome. Super clear. Thank you.
    – ratib90486
    Mar 18, 2022 at 12:16

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.