Skip to content

AbhinavXT/Eternal-Market

Repository files navigation

Eternal Domain Marketplace

Table of Contents:

Deployed Website url

https://eternal-market.vercel.app/

Screencast link

https://youtu.be/D9Itp9Ttwtw

Project Description

Eternal Domain is a marketplace where users can buy, sell and mint Eternal Characters, which are ERC-721 standard (NFT) tokens.

Eternal Characters are the residents of Eternal Domain world. They consists of 3 main characteristics, Area of Control, Weapon and Rank.

  • Area of Control - Fire, Wind, Wave, Earth, Light, Shadow, Thunder, Space, Time, Gravity, Ice
  • Weapon - Sword, Spear, Shield, Hammer, Saber, Axe, Bow, Staff, Wand, Fist, Dagger, Scythe, Mace, Blade, Katana
  • Rank - Lord, King, Emperor, Venerable, Ancestor, Saint, God

Workflow

  1. Enter the dApp and connect the wallet to rinkeby network.
  2. After entering the dApp the user can:
    1. Buy Characters
      • Go to the Home page and click on the item which user want to buy.
      • User will be redirected to the BuyNFT page which shows the price and other details about the item.
      • Click on the Buy button to buy the item.
      • Metamask pops up and asks to confirm the transaction for the price of the item.
      • After the transaction is successfully processed user is redirected to the My NFT page.
      • The bought item is displayed under the Bought Characters section
    2. Mint Characters
      • Go to the mint page and click on the Mint Character button.
      • Metamask pops up and asks to confirm the transaction.
      • After the transaction is successfully processed the user can see the minted character.
      • The minted character is also added to My NFT page under Minted Characters section.
    3. Sell Characters
      • Go to the My NFT page and click on the Sell button under the minted item which user want to sell.
      • User will be redirected to the SellNFT page where user can enter the price for the item.
      • After entering the desired price, click on the Sell button to list the item in the market place.
      • Metamask pops up and asks to confirm the transaction for the listing price.
      • After the transaction is successfully processed user is redirected to the Home page.
      • The item will be listed in the marketplace to be bought for the price entered by the user.

Directory structure

blockchain-developer-bootcamp-final-project
 ┣ client
 ┃ ┣ pages
 ┃ ┃ ┣ _app.js
 ┃ ┃ ┣ buynft.js
 ┃ ┃ ┣ index.js
 ┃ ┃ ┣ mint.js
 ┃ ┃ ┣ mynft.js
 ┃ ┃ ┗ sellnft.js
 ┃ ┣ public
 ┃ ┃ ┣ favicon.ico
 ┃ ┃ ┗ vercel.svg
 ┃ ┣ utils
 ┃ ┃ ┣ EternalMarketplace.json
 ┃ ┃ ┗ EternalNFT.json
 ┃ ┣ .gitignore
 ┃ ┣ README.md
 ┃ ┣ config.js
 ┃ ┣ package-lock.json
 ┃ ┣ package.json
 ┃ ┣ postcss.config.js
 ┃ ┗ tailwind.config.js
 ┣ contracts
 ┃ ┣ libraries
 ┃ ┃ ┗ Base64.sol
 ┃ ┣ EternalMarketplace.sol
 ┃ ┗ EternalNFT.sol
 ┣ scripts
 ┃ ┣ deploy.js
 ┃ ┗ run.js
 ┣ test
 ┃ ┗ eternalTest.js
 ┣ .gitignore
 ┣ README.md
 ┣ avoiding_common_attacks.md
 ┣ deployed_address.txt
 ┣ design_pattern_decisions.md
 ┣ hardhat.config.js
 ┣ package-lock.json
 ┗ package.json

Clone, Install and Build steps

Prerequisites

  1. Git
  2. Node JS (everything was installed and tested under v15.12.0)
  3. A Browser with the MetaMask extension installed.
  4. Test Ether on the Rinkeby network.

Cloning and installing dependencies

  1. Clone the project repository on your local machine
 git clone https://github.com/AbhinavXT/Eternal-Market.git

 cd Eternal-Market
  1. Installing dependencies
  • For contracts -
    npm install
    
  • For client -
    cd client
    npm install
    

Testing Contracts

For testing contracts run command:

npx hardhat test

Running the frontend

For running frontend locally run command:

cd client
npm run dev

Auto-Funding

This Starter Kit is configured by default to attempt to auto-fund any newly deployed contract that uses Any-API or Chainlink VRF, to save having to manually fund them after each deployment. The amount in LINK to send as part of this process can be modified in the Starter Kit Config, and are configurable per network.

Parameter Description Default Value
fundAmount Amount of LINK to transfer when funding contracts 1 LINK

If you wish to deploy the smart contracts without performing the auto-funding, run the following command when doing your deployment:

npx hardhat deploy --tags main

Deploying and running against a local instance

  1. For deploying and running the dApp against a local instance run commands:
npx hardhat node
  1. This should create a local network with 19 accounts. Keep it running, and in another terminal run:
npx hardhat deploy --network localhost
  1. When the deployment is complete, the CLI should print out the addresses of the contracts that were deployed:
nftMarket contract deployed to: 'EternalMarketplace contract address'

nft contract deployed to: 'EternalNFT contract address'
  1. Copy these addresses and paste them in the config.js file inside the client folder, in place of current addresses.
export const nftContractAddress = 'EternalMarketplace contract address'

export const nftMarketAddress = 'EternalNFT contract address''
  1. For importing account to metamask

    1. Import account using private key from one of the accounts that were logged on running npx hardhat node
    2. Create a custom network (if not already there) pointing to http://127.0.0.1:8545 with chainId 1337
    3. Switch to this network and connect it to the dApp and reload it.
    4. For better testing of the transfer of tokens and transactions import at least 2 accounts*_
    5. For changing chainId and other possible errors see Troubleshooting
  2. Now run the frontend locally in another terminal using command:

cd client
npm run dev

After this you can run and test the dApp locally in your web browser.

Run

The deployment output will give you the contract addresses as they are deployed. You can then use these contract addresses in conjunction with Hardhat tasks to perform operations on each contract

VRF Get a random number

The VRFConsumer contract has two tasks, one to request a random number, and one to read the result of the random number request. This contract needs to be funded with link first:

npx hardhat fund-link --contract insert-contract-address-here --network network

Once it's funded, you can perform a VRF request with the request-random-number task:

npx hardhat request-random-number --contract insert-contract-address-here --network network

Once you have successfully made a request for a random number, you can see the result via the read-random-number task:

npx hardhat read-random-number --contract insert-contract-address-here --network network

Troubleshooting

For custom chainId

The default chainId for network localhost8545 is 1337. To change the chainId, the user should follow these steps :

  1. Change the chainId in networks under hardhat in hardhat.config.js file.
hardhat: {
  chainId: 1337,
}
  1. After this the user needs to change the chainId in the _app.js file on line 61 and 86 under the functions connectWallet() and checkCorrectNetwork() respectively.
const devChainId = 1337

For 'Nonce too High' Error

While testing the dApp on against a local instance, if you get the Nonce too high error in the hardhat node terminal or the UI does not show processing your transaction after confirming a transaction, try resetting your metamask account. This can be done by going to Settings > Advanced > Reset Account in Metamask.

About

Marketplace to buy Eternal Domain NFTs. Built using Solidity, JavaScript, Hardhat, Chainlink, ethers.js, Next.js and TailwindCSS

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published