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.
-
Make sure you've installed Node.js ≥ 12
-
Install near-cli globally. This will be used for deployment and manual testing.
yarn install --global near-cli
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.
yarn dev-deploy
The command will deploy and initialiese the contract onto the testnet in development mode.
First, let's try to list an nft as a collateral for a loan by:
-
Approving the account to transfer the nft of interest.
./scripts/nft/approve.sh
-
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
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