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
Environment
Details
Code to reproduce
1 Like
Skyge
October 20, 2020, 1:29am
2
2 Likes
How do I use this modifier? Do I just import it into the contract using the remix?
1 Like
Skyge
October 20, 2020, 2:12am
4
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
Skyge
October 20, 2020, 3:12am
7
Removing redundant references Context
2 Likes
Should I remove all that part?
1 Like
The contract was compiled without error. It worked. Thank you very much. You helped me a lot.
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
Skyge
October 20, 2020, 4:19am
14
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
I marked @Skyge ’s answer as the solution to your question. ( 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:
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "../access/AccessControl.sol";
import "../GSN/Context.sol";
import "../utils/Counters.sol";
import "../token/ERC721/ERC721.sol";
import "../token/ERC721/ERC721Burnable.sol";
import "../token/ERC721/ERC721Pausable.sol";
/**
* @dev {ERC721} token, including:
*
* - ability for holders to burn (destroy) their tokens
* - a minter role that allows for token minting (creation)
* - a pauser role that allows to stop all token transfers
* - token ID and URI autogeneration
*
* This contract uses {AccessControl} to lock permissioned functions using the
This file has been truncated. show original
1 Like