pragma solidity ^0.6.0; import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; // ERC-721 contract that represents unique, non-fungible tokens contract MyERC721 is ERC721 { // The base URI is a human-readable string that is used as the base URL // for all token URIs string private _baseURI; constructor(string memory _name, string memory _symbol, string memory _baseURI) ERC721(_name, _symbol) public { // Set the base URI _setBaseURI(_baseURI); } // Set the base URI for the contract function setBaseURI(string memory _baseURI) public { // Only the contract owner can set the base URI require(msg.sender == owner, "Only the contract owner can set the base URI"); // Set the base URI _setBaseURI(_baseURI); } // Internal function to set the base URI function _setBaseURI(string memory _baseURI) internal { // Set the base URI _baseURI = _baseURI; } // Returns the base URI for the contract function baseURI() public view returns (string memory) { return _baseURI; } // Returns the token URI for a given token ID function tokenURI(uint256 _tokenId) public view virtual override returns (string memory) { // Encode the token URI according to the ERC-721 specification // The token URI should be a human-readable string that uniquely identifies the token return _baseURI + _tokenId; } } pragma solidity ^0.7.0; import "https://github.com/OpenZeppelin/openzeppelin-solidity/contracts/token/ERC721/ERC721.sol"; contract MyToken is ERC721 { // The base URI for the token contract string private baseURI; /** * @dev Sets the base URI for the token contract * @param _baseURI The base URI to set for the contract */ function _setBaseURI(string memory _baseURI) internal { // Only the contract owner can set the base URI require(msg.sender == owner, "Only the contract owner can set the base URI"); // Set the base URI baseURI = _baseURI; } /** * @dev Returns the base URI set for the token contract * @return The base URI set for the contract */ function getBaseURI() public view returns (string memory) { return baseURI; } }
0.4.18