├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── postcss.config.js ├── src ├── utils │ ├── hash.js │ └── wagmi-config.js ├── components │ ├── Address.jsx │ ├── Footer.jsx │ ├── NFT.jsx │ ├── Verify.jsx │ ├── Home.jsx │ ├── Mint.jsx │ ├── layout │ │ └── Navbar.jsx │ ├── Loading.jsx │ └── NFTs.jsx ├── reportWebVitals.js ├── index.css ├── index.js ├── App.js ├── App.css └── contracts │ ├── ModelNFT.sol │ ├── ModelNFT-hash.sol │ └── abi.json ├── tailwind.config.js ├── .gitignore ├── package.json └── README.md /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shafu0x/NFT-Pytorch-Callback-Frontend/main/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shafu0x/NFT-Pytorch-Callback-Frontend/main/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shafu0x/NFT-Pytorch-Callback-Frontend/main/public/logo512.png -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /src/utils/hash.js: -------------------------------------------------------------------------------- 1 | export function add0x(hash) { 2 | if (!hash.startsWith("0x")) { 3 | return "0x" + hash; 4 | } else { 5 | return hash; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('tailwindcss').Config} */ 2 | module.exports = { 3 | content: ["./src/**/*.{js,jsx,ts,tsx}"], 4 | theme: { 5 | extend: {}, 6 | }, 7 | plugins: [], 8 | }; 9 | -------------------------------------------------------------------------------- /src/components/Address.jsx: -------------------------------------------------------------------------------- 1 | import { Input } from "@chakra-ui/react"; 2 | 3 | export default function Address({ address, setAddress }) { 4 | return ( 5 |
6 | setAddress(e.target.value)} /> 7 |
8 | ); 9 | } 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | 15 | @tailwind base; 16 | @tailwind components; 17 | @tailwind utilities; 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { WagmiConfig } from "wagmi"; 2 | import "./App.css"; 3 | import { client, chains } from "./utils/wagmi-config"; 4 | import { ChakraProvider } from "@chakra-ui/react"; 5 | import { RainbowKitProvider } from "@rainbow-me/rainbowkit"; 6 | import "@rainbow-me/rainbowkit/styles.css"; 7 | import Home from "./components/Home"; 8 | // import "antd/dist/antd.css"; // or 'antd/dist/antd.less' 9 | 10 | function App() { 11 | return ( 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | ); 20 | } 21 | 22 | export default App; 23 | -------------------------------------------------------------------------------- /src/utils/wagmi-config.js: -------------------------------------------------------------------------------- 1 | import { 2 | WagmiConfig, 3 | createClient, 4 | configureChains, 5 | defaultChains, 6 | chain, 7 | } from "wagmi"; 8 | import { publicProvider } from "wagmi/providers/public"; 9 | import { getDefaultWallets, RainbowKitProvider } from "@rainbow-me/rainbowkit"; 10 | 11 | export const { chains, provider, webSocketProvider } = configureChains( 12 | [chain.mainnet, chain.polygon, chain.rinkeby], 13 | [publicProvider()] 14 | ); 15 | 16 | const { connectors } = getDefaultWallets({ 17 | appName: "My RainbowKit App", 18 | chains, 19 | }); 20 | 21 | export const client = createClient({ 22 | autoConnect: true, 23 | connectors, 24 | provider, 25 | webSocketProvider, 26 | }); 27 | -------------------------------------------------------------------------------- /src/components/Footer.jsx: -------------------------------------------------------------------------------- 1 | import { Box, HStack, useColorModeValue } from "@chakra-ui/react"; 2 | 3 | export const Footer = () => { 4 | return ( 5 | 6 | 7 | 8 | 9 |
10 |
Created By:
11 | 12 |
@elfouly_sharif
13 |
14 |
15 |
16 |
17 |
18 |
19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/components/NFT.jsx: -------------------------------------------------------------------------------- 1 | import { RadarChartOutlined } from "@ant-design/icons"; 2 | 3 | export default function NFT({ id, name, hash }) { 4 | return ( 5 |
6 |
10 |
11 |
{id}
12 | 13 |
14 |
{hash}
15 |
16 |
17 |
{name}
18 |
19 |
20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /src/components/Verify.jsx: -------------------------------------------------------------------------------- 1 | import { UploadOutlined } from "@ant-design/icons"; 2 | import { Button, message, Upload } from "antd"; 3 | 4 | export default function Verify() { 5 | return ( 6 |
7 |
8 |
Verify
9 |
10 |
11 | 17 | { 22 | console.log(e.target.files[0]); 23 | }} 24 | /> 25 |
26 |
27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /src/contracts/ModelNFT.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | import "@openzeppelin/contracts@4.7.3/token/ERC721/ERC721.sol"; 5 | import "@openzeppelin/contracts@4.7.3/access/Ownable.sol"; 6 | import "@openzeppelin/contracts@4.7.3/utils/Counters.sol"; 7 | 8 | contract ModelNFT is ERC721, Ownable { 9 | struct Model { 10 | uint256 id; 11 | string name; 12 | string hash; 13 | } 14 | 15 | using Counters for Counters.Counter; 16 | 17 | mapping(address => Model[]) public models; 18 | 19 | Counters.Counter private _tokenIdCounter; 20 | 21 | constructor() ERC721("ModelNFT", "MNFT") {} 22 | 23 | function safeMint(string memory name, string memory hash) public { 24 | // tokenID 25 | uint256 tokenId = _tokenIdCounter.current(); 26 | _tokenIdCounter.increment(); 27 | 28 | // update models 29 | Model[] storage modelList = models[msg.sender]; 30 | modelList.push(Model(tokenId, name, hash)); 31 | models[msg.sender] = modelList; 32 | 33 | // mint 34 | _safeMint(msg.sender, tokenId); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /src/contracts/ModelNFT-hash.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity ^0.8.4; 3 | 4 | import "@openzeppelin/contracts@4.7.3/token/ERC721/ERC721.sol"; 5 | import "@openzeppelin/contracts@4.7.3/access/Ownable.sol"; 6 | import "@openzeppelin/contracts@4.7.3/utils/Counters.sol"; 7 | 8 | contract ModelNFT is ERC721, Ownable { 9 | struct Model { 10 | uint256 id; 11 | string name; 12 | string loss; 13 | string epoch; 14 | bytes32 hash; 15 | uint256 timestamp; 16 | } 17 | 18 | using Counters for Counters.Counter; 19 | 20 | mapping(address => Model[]) public models; 21 | 22 | Counters.Counter private _tokenIdCounter; 23 | 24 | constructor() ERC721("ModelNFT", "MNFT") {} 25 | 26 | function safeMint(string memory name, string memory loss, string memory epoch) public { 27 | // generate hash 28 | uint256 tokenId = _tokenIdCounter.current(); 29 | bytes32 hash = keccak256(abi.encodePacked(msg.sender, block.timestamp, tokenId, name, loss, epoch)); 30 | _tokenIdCounter.increment(); 31 | 32 | // update models 33 | Model[] storage modelList = models[msg.sender]; 34 | modelList.push(Model(tokenId, name, loss, epoch, hash, block.timestamp)); 35 | models[msg.sender] = modelList; 36 | 37 | // mint 38 | _safeMint(msg.sender, tokenId); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "web3-template", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@ant-design/icons": "^4.7.0", 7 | "@chakra-ui/react": "^2.3.1", 8 | "@emotion/react": "^11.10.4", 9 | "@emotion/styled": "^11.10.4", 10 | "@rainbow-me/rainbowkit": "^0.5.0", 11 | "@testing-library/jest-dom": "^5.16.5", 12 | "@testing-library/react": "^13.3.0", 13 | "@testing-library/user-event": "^13.5.0", 14 | "antd": "^4.22.8", 15 | "ethers": "^5.7.0", 16 | "framer-motion": "^7.2.1", 17 | "react": "^18.2.0", 18 | "react-dom": "^18.2.0", 19 | "react-scripts": "5.0.1", 20 | "wagmi": "^0.6.4", 21 | "web-vitals": "^2.1.4" 22 | }, 23 | "scripts": { 24 | "start": "react-scripts start", 25 | "build": "react-scripts build", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": [ 31 | "react-app", 32 | "react-app/jest" 33 | ] 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | }, 47 | "devDependencies": { 48 | "autoprefixer": "^10.4.8", 49 | "postcss": "^8.4.16", 50 | "tailwindcss": "^3.1.8" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/components/Home.jsx: -------------------------------------------------------------------------------- 1 | import { useEffect, useState } from "react"; 2 | import { NavBar } from "./layout/Navbar"; 3 | import Mint from "./Mint"; 4 | import { useAccount } from "wagmi"; 5 | import NFTs from "./NFTs"; 6 | 7 | export default function Home() { 8 | const { address, isConnected } = useAccount(); 9 | 10 | const [reload, setReload] = useState(false); 11 | const [customAddress, setAddress] = useState(address); 12 | 13 | useEffect(() => { 14 | setAddress(address); 15 | }, [isConnected]); 16 | 17 | return ( 18 | <> 19 | 20 |
21 |
22 | {/* */} 23 | 24 |
25 |
Models
26 | {customAddress && ( 27 | 33 | )} 34 | {!isConnected && ( 35 |
36 | Connect your wallet to see your or other people's models! 37 |
38 | )} 39 |
40 |
41 |
42 | {/*