Skip to content

c4ei/arthouse

 
 

Repository files navigation

Art House

C4eiHouse is an NFT platform that allows you to create, buy and sell NFTs on multiple blockchains.

Quickstart

  1. yarn install

  2. yarn start

  3. Go to http://localhost:3000/

  4. Click on Create NFT

  5. Make sure that you can see the created NFT in NFT gallery

To build the project: yarn build

Here's a step-by-step tutorial on how to build your own C4eiHouse.

How it Works

C4eiHouse can do 4 things:

  1. Mint an NFT
  2. List an NFT for sale
  3. Buy an NFT
  4. Unlist an NFT

NFT Process

  1. Everytime a new NFT is minted it gets deployed to the provided smart contract on the relevant chain ID in config-chains.json
  2. When it gets listed for sale, approval is given by the account to the Market contract, the NFT is transferred to the address of the contract which will list the item for sale.
  3. When the account buys a listed item, the marketplace receives a commission of salesFeeBasisPoints (currently 250 basis points or 2.50%) and the seller receives the rest.
  4. The seller may choose to unlist an item at which point the ownership of the NFT will be transferred back to the seller and become unavailable for purchase in the market.

Run Hardhat in Console

To quickly run commands you can use the interactive hardhat console

npx hardhat console

const [ownerSigner, signer1, signer2] = await ethers.getSigners();
const ownerBalance = await ethers.provider.getBalance(ownerSigner.address);

Set up your Backend

  1. If you won't be deploying to a test net or mainnet, go to hardhat.config.js and comment out privateKey and all the networks except for networks.hardhat

  2. Put your private keys for the account that will be deploying the smart contract in a .secrets file. This will NOT be included in your version control. You can get the key from shared.secrets and run cp shared.secrets .secrets and replace the private key.

  3. Load the secret key source .secrets

  4. Compile the smart contracts to get the most recent change: npx hardhat compile

  5. Run your own local blockchain node using: npx hardhat node

Backend

Running Your Local Node

The backend for this project is a blockchain node. For development, you can run your own local blockchain node using: npx hardhat node

Deploying Smart Contracts

Deploying Locally

  1. Run smart contract deployment script: npx hardhat run scripts/deploy.js --network localhost

Deploying to live Testnet or Mainnet

Adding a New Chain

  1. Put your private keys for the account that will be deploying the smart contract in .secrets. This will NOT be included in your version control and run source .secrets.

  2. Add the chain information to src/config-chains.json

    1. Get Chain ID from:
      1. https://chainlist.org/
    2. Get an RPC URL for your desired blockchain (TODO: where to get good RPC urls)
      1. Binance: https://docs.binance.org/smart-chain/developer/rpc.html (TODO: add other chains)
    3. Add the apikey to .secrets
  3. Get some tokens to pay the gas fees for deploying the smart contracts. On testnets you can use a faucet:

    1. Ethereum Rinkeby: https://rinkebyfaucet.com
    2. Binance: https://testnet.binance.org/faucet-smart
    3. Polygon: https://faucet.polygon.technology
    4. Celo: https://celo.org/developers/faucet
    5. Harmony: https://faucet.pops.one
  4. Load secrets to your environment variable source .secrets

  5. Deploy the smart contract: npx hardhat deploy --chain-id [chainId]

    1. If you want to deploy just the NFT or the Market without deploying everything run:
      1. npx hardhat deploy:nft --chain-id [chainId]
      2. npx hardhat deploy:market --chain-id [chainId]
    2. Here are some examples:
    3. Ethereum Rinkeby: npx hardhat deploy --chain-id 4
    4. Binance Smart Chain Testnet: npx hardhat deploy --chain-id 97
    5. Polygon Mumbai: npx hardhat deploy --chain-id 80001

If the deploy script is not working you can also us the default hardhat deployment script. Make sure to update the CHAIN ID variable: TODO add a check that chainID matches the passed in network

npx hardhat run --network polygon scripts/deploy-hardhat.js

  1. Add the new chain information to README.md, see these commits below for examples of what to change:
    1. Ethereum
    2. Binance
    3. Polygon
    4. Celo

Smart Contract Addresses

Troubleshooting

If you see, the following doublecheck you set the correct credentials for your RPC URL:

Invalid JSON-RPC response received: {
  "message":"Invalid authentication credentials"
}

Adding Chains to Metamask

Localhost

  1. Switch to localhost 8545 in metamask

  2. Import private keys from test-accounts.txt

  3. Use accounts #0-3 for making, selling and buying NFTs between accounts

Testnets and Main

  1. Open Metamask extension and go to settings > networks (TODO add a 1-click button for adding networks)

Public RPCs may have traffic or rate-limits depending on usage.

So you may see the following error.

Could not fetch chain ID. Is your RPC URL correct?

If that happens, try a different URL or you can get a free dedicated free RPC URLS.

Celo Alfajores

Network Name: Celo (Alfajores Testnet)
New RPC URL: https://alfajores-forno.celo-testnet.org
Chain ID: 44787
Currency Symbol (Optional): CELO
Block Explorer URL (Optional): https://alfajores-blockscout.celo-testnet.org

Polygon:

Network Name: Mumbai TestNet
New RPC URL: https://rpc-mumbai.matic.today
Chain ID: 80001
Currency Symbol: Matic
Block Explorer URL: https://mumbai.polygonscan.com/

TODO: Get correct Browser settings for Rinkeby (although it's included by default in Metamask) [Rinkeby Ethereum]

Network Name: Mumbai TestNet
New RPC URL: https://rpc-mumbai.matic.today
Chain ID: 80001
Currency Symbol: Matic
Block Explorer URL: https://mumbai.polygonscan.com/

Harmony Testnet

Network Name: Harmony Testnet
RPC URL: https://api.s0.b.hmny.io
Chain ID: 1666700000
Currency Symbol: ONE
Block Explorer URL: https://explorer.pops.one/

Running Tests

Testing Smart Contracts

npx hardhat test

Test a specific feature: npx hardhat test --grep unListMarketItem

Sometimes you might try to run a test or a piece of code and find that a function is undefined. This might be due to an outdated artifacts build. Run npx hardhat compile --force to force a recompilation.

Deploying smart contracts

  1. Compile the smart contracts to get the most recent change: npx hardhat compile
  2. Load your environment variables using shared.env as a template

Resources

Inspired by Nader Dabit's Building a Full Stack NFT Marketplace on Ethereum with Polygon.

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 56.1%
  • JavaScript 28.5%
  • Solidity 9.2%
  • HTML 4.6%
  • SCSS 1.6%