How to modify an ERC721 contract to give exclusive access to functions only for the owner?

I have already implemented this contract on the main network. But now I realized that anyone can use the various functions of the contract, such as emitting, burning. I would like to make a small modification to the contract to allow only the contract owner to access the functions. How do I do this? Can someone help me? Thank you.

Contract: https://etherscan.io/address/0xa1234cec7eb5115994b17e08d41dbb97af944c06#code

:computer: Environment

:memo:Details

:1234: Code to reproduce

1 Like

You need a modifier to modify the functions you need, just like this one onlyOwner https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/access/Ownable.sol#L42

2 Likes

How do I use this modifier? Do I just import it into the contract using the remix?

1 Like
import "Ownable.sol";

contract NinoArteiro is ERC721, Ownable {
    function mint(address to, uint256 tokenId) public onlyOwner {
        _mint(to, tokenId);
    }
}

just like above, so now, only owner can call the function mint()

2 Likes

Thank you very much. I will test.

1 Like

It gave that error. How do I correct?

[image]

1 Like

Removing redundant references Context

2 Likes

Should I remove all that part?

1 Like

I think so, just try!

2 Likes

The contract was compiled without error. It worked. Thank you very much. You helped me a lot. :slightly_smiling_face:

1 Like

Please, just one more question. Can I modify my current contract on the main network? Or do I have to create a new contract?

1 Like

If you use the proxy pattern, you can update the contract without change the contract address, if not, deploy a new contract.

2 Likes

Hi @ninoarteiro,

Welcome to the community :wave:

I marked @Skyge’s answer as the solution to your question. (:pray: Thanks as always @Skyge).

For more information on AccessControl (including Ownable), please see the documentation: https://docs.openzeppelin.com/contracts/3.x/access-control

For an example of an ERC721 using AccessControl please see the preset contract:

1 Like