# <%= projectName %>

This project was created by <%= author %>!

This project was generated by [Infura Cruxy](https://github.com/anataliocs/infura-web3-cruxy)!

Cruxy is a CLI tool that automatically generates an Infura project based on specific parameters supplied by you!

## Run Project Locally

### 1. Installation

Clone the project

```bash
  git clone git@github.com:<%= githubName %>/<%= projectName %>.git
```

Go to the project directory

```bash
  cd <%= projectName %>
```

Install dependencies

```bash
  yarn
```

### 2. Environment Variables

Create environment variables file

```bash
  cp template.env .env
```

Add your Infura project IDs and Secrets to the `.env` file.

Setup your .env file:

```

  # Send Transaction Variables
  NEXT_PUBLIC_WEB3_TEST_ETHEREUM_NETWORK=goerli
  NEXT_PUBLIC_WEB3_INFURA_API_KEY=[Your WEB3 Infura Project]

  # IPFS Variables
  NEXT_PUBLIC_INFURA_IPFS_ENDPOINT=https://ipfs.infura.io:5001
  NEXT_PUBLIC_INFURA_IPFS_PROJECT_ID=[Your IPFS Infura Project ID]
  NEXT_PUBLIC_INFURA_IPFS_PROJECT_SECRET=[Your IPFS Infura Project Secret]

  # Minting Variables
  WALLET_MNEMONIC=
  NEXT_PUBLIC_MINTING_INFURA_PROJECT_ID=[Your WEB3 Infura Project]
  NEXT_PUBLIC_SMART_CONTRACT_ADDRESS=[The hash of the deployed contract on goerli]
```

### 3. Run the Project

```bash
  yarn dev
```

# Send Transaction

The user can connect to MetaMask, send a transaction, then review a transaction, using [Infura](https://infura.io).

### 1 - Fund Your Wallet With Testnet Ether

In your MetaMask wallet, switch to the `Goerli Test Network` (you may have to click "show/hide test networks" and toggle the setting to see the Goerli network)

Go to https://faucet.paradigm.xyz/, connect your wallet, and then request the test ETH be sent to your account.

### 2 - Connect Wallet

Go to http://localhost:3000/transaction/connect and click `Connect Wallet`

In `/api/balance.ts` we are using the Infura API [eth_getBalance](https://docs.infura.io/infura/networks/ethereum/json-rpc-methods/eth_getbalance) to get the current balance of ETH in the connected wallet account.

### 3 - Transfer ETH

Enter a wallet address for the wallet that you are going to be tranferring **to** (you can create an additional account in your MetaMask wallet to send to)

Enter the amount of testnet Ether you want to transfer (i.e. 0.001 ETH)

Hit `Submit` and if your wallet has sufficient funds the transaction will be mined (Note that the transaction may take a while to finish up, testnets can often be a bit slow)

When the transaction is mined you'll see a confirmation screen with the `transaction hash`, copy the hash to the clipboard for the next step

### 4 - Review

Paste your transaction hash from the previous step and click `Review`

You should then see the transaction details.


# Mint an NFT

In this project the user will deploy a smart contract using Truffle, upload to IPFS, and mint an NFT.

### 1 - Fund your wallet

In your MetaMask wallet, switch to the `Goerli Test Network` (you may have to click "show/hide test networks" and toggle the setting to see the Goerli network)

Go to https://faucet.paradigm.xyz/, connect your wallet, and then request the test ETH

### 2 - Deploy a Smart Contract

1. Install Truffle: `yarn global add truffle`

   [Truffle](https://trufflesuite.com/) is a development environment, testing framework, and asset pipeline for blockchains using the Ethereum Virtual Machine. The suite of Truffle tools is quite powerful, we're going to be using Truffle's built-in smart contract compilation, linking, deployment, and binary management.

   The truffle project has already been initialized so you'll see `contracts/`, `migrations/`, and `truffle-config.js` already in the project structure.

2. Add your wallet mnemonic (the twelve-word phrase the wallet uses to generate public/private key pairs) and your Infura project ID for an Ethereum project (this can be the same project ID as the Send Transaction Project) to your environment variables. We'll use the goerli network for this example so you can preview your minted nft on OpenSea Testnets.

   ```bash

   # Minting Variables
    WALLET_MNEMONIC=
    NEXT_PUBLIC_MINTING_INFURA_PROJECT_ID=[Your WEB3 Infura Project]
   ```

   **IMPORTANT:** Be careful not to share or commit your wallet mnemonic, it can be used to access your wallet accounts and their contents.

3. In `/contracts/NFTContract.sol` you'll find a basic smart contract for minting NFTs. This contract uses [OpenZeppelin](https://docs.openzeppelin.com/) - a trusted open-source library of Solidity smart contracts - to construct an ERC721 Token Contract. ERC721 is a token standard for representing ownership of non-fungible tokens (i.e. where each token is unique).

   In `NFTContract.sol` give your NFT collection a name and symbol. Each NFT minted with this contract will have an ID number. The `tokenCounter` will act as the ID and the contract will increment the counter as new NFTs are minted.

4. In your terminal run

   ```bash
   truffle compile
   ```

   This will add a `build/` folder to the project structure (do not delete)

5. Migrate the smart contract onto the chain by running

   ```bash
   truffle migrate --network goerli
   ```

   **IMPORTANT:** After your migration completes, copy the `contract address` in the cli output and add it to your environment variables

   ```bash

   # Minting Variables
   WALLET_MNEMONIC=
   NEXT_PUBLIC_MINTING_INFURA_PROJECT_ID=
   NEXT_PUBLIC_SMART_CONTRACT_ADDRESS=
   ```

### 3 - Start the app

In your terminal, run

```bash
yarn dev
```

and go to http://localhost:3000/mint

### 4 - Upload to IPFS

Select the file for your NFT and give it a name, description, and attributes (optional), then click `UPLOAD` to upload the NFT metadata to IPFS.

Visit the IPFS documentation above for more details.

**IMPORTANT**: Make sure to copy the tokenURI (IPFS hash) for the uploaded object.

### 5 - Mint

on the `http://localhost:3000/mint/mint` page, paste the token URI you copied in the previous step into the input field. Press submit and wait as your NFT is minted. The results will be displayed when the process is complete.

You can view your collection on OpenSea by searching for the contract address on [OpenSea's Testnet site](https://testnets.opensea.io/)
