├── .env.example ├── .gitignore ├── .prettierrc ├── LICENSE.md ├── README.md ├── index.html ├── package.json ├── postcss.config.js ├── public ├── favicon.ico ├── logo.png └── thirdweb.svg ├── src ├── App.tsx ├── components │ ├── HistoryCard.tsx │ ├── NFTCard.tsx │ ├── Nav │ │ ├── Footer.tsx │ │ └── Header.tsx │ ├── PaginationHelper.tsx │ └── PoweredBy.tsx ├── consts │ └── parameters.ts ├── hooks │ └── useDebounce.ts ├── icons │ ├── LinkIcon.tsx │ └── SearchIcon.tsx ├── index.css ├── main.tsx ├── pages │ ├── index.tsx │ └── nft │ │ └── $id.tsx ├── utils │ └── truncateAddress.ts └── vite-env.d.ts ├── tailwind.config.js ├── tsconfig.json ├── tsconfig.node.json ├── vercel.json └── vite.config.ts /.env.example: -------------------------------------------------------------------------------- 1 | VITE_TEMPLATE_CLIENT_ID= -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | 26 | .env 27 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": false, 3 | "trailingComma": "all" 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2021 Non-Fungible Labs, Inc 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NFT Gallery 2 | 3 | Create your own NFT gallery for any ERC721/ERC1155 NFT collection on [any EVM-compatible chain](https://blog.thirdweb.com/any-contract-any-evm-chain/). 4 | 5 | View the metadata of all NFTs in the collection, including features such as pagination, filtering, and search. 6 | 7 | ## Using This Repo 8 | 9 | To create your own version of this template, you can use the following steps: 10 | 11 | Run this command from the terminal to clone this project: 12 | 13 | ```bash 14 | npx thirdweb create --template nft-gallery 15 | ``` 16 | 17 | ## Environment Variables 18 | 19 | To run this project, you will need to add environment variables. Check the `.env.example` file for all the environment variables required and add it to `.env` file or set them up on your hosting provider. 20 | 21 | ### 1. Deploy or Import Your NFT Collection 22 | 23 | If you haven't already deployed your contract, head over to the thirdweb dashboard and create your own [NFT collection](https://thirdweb.com/thirdweb.eth/TokenERC721) contract. 24 | 25 | If you have an existing contract, use the [thirdweb dashboard](https://thirdweb.com/dashboard) to import it! 26 | 27 | ### 2. Configure Parameters 28 | 29 | Go to the [`parameters.ts`](/src/consts/parameters.ts) and update the following values: 30 | 31 | 1. `contractAddress`: The smart contract address of your NFT collection. 32 | 2. `chain`: The name of the chain that your smart contract is deployed to. 33 | 3. `blockExplorer`: (Optional) - The block explorer to open when user's click on historical events of each NFT. 34 | 35 | ### 3. Customize the Styling 36 | 37 | Update the styles in the respective components by changing the [Tailwind](https://tailwindcss.com/) classes. 38 | 39 | ## Join our Discord! 40 | 41 | For any questions or suggestions, join our discord at [https://discord.gg/thirdweb](https://discord.gg/thirdweb). 42 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | NFT Gallery 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nft-gallery", 3 | "private": true, 4 | "version": "0.0.0", 5 | "type": "module", 6 | "scripts": { 7 | "dev": "vite", 8 | "build": "tsc && vite build", 9 | "preview": "vite preview", 10 | "format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,json,md}\"" 11 | }, 12 | "dependencies": { 13 | "react": "^18.3", 14 | "react-dom": "^18.3", 15 | "react-helmet": "^6.1.0", 16 | "react-router-dom": "^6.23.1", 17 | "thirdweb": "^5.23.0" 18 | }, 19 | "devDependencies": { 20 | "@types/react": "^18.3.2", 21 | "@types/react-dom": "^18.3.0", 22 | "@types/react-helmet": "^6.1.11", 23 | "@vitejs/plugin-react-swc": "^3.7.0", 24 | "autoprefixer": "^10.4.19", 25 | "postcss": "^8.4.38", 26 | "prettier": "^3.2.5", 27 | "prettier-plugin-tailwindcss": "^0.5.14", 28 | "tailwindcss": "^3.4.3", 29 | "typescript": "^5", 30 | "vite": "^5.2.11", 31 | "vite-plugin-node-polyfills": "^0.22.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thirdweb-example/nft-gallery/bf0f7c066e110db34e86b4831a2ea479be74ed63/public/favicon.ico -------------------------------------------------------------------------------- /public/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thirdweb-example/nft-gallery/bf0f7c066e110db34e86b4831a2ea479be74ed63/public/logo.png -------------------------------------------------------------------------------- /public/thirdweb.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | createBrowserRouter, 3 | RouterProvider, 4 | LoaderFunction, 5 | ActionFunction, 6 | } from "react-router-dom"; 7 | 8 | interface IRoute { 9 | path: string; 10 | Element: JSX.Element; 11 | loader?: LoaderFunction; 12 | action?: ActionFunction; 13 | ErrorBoundary?: JSX.Element; 14 | } 15 | 16 | const pages = import.meta.glob("./pages/**/*.tsx", { eager: true }); 17 | 18 | const routes: IRoute[] = []; 19 | for (const path of Object.keys(pages)) { 20 | const fileName = path.match(/\.\/pages\/(.*)\.tsx$/)?.[1]; 21 | if (!fileName) { 22 | continue; 23 | } 24 | 25 | const normalizedPathName = fileName.includes("$") 26 | ? fileName.replace("$", ":") 27 | : fileName.replace(/\/index/, ""); 28 | 29 | routes.push({ 30 | path: fileName === "index" ? "/" : `/${normalizedPathName.toLowerCase()}`, 31 | // @ts-ignore 32 | Element: pages[path].default, 33 | // @ts-ignore 34 | loader: pages[path]?.loader as unknown as LoaderFunction | undefined, 35 | // @ts-ignore 36 | action: pages[path]?.action as unknown as ActionFunction | undefined, 37 | // @ts-ignore 38 | ErrorBoundary: pages[path]?.ErrorBoundary as unknown as JSX.Element, 39 | }); 40 | } 41 | 42 | const router = createBrowserRouter( 43 | routes.map(({ Element, ErrorBoundary, ...rest }) => ({ 44 | ...rest, 45 | // @ts-ignore 46 | element: , 47 | // @ts-ignore 48 | ...(ErrorBoundary && { errorElement: }), 49 | })), 50 | ); 51 | 52 | const App = () => { 53 | return ; 54 | }; 55 | 56 | export default App; 57 | -------------------------------------------------------------------------------- /src/components/HistoryCard.tsx: -------------------------------------------------------------------------------- 1 | import { blockExplorer } from "@/consts/parameters"; 2 | import { LinkIcon } from "@/icons/LinkIcon"; 3 | import { truncateAddress } from "@/utils/truncateAddress"; 4 | import type { FC } from "react"; 5 | 6 | interface HistoryCardProps { 7 | // todo: add type after migration to v5 8 | event: any; 9 | } 10 | 11 | export const HistoryCard: FC = ({ event }) => { 12 | return ( 13 | 20 |
21 |

EVENT

22 |

{event.eventName}

23 |
24 |
25 |
26 |

FROM

27 |

28 | {event.args.from ? truncateAddress(event.args.from) : "N/A"} 29 |

30 |
31 |
32 |

TO

33 |

34 | {event.args.to ? truncateAddress(event.args.to) : "N/A"} 35 |

36 |
37 |
38 | 39 | 40 |
41 | ); 42 | }; 43 | -------------------------------------------------------------------------------- /src/components/NFTCard.tsx: -------------------------------------------------------------------------------- 1 | import { client } from "@/consts/parameters"; 2 | import { FC, useState } from "react"; 3 | import { Link } from "react-router-dom"; 4 | import { NFT } from "thirdweb"; 5 | import { MediaRenderer } from "thirdweb/react"; 6 | 7 | interface INFTCardProps { 8 | nft: NFT; 9 | } 10 | 11 | export const NFTCard: FC = ({ nft }) => { 12 | const [hover, setHover] = useState(false); 13 | return ( 14 | 15 |
setHover(true)} 18 | onMouseLeave={() => setHover(false)} 19 | > 20 | 21 | 22 | {hover && ( 23 |
24 |

25 | {String(nft.metadata.name).split(" ")[0]} 26 |

27 |

28 | {String(nft.metadata.name).split(" ")[1]} 29 |

30 |
31 | )} 32 |
33 | 34 | ); 35 | }; 36 | -------------------------------------------------------------------------------- /src/components/Nav/Footer.tsx: -------------------------------------------------------------------------------- 1 | import type { FC } from "react"; 2 | import { PaginationHelper } from "../PaginationHelper"; 3 | import { PoweredBy } from "../PoweredBy"; 4 | 5 | interface IProps { 6 | page: number; 7 | setPage: (page: number) => void; 8 | nftsPerPage: number; 9 | totalCount: number | undefined; 10 | loading: boolean; 11 | } 12 | 13 | export const Footer: FC = ({ 14 | page, 15 | setPage, 16 | nftsPerPage, 17 | totalCount, 18 | loading, 19 | }) => { 20 | if (!totalCount) return null; 21 | const noOfPages = Math.ceil(totalCount / nftsPerPage); 22 | const start = (page - 1) * nftsPerPage; 23 | const end = start + nftsPerPage; 24 | 25 | return ( 26 |
27 |

28 | {end} / {totalCount.toLocaleString()} 29 |

30 | 31 | 37 | 38 |
39 | ); 40 | }; 41 | -------------------------------------------------------------------------------- /src/components/Nav/Header.tsx: -------------------------------------------------------------------------------- 1 | import { client, nftContract } from "@/consts/parameters"; 2 | import { Link } from "react-router-dom"; 3 | import { getContractMetadata } from "thirdweb/extensions/common"; 4 | import { getNFT } from "thirdweb/extensions/erc721"; 5 | import { ConnectButton, useReadContract } from "thirdweb/react"; 6 | 7 | export const Header: React.FC = () => { 8 | const { data: firstNFT, isLoading: nftLoading } = useReadContract(getNFT, { 9 | contract: nftContract, 10 | tokenId: 1n, 11 | }); 12 | const { data: contractMetadata, isLoading: contractLoading } = 13 | useReadContract(getContractMetadata, { 14 | contract: nftContract, 15 | }); 16 | return ( 17 |
18 | 19 |
20 | {contractLoading ? ( 21 | <> 22 |
23 |
24 | 25 | ) : ( 26 | <> 27 | { 36 |

37 | {contractMetadata?.name || firstNFT?.metadata.name}{" "} 38 |

39 | 40 | )} 41 |
42 | 43 | 44 |
45 | 46 |
47 |
48 | ); 49 | }; 50 | -------------------------------------------------------------------------------- /src/components/PaginationHelper.tsx: -------------------------------------------------------------------------------- 1 | import useDebounce from "@/hooks/useDebounce"; 2 | import { FC, useEffect, useState } from "react"; 3 | 4 | interface IProps { 5 | page: number; 6 | setPage: (page: number) => void; 7 | noOfPages: number; 8 | loading: boolean; 9 | } 10 | 11 | const PaginationHelper: FC = ({ 12 | page, 13 | setPage, 14 | noOfPages, 15 | loading, 16 | }) => { 17 | const [isSearching, setIsSearching] = useState(false); 18 | const [pageInput, setPageInput] = useState(page); 19 | const debouncedSearchTerm = useDebounce(String(pageInput), 500); 20 | 21 | useEffect(() => { 22 | if (debouncedSearchTerm) { 23 | setIsSearching(true); 24 | setPage(Number(debouncedSearchTerm)); 25 | setIsSearching(false); 26 | } else { 27 | setPage(1); 28 | } 29 | }, [debouncedSearchTerm]); 30 | 31 | return ( 32 |
33 | {isSearching || loading ? ( 34 |
35 | ) : ( 36 | <> 37 | 57 | setPageInput(Number(e.target.value))} 61 | value={pageInput} 62 | /> 63 | 64 | 84 | 85 | )} 86 |
87 | ); 88 | }; 89 | 90 | export { PaginationHelper }; 91 | -------------------------------------------------------------------------------- /src/components/PoweredBy.tsx: -------------------------------------------------------------------------------- 1 | import { nftContract } from "@/consts/parameters"; 2 | import { truncateAddress } from "@/utils/truncateAddress"; 3 | import type { FC } from "react"; 4 | 5 | export const PoweredBy: FC = () => { 6 | return ( 7 | 13 | thirdweb 18 |
19 |

20 | {truncateAddress(nftContract.address)} 21 |

22 |

23 | powered by thirdweb 24 |

25 |
26 |
27 | ); 28 | }; 29 | -------------------------------------------------------------------------------- /src/consts/parameters.ts: -------------------------------------------------------------------------------- 1 | import { createThirdwebClient, getContract } from "thirdweb"; 2 | import { ethereum } from "thirdweb/chains"; 3 | 4 | /** Change these values to configure the application for your own use. **/ 5 | 6 | export const client = createThirdwebClient({ 7 | clientId: import.meta.env.VITE_TEMPLATE_CLIENT_ID, 8 | }); 9 | 10 | export const nftContract = getContract({ 11 | // Your smart contract address (available on the thirdweb dashboard) 12 | address: "0xed5af388653567af2f388e6224dc7c4b3241c544", 13 | // The chain object of the chain your contract is deployed to. 14 | // If that chain isn't in the default list of our SDK, use `defineChain` - for example: defineChain(666666) 15 | chain: ethereum, 16 | client, 17 | }); 18 | 19 | // The block explorer you want to use (Opens when user clicks on history of events. i.e. transfers) 20 | export const blockExplorer = "https://etherscan.io"; 21 | -------------------------------------------------------------------------------- /src/hooks/useDebounce.ts: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | 3 | const useDebounce = (value: string, delay: number) => { 4 | // State and setters for debounced value 5 | const [debouncedValue, setDebouncedValue] = useState(value); 6 | useEffect( 7 | () => { 8 | // Update debounced value after delay 9 | const handler = setTimeout(() => { 10 | setDebouncedValue(value); 11 | }, delay); 12 | // Cancel the timeout if value changes (also on delay change or unmount) 13 | // This is how we prevent debounced value from updating if value is changed ... 14 | // .. within the delay period. Timeout gets cleared and restarted. 15 | return () => { 16 | clearTimeout(handler); 17 | }; 18 | }, 19 | [value, delay], // Only re-call effect if value or delay changes 20 | ); 21 | return debouncedValue; 22 | }; 23 | 24 | export default useDebounce; 25 | -------------------------------------------------------------------------------- /src/icons/LinkIcon.tsx: -------------------------------------------------------------------------------- 1 | import type { FC } from "react"; 2 | 3 | export const LinkIcon: FC = () => { 4 | return ( 5 | 13 | 20 | 27 | 34 | 35 | ); 36 | }; 37 | -------------------------------------------------------------------------------- /src/icons/SearchIcon.tsx: -------------------------------------------------------------------------------- 1 | import type { FC } from "react"; 2 | 3 | export const SearchIcon: FC = () => { 4 | return ( 5 | 17 | 18 | 19 | 20 | ); 21 | }; 22 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @import url("https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap"); 2 | 3 | @tailwind base; 4 | @tailwind components; 5 | @tailwind utilities; 6 | -------------------------------------------------------------------------------- /src/main.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom/client"; 3 | import App from "./App"; 4 | import "./index.css"; 5 | import { ThirdwebProvider } from "thirdweb/react"; 6 | 7 | ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render( 8 | 9 | 10 | 11 | 12 | , 13 | ); 14 | -------------------------------------------------------------------------------- /src/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import { Footer } from "@/components/Nav/Footer"; 2 | import { Header } from "@/components/Nav/Header"; 3 | import { NFTCard } from "@/components/NFTCard"; 4 | import { nftContract } from "@/consts/parameters"; 5 | import useDebounce from "@/hooks/useDebounce"; 6 | import { SearchIcon } from "@/icons/SearchIcon"; 7 | import { useEffect, useState } from "react"; 8 | import { Helmet } from "react-helmet"; 9 | import { NFT } from "thirdweb"; 10 | import { getContractMetadata } from "thirdweb/extensions/common"; 11 | import { getNFT, getNFTs, totalSupply } from "thirdweb/extensions/erc721"; 12 | import { useReadContract } from "thirdweb/react"; 13 | 14 | function App() { 15 | const nftsPerPage = 30; 16 | const [page, setPage] = useState(1); 17 | const [search, setSearch] = useState(""); 18 | const debouncedSearchTerm = useDebounce(search, 500); 19 | const { data: nfts, isLoading } = useReadContract(getNFTs, { 20 | contract: nftContract, 21 | count: nftsPerPage, 22 | start: (page - 1) * nftsPerPage, 23 | }); 24 | const { data: totalCount } = useReadContract(totalSupply, { 25 | contract: nftContract, 26 | }); 27 | const { data: contractMetadata, isLoading: contractLoading } = 28 | useReadContract(getContractMetadata, { 29 | contract: nftContract, 30 | }); 31 | const [nft, setNft] = useState(null); 32 | const [isSearching, setIsSearching] = useState(false); 33 | 34 | const fetchNFT = async () => { 35 | const nft = await getNFT({ 36 | contract: nftContract, 37 | tokenId: BigInt(debouncedSearchTerm), 38 | }); 39 | setNft(nft!); 40 | setIsSearching(false); 41 | }; 42 | 43 | useEffect(() => { 44 | if (debouncedSearchTerm) { 45 | setIsSearching(true); 46 | fetchNFT(); 47 | } else { 48 | setNft(null); 49 | } 50 | }, [debouncedSearchTerm]); 51 | 52 | return ( 53 |
54 |
55 | 56 | 57 | {contractMetadata?.name} 58 | 59 | 60 |
61 | {contractMetadata ? ( 62 |
63 |

64 | {contractMetadata.name} 65 |

66 |

67 | {contractMetadata.description} 68 |

69 |
70 | ) : contractLoading ? ( 71 |
72 |
73 |
74 |
75 | ) : null} 76 | 77 |
78 | 79 | { 82 | if ( 83 | e.target.value.match(/^[0-9]*$/) && 84 | Number(e.target.value) > 0 85 | ) { 86 | setSearch(e.target.value); 87 | } else { 88 | setSearch(""); 89 | } 90 | }} 91 | placeholder="Search by Token ID" 92 | className="w-full bg-transparent px-4 text-white focus:outline-none" 93 | /> 94 |
95 | 96 | {isSearching ? ( 97 |
98 | ) : null} 99 | 100 | {search && nft && !isSearching ? ( 101 | 102 | ) : null} 103 | 104 | {isLoading && ( 105 |
106 | {Array.from({ length: nftsPerPage }).map((_, i) => ( 107 |
111 | ))} 112 |
113 | )} 114 | 115 | {nfts && !search && ( 116 |
117 | {nfts.map((nft) => ( 118 | 119 | ))} 120 |
121 | )} 122 | 123 | {!search && ( 124 |
131 | )} 132 |
133 |
134 | ); 135 | } 136 | 137 | export default App; 138 | -------------------------------------------------------------------------------- /src/pages/nft/$id.tsx: -------------------------------------------------------------------------------- 1 | import { HistoryCard } from "@/components/HistoryCard"; 2 | import { Header } from "@/components/Nav/Header"; 3 | import { PoweredBy } from "@/components/PoweredBy"; 4 | import { client, nftContract } from "@/consts/parameters"; 5 | import { truncateAddress } from "@/utils/truncateAddress"; 6 | import { useEffect } from "react"; 7 | import { Helmet } from "react-helmet"; 8 | import { useParams } from "react-router-dom"; 9 | import { 10 | MediaRenderer, 11 | useContractEvents, 12 | useReadContract, 13 | } from "thirdweb/react"; 14 | import { getNFT, transferEvent } from "thirdweb/extensions/erc721"; 15 | import { getContractMetadata } from "thirdweb/extensions/common"; 16 | 17 | const NFTPage = () => { 18 | const { id } = useParams(); 19 | const { data: nft, isLoading } = useReadContract(getNFT, { 20 | contract: nftContract, 21 | tokenId: BigInt(id as string), 22 | }); 23 | const { data: contractMetadata } = useReadContract(getContractMetadata, { 24 | contract: nftContract, 25 | }); 26 | const { data: eventsData, isLoading: eventsLoading } = useContractEvents({ 27 | contract: nftContract, 28 | events: [ 29 | transferEvent({ 30 | tokenId: BigInt(id as string), 31 | }), 32 | ], 33 | }); 34 | useEffect(() => { 35 | window.scrollTo(0, 0); 36 | }, []); 37 | 38 | return ( 39 |
40 |
41 | 42 | 43 | {nft?.metadata.name} 44 | 45 | 46 |
47 |
48 | {nft ? ( 49 | 54 | ) : ( 55 | isLoading && ( 56 |
57 | ) 58 | )} 59 | 60 | {eventsData && eventsData?.length > 0 ? ( 61 |

62 | History 63 |

64 | ) : ( 65 | isLoading && ( 66 |
67 | ) 68 | )} 69 | 70 | {eventsLoading ? ( 71 |
72 | ) : ( 73 |
74 | {eventsData?.map((event) => ( 75 | 76 | ))} 77 |
78 | )} 79 |
80 | 81 |
82 |
83 | {contractMetadata?.name ? ( 84 |

85 | collection 86 |

87 | ) : ( 88 | isLoading && ( 89 |
90 | ) 91 | )} 92 | 93 | {isLoading ? ( 94 |
95 | ) : ( 96 |

97 | {contractMetadata?.name} 98 |

99 | )} 100 |
101 | 102 |
103 |

104 | #{id} 105 |

106 | 107 | {nft?.metadata.name ? ( 108 |

109 | {String(nft?.metadata.name).split("#")[0]} 110 |

111 | ) : ( 112 | isLoading && ( 113 |
114 | ) 115 | )} 116 |
117 | 118 |
119 | {nft?.owner ? ( 120 |

121 | CURRENT OWNER 122 |

123 | ) : ( 124 | isLoading && ( 125 |
126 | ) 127 | )} 128 | 129 | {isLoading ? ( 130 |
131 | ) : ( 132 |

133 | {nft?.owner ? truncateAddress(nft?.owner!) : "N/A"} 134 |

135 | )} 136 |
137 | 138 | {nft?.metadata.description ? ( 139 |

140 | Description 141 |

142 | ) : ( 143 | isLoading && ( 144 |
145 | ) 146 | )} 147 | 148 | {isLoading ? ( 149 |
150 | ) : ( 151 |

152 | {nft?.metadata.description} 153 |

154 | )} 155 | 156 |
157 | {nft?.metadata.attributes && 158 | // @ts-ignore 159 | nft?.metadata.attributes.length > 0 && ( 160 | <> 161 | {isLoading ? ( 162 |
163 | ) : ( 164 |

165 | Attributes 166 |

167 | )} 168 |
169 | {/* @ts-ignore */} 170 | {nft?.metadata.attributes?.map( 171 | (attr: { trait_type: string; value: string }) => ( 172 |
173 |

174 | {attr.trait_type} 175 |

176 |

177 | {attr.value} 178 |

179 |
180 | ), 181 | )} 182 |
183 | 184 | )} 185 | 186 | {eventsData && eventsData?.length > 0 ? ( 187 |

188 | History 189 |

190 | ) : ( 191 | isLoading && ( 192 |
193 | ) 194 | )} 195 | 196 | {eventsLoading ? ( 197 |
198 | ) : ( 199 |
200 | {eventsData?.map((event) => ( 201 | 202 | ))} 203 |
204 | )} 205 |
206 | 207 |
208 | 209 |
210 |
211 |
212 |
213 | ); 214 | }; 215 | 216 | export default NFTPage; 217 | -------------------------------------------------------------------------------- /src/utils/truncateAddress.ts: -------------------------------------------------------------------------------- 1 | export const truncateAddress = (address: string) => { 2 | return `${address.slice(0, 6)}...${address.slice(-4)}`; 3 | }; 4 | -------------------------------------------------------------------------------- /src/vite-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | export default { 3 | content: ["./index.html", "./src/**/*.{js,ts,jsx,tsx}"], 4 | theme: { 5 | extend: { 6 | fontFamily: { 7 | inter: ["Inter", "sans-serif"], 8 | }, 9 | }, 10 | }, 11 | plugins: [], 12 | }; 13 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ESNext", 4 | "useDefineForClassFields": true, 5 | "lib": [ 6 | "DOM", 7 | "DOM.Iterable", 8 | "ESNext" 9 | ], 10 | "allowJs": false, 11 | "skipLibCheck": true, 12 | "esModuleInterop": false, 13 | "allowSyntheticDefaultImports": true, 14 | "strict": true, 15 | "forceConsistentCasingInFileNames": true, 16 | "module": "ESNext", 17 | "moduleResolution": "Node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx", 22 | "baseUrl": ".", 23 | "paths": { 24 | "@/*": [ 25 | "src/*" 26 | ] 27 | } 28 | }, 29 | "include": [ 30 | "src" 31 | ], 32 | "references": [ 33 | { 34 | "path": "./tsconfig.node.json" 35 | } 36 | ] 37 | } -------------------------------------------------------------------------------- /tsconfig.node.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "composite": true, 4 | "module": "ESNext", 5 | "moduleResolution": "Node", 6 | "allowSyntheticDefaultImports": true 7 | }, 8 | "include": ["vite.config.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "rewrites": [{ "source": "/(.*)", "destination": "/" }] 3 | } 4 | -------------------------------------------------------------------------------- /vite.config.ts: -------------------------------------------------------------------------------- 1 | import react from "@vitejs/plugin-react-swc"; 2 | import { defineConfig } from "vite"; 3 | import { nodePolyfills } from "vite-plugin-node-polyfills"; 4 | 5 | export default defineConfig({ 6 | plugins: [react(), nodePolyfills()], 7 | define: { 8 | "process.env": {}, 9 | }, 10 | resolve: { 11 | alias: { 12 | "@": "/src", 13 | }, 14 | }, 15 | }); 16 | --------------------------------------------------------------------------------