Skip to content

NFT marketplaces often use techniques for reducing transaction fees. Some of these techniques require users to use these marketplaces with an off-chain sibling system that assist the on-chain pieces. This is a simple off-chain system and the on-chain smart-contract to enable cheap auctions. The goal is to enable trades between an ERC721 and a ER…

Notifications You must be signed in to change notification settings

codewithpatelo/auctionfity_back

Repository files navigation

Auctionfity: Cheap NFT Auction House Example

Author: Patricio J Gerpe Onchain - Offchain Auction House to list NFT and trade them for ERC20 Tokens.

Architecture:

Express, Nodemon, NodeJs, Typescript, Hardhat, Ethers, Solidity, OpenZepellin, Typechain, Ropsten. Chai, Solhint, Prettier and Eslint are used for Quality Control.

image

Case outline:

NFT marketplaces often use techniques for reducing transaction fees. Some of these techniques require users to use these marketplaces with an off-chain sibling system that assist the on-chain pieces. This is a simple off-chain system and the on-chain smart-contract to enable cheap auctions. The goal is to enable trades between an ERC721 and a ERC20 with a single on-chain transaction.

Installation

npm i .

To run in development (Local Test Network)

  1. Compile contracts npm run compile
  2. Start a local node npm run start:node
  3. Deploy contracts to local node npm run deploy:dev
  4. Start Auctionfity app
  5. Use postman collection to communicate with Auctionfity application (./data/Auctionfity.postman_collection.json)

image image image

image

You can test with

npm run test

image

(TODO: Finish UT for settleTransaction function which can be tested via PostMan now)

To run in stagging (Goerli Test Network)

  1. Copy .env.example file and paste with the name '.env'
  2. Create an Alchemy Account: https://www.alchemy.com/
  3. Create an App with network option as "Goerli"
  4. Press "View key" and the copy API KEY value to .env GI_API_KEY= value
  5. Create wallets npx hardhat init (this will initiate init task that will create bidder and nftowner wallets)
  6. Copy both private keys and addresses and fill that data in our .env file (NFTOWNER_PRIVATE_KEY,BIDDER_PRIVATE_KEY,NFTOWNER_ADDR,BIDDER_ADDR)
  7. Make sure to write STAG after ENVIRONMENT property at .env
  8. Compile contracts npm run compile
  9. Deploy contracts to Goerli npm run deploy:stag
  10. Provide faucets for both Bidder and NFTOwner accounts at https://goerlifaucet.com/
  11. Start Auctionfity app npm run start
  12. Use postman collection to communicate with Auctionfity application (./data/Auctionfity.postman_collection.json)

image

image

APPLICATION ENDPOINTS:

image

(You can import postmanCollection from ./data folder)

curl --location --request GET '127.0.0.1:3000/api/accounts'

image

curl --location --request POST '127.0.0.1:3000/api/init'

image

curl --location --request POST '127.0.0.1:3000/api/nfts/approve' \
--header 'Content-Type: application/json' \
--data-raw '{"nfts": [{"tokenId": 1, "price": 0.035}, {"tokenId": 2, "price": 0.035}]}'

image

curl --location --request GET '127.0.0.1:3000/api/nfts' \
--header 'Content-Type: application/json' \
--data-raw '{"nfts": [{"tokenId": 1, "price": 0.035}]}'

image

curl --location --request POST '127.0.0.1:3000/api/token/approve' \
--header 'Content-Type: application/json' \
--data-raw '{"quantity": 1000000000000000}'

image

curl --location --request POST '127.0.0.1:3000/api/nfts/list' \
--header 'Content-Type: application/json' \
--data-raw '{"nft": {"tokenId": 1}, "minPrice": 50}'

image

curl --location --request GET '127.0.0.1:3000/api/nfts/listings?startTime=2021-06-01&endTime=2022-09-09'

image

curl --location --request POST '127.0.0.1:3000/api/nfts/listings/bid-offer' \
--header 'Content-Type: application/json' \
--data-raw '{"price": 90, "tokenId": 1}'

image

curl --location --request GET '127.0.0.1:3000/api/nfts/listings/bids?startTime=2021-06-01&endTime=2022-09-09&tokenId=1'

image

curl --location --request POST '127.0.0.1:3000/api/nfts/listings/bid-accept' \
--header 'Content-Type: application/json' \
--data-raw '{"price": 50, "tokenId": 1}'

image

curl --location --request GET '127.0.0.1:3000/api/signatures?startTime=2021-06-01&endTime=2022-09-09'

image

curl --location --request POST '127.0.0.1:3000/api/nfts/settle' \
--header 'Content-Type: application/json' \
--data-raw '{"tokenId": 1, "bidderSignature": {
        "r": "0x7f6e2a6fce8f54b25ef0f5dba37d6c4b1a063ce3c7afc0ee3ba6568619777fbb",
        "s": "0x75c4cdc54ecedf68a43775742f3fe5b956098ca0ff8f95c824b47816a723d01c",
        "_vs": "0xf5c4cdc54ecedf68a43775742f3fe5b956098ca0ff8f95c824b47816a723d01c",
        "recoveryParam": 1,
        "v": 28,
        "yParityAndS": "0xf5c4cdc54ecedf68a43775742f3fe5b956098ca0ff8f95c824b47816a723d01c",
        "compact": "0x7f6e2a6fce8f54b25ef0f5dba37d6c4b1a063ce3c7afc0ee3ba6568619777fbbf5c4cdc54ecedf68a43775742f3fe5b956098ca0ff8f95c824b47816a723d01c"
    }, "nftOwnerSignature": {
        "r": "0xca7a2a7760cf9670e3db308380fb886665adfcaa56f4d972c435e4178ee72fec",
        "s": "0x69f1462599593d67eb842e26a27b92af966640a2bb335d07bca5946269243267",
        "_vs": "0x69f1462599593d67eb842e26a27b92af966640a2bb335d07bca5946269243267",
        "recoveryParam": 0,
        "v": 27,
        "yParityAndS": "0x69f1462599593d67eb842e26a27b92af966640a2bb335d07bca5946269243267",
        "compact": "0xca7a2a7760cf9670e3db308380fb886665adfcaa56f4d972c435e4178ee72fec69f1462599593d67eb842e26a27b92af966640a2bb335d07bca5946269243267"
    }
    }'

image image

QUALITY CONTROL

npm run test
npm run lint:ts -- --fix
npm run lint:sol
npm run format

TODOS AND ROOM FOR IMPROVEMENTS:

  • handle ERC20 Token Transfers within MKT Contract Logic
  • work with listings fees
  • finish ut for settleTransaction function (it can be tested via postman though)
  • add test coverage
  • add full coverage smart contract ut
  • refactor controllers and services to reduce code lines per file and avoid cases of repeated code
  • integrate Mongoose for more convenient data quering
  • update software architecture diagram with Alchemy and Goerli (replacing Ropsten)

About

NFT marketplaces often use techniques for reducing transaction fees. Some of these techniques require users to use these marketplaces with an off-chain sibling system that assist the on-chain pieces. This is a simple off-chain system and the on-chain smart-contract to enable cheap auctions. The goal is to enable trades between an ERC721 and a ER…

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published