|
| 1 | +# NFT Minting dApp Starter |
| 2 | + |
| 3 | +A full stack dApp starter for minting NFTs built on Ethereum (Solidity) with Next.js (React). |
| 4 | + |
| 5 | +This repo contains boilerplate code for minting NFTs from the client-side using [Solidity](https://soliditylang.org/), [React](https://reactjs.org/) and [TailwindCSS](https://tailwindcss.com/). |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +## Prerequisites |
| 10 | + |
| 11 | +- [Node.js](https://nodejs.org/en/download/) |
| 12 | +- [MetaMask wallet browser extension](https://metamask.io/download.html). |
| 13 | + |
| 14 | +## Getting Started |
| 15 | + |
| 16 | +### Clone This Repo |
| 17 | + |
| 18 | +Use `git clone https://github.com/tomhirst/nft-minting-dapp-starter.git` to get the files within this repository onto your local machine. |
| 19 | + |
| 20 | +### Environment Setup |
| 21 | + |
| 22 | +Duplicate `.env.example` to `.env` and fill out the `HARDHAT_CHAIN_ID` environment variable. The port from the example file, if it's free, will be fine in most cases. |
| 23 | + |
| 24 | +Run `npm install`. |
| 25 | + |
| 26 | +### Running The Smart Contract Locally |
| 27 | + |
| 28 | +Compile the ABI for the smart contract using `npx hardhat compile`. |
| 29 | + |
| 30 | +If you're successful, you'll recieve a confirmation message of: |
| 31 | + |
| 32 | +``` |
| 33 | +Compilation finished successfully |
| 34 | +``` |
| 35 | + |
| 36 | +And, a `src/artifacts` folder will be created in your project. |
| 37 | + |
| 38 | +Deploy the smart contract to the local blockchain for testing with `npx hardhat node`. |
| 39 | + |
| 40 | +If you're successful, you'll be presented with a number of account details in the CLI. Here's an example: |
| 41 | + |
| 42 | +``` |
| 43 | +Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH) |
| 44 | +Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 |
| 45 | +``` |
| 46 | + |
| 47 | +Then in a new terminal window, `npx hardhat run scripts/deploy.js --network localhost`. |
| 48 | + |
| 49 | +If you're successful, you'll get something like the following CLI output: |
| 50 | + |
| 51 | +``` |
| 52 | +Minter deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0 |
| 53 | +``` |
| 54 | + |
| 55 | +### Adding A Local Account To MetaMask |
| 56 | + |
| 57 | +Open your MetaMask browser extension and change the network to `Localhost 8545`. |
| 58 | + |
| 59 | +Next, import one of the accounts by adding its Private Key (for example, `0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80` to MetaMask. |
| 60 | + |
| 61 | +If you're successful, you should see the a balance resembling something like `10000 ETH` in the wallet. |
| 62 | + |
| 63 | +### Connecting The Front-End |
| 64 | + |
| 65 | +In `.env` set the `NEXT_PUBLIC_MINTER_ADDRESS` environment variable to the address your smart contract was deployed to. For example, `0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0`. |
| 66 | + |
| 67 | +In a new terminal window, load the front-end with `npm run dev`. If you want to use an alternate port from `3000`, use `npm run dev -- --port=1234`, or whatever port number you prefer. |
| 68 | + |
| 69 | +## Demo'ing The Functionality |
| 70 | + |
| 71 | +Once set up, go to `localhost:3000` (or whatever post number you used), to view your dApp in the browser. |
| 72 | + |
| 73 | +First, connect your wallet by clicking `Connect wallet`. Ensure you're connected to the `Localhost 8454` network in your MetaMask extension. Select the wallet that you imported earlier. |
| 74 | + |
| 75 | +You can now test minting tokens, between 1 and 10 per transaction, by filling out the input with your desired amount and clicking the `Mint` button. |
| 76 | + |
| 77 | +If you successfully mint a number of NFTs, you should see the `Tokens minted` amount increment. |
| 78 | + |
| 79 | +Switching accounts in MetaMask will update the wallet address in the top right hand corner. Disconnecting all accounts will prompt you to connect your wallet. |
| 80 | + |
| 81 | +All state is retained on browser refresh. |
| 82 | + |
| 83 | +## Editing The Front-End |
| 84 | + |
| 85 | +To modify the front page of your application, edit `pages/index.js`. |
| 86 | + |
| 87 | +All [TailwindCSS classes](https://tailwindcss.com/docs) are available to you. |
| 88 | + |
| 89 | +To lint your front-end code, use `npm run lint`. |
| 90 | + |
| 91 | +## Testing |
| 92 | + |
| 93 | +To test the smart contract, run `npx hardhat test`. |
| 94 | + |
| 95 | +Basic tests can be found in `test/Minter.test.js`. |
| 96 | + |
| 97 | +## Roadmap |
| 98 | + |
| 99 | +- Show the funds available in the connected account's wallet |
| 100 | +- Add common owner functionality to the contract |
| 101 | + - Reserve tokens |
| 102 | + - Flip sale state |
| 103 | + - Set starting index |
| 104 | + - Set base URI for asset metadata |
| 105 | + - Set provenance hash |
| 106 | + - Withdraw funds |
| 107 | +- Attach image data to minted tokens with IPFS |
| 108 | +- Deploy to the Ropsten test network |
| 109 | +- Introduce code style rules and linting |
| 110 | +- Write more extensive tests |
| 111 | +- Create a TypeScript fork |
0 commit comments