11// SPDX-License-Identifier: MIT
22pragma solidity >= 0.8.30 ;
33
4+ import {LibUtils} from "../../Libraries/LibUtils.sol " ;
5+
46/// @title ERC721 Receiver Interface
57/// @notice Interface for contracts that want to support safe ERC721 token transfers.
68/// @dev Implementers must return the function selector to confirm token receipt.
@@ -16,7 +18,7 @@ interface IERC721Receiver {
1618 returns (bytes4 );
1719}
1820
19- /// @title ERC-721 Enumerable Token (Zero-dependency Implementation)
21+ /// @title ERC-721 Enumerable Token
2022/// @notice A complete, dependency-free ERC-721 implementation with enumeration support using a custom storage layout.
2123/// @dev Provides metadata, ownership, approvals, enumeration, safe transfers, minting, and burning features.
2224contract ERC721EnumerableFacet {
@@ -52,6 +54,7 @@ contract ERC721EnumerableFacet {
5254 struct ERC721EnumerableStorage {
5355 string name;
5456 string symbol;
57+ string baseURI;
5558 mapping (uint256 tokenId = > string tokenURI ) tokenURIOf;
5659 mapping (uint256 tokenId = > address owner ) ownerOf;
5760 mapping (address owner = > uint256 [] ownedTokens ) ownedTokensOf;
@@ -83,6 +86,23 @@ contract ERC721EnumerableFacet {
8386 return getStorage ().symbol;
8487 }
8588
89+ /// @notice Provide the metadata URI for a given token ID.
90+ /// @param _tokenId tokenID of the NFT to query the metadata from
91+ /// @return the URI providing the detailed metadata of the specified tokenID
92+ function tokenURI (uint256 _tokenId ) external view returns (string memory ) {
93+ ERC721EnumerableStorage storage s = getStorage ();
94+ address owner = s.ownerOf[_tokenId];
95+ if (owner == address (0 )) {
96+ revert ERC721NonexistentToken (_tokenId);
97+ }
98+
99+ if (bytes (s.baseURI).length == 0 ) {
100+ return "" ;
101+ }
102+
103+ return string .concat (s.baseURI, LibUtils.toString (_tokenId));
104+ }
105+
86106 /// @notice Returns the total number of tokens in existence.
87107 /// @return The total supply of tokens.
88108 function totalSupply () external view returns (uint256 ) {
0 commit comments