Giter VIP home page Giter VIP logo

nft-pawnshop's Introduction

Nft Pawnshop

A Near smart contract written in Rust for an app that uses NFTs to facilitate P2P lending. NFT owners can use their NFTs as collateral to request for loans. Lenders can accept loan conditions at an agreed interest rate and due date.

Prerequisites

  1. Make sure you've installed Node.js โ‰ฅ 12

  2. Install Rust and Cargo

  3. Install near-cli globally. This will be used for deployment and manual testing.

     yarn install --global near-cli
    

Quick Start

Step 1. Set up

The scripts to run and interact with the contract all use the parameters in scripts/config.sh.

 vim scripts/config.sh

Start by configuring these parameters.

Name Description
PAWNSHOP_ID Near address to deploy contract on
BORROWER_ID Near address of borrower / nft owner
BROKER_ID Near address of broker
NFT_CONTRACT_ID Near address of nft to pawn
TOKEN_ID ID of nft to pawn

NOTE: You'll need the full access keys for PAWNSHOP_ID, BORROWER_ID, AND BROKER_ID to call contract methods later on.

Step 2. Deploy the contract

yarn dev-deploy

The command will deploy and initialiese the contract onto the testnet in development mode.

Step 3. Interact with the contract

First, let's try to list an nft as a collateral for a loan by:

  1. Approving the account to transfer the nft of interest.

     ./scripts/nft/approve.sh
    
  2. Then, call contract code to list the pawn offer

     yarn offer-pawn
    

๐Ÿ’ก To mint NFTs for manual testing purposes, we can run scripts/nft/mint.sh.

To see how to accept pawn offers, repay loans, and collect collateral, read the documentation

Troubleshooting

On Mac M1, cross-compilation is not supported on Apple ARM yet. This might cause problems when trying to run tests. Please see this issue. To circumvent this, do switch to a x86-64 toolchain.

Install the toolchain if you've not done so.

 rustup toolchain install stable-x86_64-apple-darwin

Set the toolchain as the default.

 rustup default stable-x86_64-apple-darwin

nft-pawnshop's People

Contributors

bryanwee023 avatar

Watchers

 avatar

Forkers

neardragons

nft-pawnshop's Issues

Fix storage issue for nft approval

It is possible for malicious users to freeze up contract funds by repeatedly approving the contract to transfer nfts and consequentially calling nft_on_approve().

This is possible since users do not have to pay for storage fees when approving.

Add simulation tests

Simulation tests will better ensure the reliability of the contract, especially with regards to its cross-contract features.

There seems to be problem compiling near_sdk_sim simulation tests on Apple M1 chips, so this will be put on hold for now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.