Blockchain Developer Bootcamp Final Project - NFT Lend
URL of deployed application
http://faulty-hill.surge.sh/
You will need some ERC-721 in your account to test this.
Running the project locally
Prerequisites
- yarn should be installed
- npm should be installed
- Node.js >= v14
- Browser with Metamask extension installed
Contracts
After checking out the main
branch of this project:
yarn install
to install dependencies
yarn compile
to compile smart contracts
yarn test
to run unit tests
Deploy contracts to local network, and setup test environment
- Start a new terminal, and run
yarn hardhat node
- We will make use of the generated account's private keys for testing, so please take note of:
- Account 1: Lender of NFT, deployer of contracts
- Account 2: Borrower of NFT
- A local hardhat node should be running, and you'll see:
Started HTTP and WebSocket JSON-RPC server at http://127.0.0.1:8545/
- Leave the terminal running until the end of tests, and use another one for the subsequent steps
yarn hardhat run scripts/testing/deploy_w_testtokens.ts --network localhost
to
- deploy test NFT to local hardhat node
- Take note of NFT address printed in console
- mint 3 NFTs to account 1
- Take note that minted NFTs have token-ids
0
, 1
, and 2
- deploy the lender contract.
- Take note of the
Lender
contract
Start UI locally
- Use the lender contract address from step 7.3.1 and update the following variables in
frontend/src/App.svelte
const lenderAddress = '<>'; // address from step 7.3.1
const contractCreationBlock = 0; // set this to 0
cd frontend
npm install
to install frontend dependencies
npm run build
to build the frontend
npm run dev
to start the frontend, it should be deployed to http://localhost:5000
Screencast link
https://youtu.be/fsz7ex5a-JY
Public Ethereum wallet for certification:
0x8C67b4AAF78CF53b624d8bcB63Ca7513A5634203
Project description
NFT Lend
The application will provide an interface that allows a user (user A) to lend out an NFT to another user (user B) for set period of time (eg. 1 day). The borrower (user B) can freely transfer the temporary ownership (represented by a wrapper NFT).
The application will also provide an interface for anyone to check the current owner of a lent NFT.
A borrower should be able to return the borrowed NFT by burning the wrapper NFT.
Workflows
Simple lending workflow
Lender
- Enter website
- Login with Metamask
- Enter NFT Token address, token id, and borrower address
- Click 'Lend'
- Use the 'verify ownership' form to check that the contract is returning the borrower's address as the virtual owner.
Borrower
- Enter website
- Connect with Metamask
- Observe that the borrowed NFT is showing up under 'borrowed' section.
Collecting an NFT that was borrowed (Not implemented in UI)
Lender
- After the lending duration has expired, enter the website
- Connect with Metamask
- Click on 'Collect' on an NFT under the 'lent' section
- Use the 'verify ownership' to check that you are the new virtual owner. NFT contract should also say that you are the current owner.
Returning an NFT early (Not implemented in UI)
Borrower
- Enter the website
- Connect with Metamask
- Click on 'Return' to burn the wrapped token and return the lent token to the original owner.
Directory structure
frontend
: Project's React frontend.
contracts
: Smart contracts that are deployed in the Ropsten testnet.
test
: Tests for smart contracts.
Environment variables (not needed for running project locally)
This is only required for deployment
TODO features
- UI for returning of NFT
- UI to display status of lent/borrowed NFTs, and to enable filtering
- Use ERC-1155 to track lending instead
- Support for lending out ERC-1155 tokens