@inaridiy/erc721l

1.1.1 • Public • Published

ERC721Loanable

Extension of ERC721 that allows borrowing and lending NFTs according to contract without trusting the other party.

Installation

npm install -save-dev @inaridiy/erc721l

Usage

After installing the contract, you can use it by importing the contract.

// SPDX-License-Identifier: MIT
// Inaridiy ERC721Loanable Sample Contract v1.0.1
pragma solidity ^0.8.4;

import "./ERC721Loanable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";

contract Sample is ERC721Loanable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIds;

    constructor() ERC721Loanable("Sample ERC721Loanable Token", "SET") {}

    function mint() public returns (uint256) {
        uint256 newItemId = _tokenIds.current();
        _mint(_msgSender(), newItemId);
        _tokenIds.increment();
        return newItemId;
    }

    function lend(
        address to,
        uint256 tokenId,
        uint256 period
    ) public {
        _lend(to, tokenId, period);
    }
}

Added Methods

The ERC721L adds three functions to the ERC721 to achieve NFT lending and borrowing.

lend

Lend an NFT of tokenId to an address of to for period of time. You can rent out NFTs that you own and have not yet rented out. The borrower cannot transfer NFT.

_lend(address to,uint256 tokenId,uint256 period) internal;

reclaim

You can get back the NFT of a tokenId whose loan period has expired. You cannot reclaim an NFT that is still in the loan period.

reclaim(uint256 tokenId) public;

lendingInfo

Lending information for the NFT of tokenId can be obtained. ※If not on loan, all information will be the initial values of Solidity.

lendingInfo(uint256 tokenId) public view returns(address owner,address borrower,uint256 deadline)

Local test run.

git clone git@github.com:inaridiy/ERC721L.git
npm install
npm run hardhat test

License

Distributed under the MIT License. See LICENSE.txt for more information.

Contact

twitter: https://twitter.com/unknown_gakusei ens: inaridiy.eth

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.1
    0
  • 1.0.2
    0
  • 1.0.1
    0

Package Sidebar

Install

npm i @inaridiy/erc721l

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

8.76 kB

Total Files

7

Last publish

Collaborators

  • inaridiy