-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created Token URI smart contract and added new mint function
- Loading branch information
1 parent
56f4f42
commit 9887032
Showing
4 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "../node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol"; | ||
|
||
/** | ||
* @title ERC721 implementing Token URI | ||
* @dev ERC721 token with storage based token URI management. | ||
*/ | ||
abstract contract ERC721URIStorage is ERC721Enumerable { | ||
using Strings for uint256; | ||
|
||
// Optional mapping for token URIs | ||
mapping(uint256 => string) private _tokenURIs; | ||
|
||
/** | ||
* @dev See {IERC721Metadata-tokenURI}. | ||
*/ | ||
function tokenURI(uint256 tokenId) | ||
public | ||
view | ||
virtual | ||
override | ||
returns (string memory) | ||
{ | ||
require( | ||
_exists(tokenId), | ||
"ERC721URIStorage: URI query for nonexistent token" | ||
); | ||
|
||
string memory _tokenURI = _tokenURIs[tokenId]; | ||
string memory base = _baseURI(); | ||
|
||
// If there is no base URI, return the token URI. | ||
if (bytes(base).length == 0) { | ||
return _tokenURI; | ||
} | ||
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked). | ||
if (bytes(_tokenURI).length > 0) { | ||
return string(abi.encodePacked(base, _tokenURI)); | ||
} | ||
|
||
return super.tokenURI(tokenId); | ||
} | ||
|
||
/** | ||
* @dev Sets `_tokenURI` as the tokenURI of `tokenId`. | ||
* | ||
* Requirements: | ||
* | ||
* - `tokenId` must exist. | ||
*/ | ||
function _setTokenURI(uint256 tokenId, string memory _tokenURI) | ||
internal | ||
virtual | ||
{ | ||
require( | ||
_exists(tokenId), | ||
"ERC721URIStorage: URI set of nonexistent token" | ||
); | ||
_tokenURIs[tokenId] = _tokenURI; | ||
} | ||
|
||
/** | ||
* @dev Destroys `tokenId`. | ||
* The approval is cleared when the token is burned. | ||
* | ||
* Requirements: | ||
* | ||
* - `tokenId` must exist. | ||
* | ||
* Emits a {Transfer} event. | ||
*/ | ||
function _burn(uint256 tokenId) internal virtual override { | ||
super._burn(tokenId); | ||
|
||
if (bytes(_tokenURIs[tokenId]).length != 0) { | ||
delete _tokenURIs[tokenId]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters