### Install NFTfi.js SDK Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Installs the NFTfi.js SDK using yarn. This is the first step before initializing and using the SDK. ```shell yarn install ``` -------------------------------- ### Create Flexible Loan Offer using nftfi.js Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md An example of creating a Flexible Loan offer, which allows for prorated interest. The setup includes defining terms and approving the principal amount. ```javascript // Construct the loan terms const nft = { address: '0x000', id: '1' }; const type = "v3.asset"; const currency = lender.config.erc20.weth.address; const principal = '1000000000000000000'; const repayment = '2000000000000000000'; const origination = '50000000000000000'; // Origination fee const interest = { prorated: true }; // Flexible const secPerDay = 86400; const duration = 1 * secPerDay; const expiry = { seconds: 30 * secPerDay }; // 30 days (max limit) const borrower = { address: '0x222' }; // Approve principal with NFTfi contracts await lender.erc20.approve({ token: { address: currency }, nftfi: { contract: { name: "v3.erc20Manager.v1" } }, amount: principal }); // Create the offer on the listing const offer = await lender.offers.create({ type, nft, borrower, terms: { principal, repayment, duration, currency, expiry, origination, interest } }); ``` -------------------------------- ### Create Asset Loan Offer using nftfi.js Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Provides a comprehensive example of creating an Asset Loan offer. It includes setting up loan terms, approving principal, and initiating the offer with NFTfi.js. ```javascript // Construct the loan terms const nft = { address: '0x000', id: '1' }; const type = "v3.asset"; const currency = lender.config.erc20.weth.address; const principal = '1000000000000000000'; const repayment = '2000000000000000000'; const origination = '0'; // Origination fee const interest = { prorated: false }; // Fixed const secPerDay = 86400; const duration = 1 * secPerDay; const expiry = { seconds: 30 * secPerDay }; // 30 days (max limit) const borrower = { address: '0x222' }; // Approve principal with NFTfi contracts await lender.erc20.approve({ token: { address: currency }, nftfi: { contract: { name: "v3.erc20Manager.v1" } }, amount: principal }); // Create the offer on the listing const offer = await lender.offers.create({ type, nft, borrower, terms: { principal, repayment, duration, currency, expiry, origination, interest } }); ``` -------------------------------- ### Create Collection Loan Offer using nftfi.js Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Demonstrates how to create a Collection Loan offer. This example outlines the necessary parameters for collateralizing a collection of NFTs and specifies a zero address for the borrower. ```javascript // Construct the loan terms const nft = { address: '0x000' }; const type = "v3.collection"; // Collection offer const currency = lender.config.erc20.weth.address; const principal = '1000000000000000000'; const repayment = '2000000000000000000'; const origination = '0'; // No origination fee const interest = { prorated: false }; // Fixed const secPerDay = 86400; const duration = 1 * secPerDay; const expiry = { seconds: 30 * secPerDay }; // 30 days (max limit) const borrower = { address: '0x0000000000000000000000000000000000000000' }; // Zero address // Approve principal with NFTfi contracts await lender.erc20.approve({ token: { address: currency }, nftfi: { contract: { name: "v3.erc20Manager.v1" } }, amount: principal }); // Create the offer on the listing const offer = await lender.offers.create({ type, nft, borrower, terms: { principal, repayment, duration, currency, expiry, origination, interest } }); ``` -------------------------------- ### Offers API Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Provides methods to retrieve and manage NFT offers. The `get` method allows fetching offers with various filtering and pagination options. ```APIDOC ## GET /offers ### Description Retrieves NFT offers based on specified filters. If no filters are provided, it defaults to fetching offers made by the authenticated user as a lender. Supports filtering by NFT details, lender/borrower addresses, loan parameters, offer type, and pagination. ### Method GET ### Endpoint /offers ### Parameters #### Query Parameters - **options.filters.nft.address** (string) - Optional - NFT contract address to filter by. - **options.filters.nft.id** (string) - Optional - NFT id of the asset to filter by. - **options.filters.lender.address.eq** (string) - Optional - Lender wallet address to filter by. - **options.filters.borrower.address.eq** (string) - Optional - Borrower wallet address to filter by. - **options.filters.lender.address.ne** (string) - Optional - Lender wallet address to exclude. - **options.filters.nftfi.contract.name** (string) - Optional - Contract name to filter by. - **options.filters.nftfi.contract.name.in** (Array) - Optional - Contract names to filter by. - **options.filters.loan.apr.lte** (string) - Optional - Maximum APR to filter by. - **options.filters.loan.effectiveApr.lte** (string) - Optional - Maximum effective APR to filter by. - **options.filters.loan.duration.eq** (string) - Optional - Loan duration to filter by. - **options.filters.loan.duration.nin** (Array) - Optional - Loan durations to exclude. - **options.filters.loan.currency.address.eq** (string) - Optional - Loan currency address to filter by. - **options.filters.interest.prorated** (boolean) - Optional - Filter for flexible or fixed offers. - **options.filters.type** (string) - Optional - Filter for offers of a certain type, `v3.asset` or `v3.collection`. - **options.filters.type.in** (Array) - Optional - Filter for offers that match one of many types. - **options.pagination.page** (number) - Optional - Pagination page number. - **options.pagination.limit** (number) - Optional - Pagination limit per page. - **options.pagination.sort** (string) - Optional - Field to sort offers by. - **options.pagination.direction** ('asc' | 'desc') - Optional - Direction to sort offers by. - **options.validation.check** (boolean) - Optional - Defaults to `true`. Validate offers and append error info. - **options.validation.refinance** (boolean) - Optional - Defaults to `false`. Validate offers checking if they're valid in the context of refinancing (only works when offers are filtered by lender address). - **options.auth.token** ('required' | 'optional' | 'none') - Optional - Specify if the call to fetch offers should be authenticated. Un-authenticated calls will redact offer signatures. Defaults to `optional`. ### Request Example ```javascript // Get all offers made by your account const offers = await nftfi.offers.get(); // Get the first page of offers for a specific NFT const offers = await nftfi.offers.get({ filters: { nft: { address: "0x00000000", id: "42" } }, pagination:{ page: 1, limit: 10 } }); // Get all collection offers from a specific lender const offers = await nftfi.offers.get({ filters: { type: 'v3.collection', nft: { address: "0x00000000", }, lender:{ address: { eq: "0x12345567" } }, }, pagination:{ page: 1, limit: 10 } }); // Get all offers without validation checks const offers = await nftfi.offers.get({ validation: { check: false } }); ``` ### Response #### Success Response (200) - **offers** (Array) - An array of offer objects. #### Response Example ```json [ { "offerId": "0x123...", "nft": { "address": "0x00000000", "id": "42", "collectionName": "Bored Ape Yacht Club" }, "lender": { "address": "0xLENDER..." }, "borrower": { "address": "0xBORROWER..." }, "loan": { "currency": { "address": "0xETH...", "symbol": "ETH" }, "amount": "1000000000000000000", "duration": "604800", "apr": "1000" } } ] ``` ``` -------------------------------- ### Get Offers with Filters Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Retrieves offers from the order-book with new filtering options, allowing selection by offer type. ```APIDOC ## GET /offers ### Description Retrieves offers from the order-book. Supports new filters to narrow down results by offer type (asset or collection) or multiple types. ### Method GET ### Endpoint /offers ### Parameters #### Query Parameters - **filters.type** (string) - Optional - Filters offers by a specific type (e.g., 'v3.asset', 'v3.collection'). - **filters.type.in** (array of strings) - Optional - Filters offers by multiple specified types. ### Request Example ```json // Get v3.asset offers await borrower.offers.get({ "filters": {"type": "v3.asset"} }); // Get v3.collection offers await borrower.offers.get({ "filters": {"type": "v3.collection"} }); // Get both v3.collection and v3.asset offers await borrower.offers.get({ "filters": {"type": {"in": ["v3.asset", "v3.collection"]}} }); ``` ### Response #### Success Response (200) - **offers** (array) - A list of offers matching the specified filters. #### Response Example ```json { "offers": [ { "id": "offer_id_123", "type": "v3.asset", "terms": {...} }, { "id": "offer_id_456", "type": "v3.collection", "terms": {...} } ] } ``` ``` -------------------------------- ### Initialize NFTfi.js SDK without Private Key or Web3 Provider Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Initializes the NFTfi.js SDK with an NFTfi API key and provider URL, but without a private key or Web3 provider. This setup limits functionality, as it cannot make offers or initiate loans that require signatures. ```javascript import NFTfi from '@nftfi/js'; const nftfi = await NFTfi.init({ config: { api: { key: } }, ethereum: { account: { address: }, provider: { url: } } }); ``` -------------------------------- ### Approve NFTs and ERC20 Tokens for v3 Loans (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Provides examples of how borrowers and lenders grant necessary approvals for v3 loans. This includes approving NFTs with the Escrow contract, principal amounts with the ERC20 Manager, and obligation receipts with the Refinancing contract. ```javascript // Borrower approves NFT with Escrow contract await borrower.nft.approve({ token: { address: offer.nft.address }, nftfi: { contract: { name: 'v3.escrow.v1' } } }); ``` ```javascript // Lender approves principal with the ERC20 Manager contract await lender.erc20.approve({ token: { address: offer.terms.currency }, amount: offer.principal, nftfi: { contract: { name: 'v3.erc20Manager.v1' } } }); ``` ```javascript // Borrower approves erc20 and obligation receipt with Refinancing contract await borrower.erc20.approve({ token: { address: offer.terms.currency }, amount: offer.repayment, nftfi: { contract: { name: 'v3.refinance.v1' } } }); await borrower.nft.approve({ token: { address: nftfi.config.protocol.v3.obligationReceipt.v1.address }, nftfi: { contract: { name: 'v3.refinance.v1' } } }); ``` -------------------------------- ### Calculate Effective APR using nftfi.js utility Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Example of using the new `calcEffectiveApr` utility function to determine the Annual Percentage Rate for a loan, considering principal, repayment, duration, and origination fee. ```javascript const principal = '1000000000000000000'; const repayment = '1200000000000000000'; const originationFee = '100000000000000000'; const duration = 365; const eAPR = nftfi.utils.calcEffectiveApr(principal, repayment, duration, originationFee); ``` -------------------------------- ### Get All Listings (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves all current NFT listings. This method can be filtered by NFT contract addresses and paginated. It returns an array of listing objects. ```javascript const listings = await nftfi.listings.get(); ``` -------------------------------- ### Filter NFTFi Offers by Type (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Demonstrates how to retrieve offers from the order-book using new filtering capabilities. These examples show filtering by a single offer type ('v3.asset' or 'v3.collection') and by multiple types using the 'in' operator. ```javascript // Get v3.asset offers const offers = await borrower.offers.get({ filters: { type: 'v3.asset' } }); ``` ```javascript // Get v3.collection offers const offers = await borrower.offers.get({ filters: { type: 'v3.collection' } }); ``` ```javascript // Get both v3.collection and v3.asset offers const offers = await borrower.offers.get({ filters: { type: { in: ['v3.asset', 'v3.collection'] } } }); ``` -------------------------------- ### Create Flexible Offer on NFT Collection Range - JavaScript Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Creates a flexible offer on a specified range of NFTs within a collection. This method requires the offer type, NFT collection address with start and end IDs for the range, and the offer terms including principal, repayment, origination fees, interest, duration, currency, and expiry. ```javascript const offer = await nftfi.offers.create({ type: 'v3.collection', nft: { address: '0x22222222', ids: { from: 1, to: 10 } }, terms: { principal: '1000000000000000000', repayment: '1100000000000000000', origination: '0', interest: { prorated: true }, duration: 31536000, currency: '0x00000000', expiry: { seconds: 3600 } // 1 hour } }); ``` -------------------------------- ### Get Filtered and Paginated Listings (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves NFT listings with specific filters for NFT contract addresses and pagination options. This allows for targeted data retrieval, returning an array of listing objects. ```javascript const listings = await nftfi.listings.get({ filters: { nftAddresses: ['0x11111111', '0x22222222'] }, pagination: { page: 1, limit: 20 } }); ``` -------------------------------- ### Get Defaulted Loans for Borrower or Lender (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves defaulted loans where the current account acts as either the borrower or lender. Supports pagination for managing results and returns an array of loan objects. ```javascript const { data: { results } } = await nftfi.loans.get({ filters: { lender: { address: nftfi.account.getAddress() }, borrower: { address: nftfi.account.getAddress() }, status: 'defaulted' }, pagination: { page: 1, limit: 10 } }); ``` -------------------------------- ### Get NFTFi Offers (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves NFTFi offers. Defaults to filtering by the current account as the lender if no filters are provided. Supports extensive filtering by NFT details, lender/borrower addresses, loan attributes, offer types, and pagination. Can also control offer validation. ```javascript const offers = await nftfi.offers.get(); ``` ```javascript const offers = await nftfi.offers.get({ filters: { nft: { address: "0x00000000", id: "42" } }, pagination:{ page: 1, limit: 10 } }); ``` ```javascript const offers = await nftfi.offers.get({ filters: { nft: { address: "0x00000000" } } }); ``` ```javascript const offers = await nftfi.offers.get({ filters: { type: 'v3.collection', nft: { address: "0x00000000", }, lender:{ address: { eq: "0x12345567" } }, }, pagination:{ page: 1, limit: 10 } }); ``` ```javascript const offers = await nftfi.offers.get({ validation: { check: false } }); ``` -------------------------------- ### Begin NFT Loan Offer - JavaScript Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Initiates a loan by accepting a lender's offer. This method is used by the borrower to finalize the loan terms and collateral. It requires detailed information about the NFT, loan terms, borrower, lender, and the lender's signature. ```javascript const result = await nftfi.loans.begin({ type: 'v3.asset', nft: { address: '0x22222222', id: '2' }, borrower: { address: '0x11111111' }, lender: { address: '0x22222222' }, terms: { principal: '1000000000000000000', repayment: '1100000000000000000', origination: '100000000000000000', interest: { prorated: true }, duration: 31536000, currency: '0x00000000', expiry: { seconds: 1722260287 } }, signature: "0x000000000" }); ``` -------------------------------- ### Get Expiry Timestamp (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Generates a future expiry timestamp. This is commonly used for setting expiration times for transactions, offers, or sessions. ```javascript // Get an expiry timestamp into the future const expiry = nftfi.utils.getExpiry(); ``` -------------------------------- ### Initialize NFTfi.js SDK with Private Key Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Initializes the NFTfi.js SDK using a private key for authentication. It requires an NFTfi API key, the account's private key, and the Ethereum provider URL. This method allows for full interaction with the NFTfi protocol. ```javascript import NFTfi from '@nftfi/js'; const nftfi = await NFTfi.init({ config: { api: { key: } }, ethereum: { account: { privateKey: }, provider: { url: } } }); ``` -------------------------------- ### Get Random Nonce (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Generates a random nonce string. This utility function is useful for various cryptographic operations or as unique identifiers. ```javascript // Get a random nonce const nonce = nftfi.utils.getNonce(); ``` -------------------------------- ### Loans API - Begin Loan Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Initiates a loan by allowing a borrower to accept a lender's offer. This method is part of the instance methods for the Loans class. ```APIDOC ## POST /loans/begin ### Description Begin a loan. Called by the borrower when accepting a lender's offer. ### Method POST ### Endpoint /loans/begin ### Parameters #### Request Body - **options** (object) - Required - Hashmap of config options for this method - **options.type** (object) - Required - Type of the offer `v3.asset` or `v3.collection` - **options.offer.nft.address** (string) - Required - Address of the NFT being used as collateral - **options.offer.nft.id** (string) - Optional - ID of NFT being used as collateral - **options.offer.nft.ids.from** (number) - Optional - "from" ID of NFT id range of the offer (only when accepting a ranged offer) - **options.offer.nft.ids.to** (number) - Optional - "to" ID of NFT id range of the offer (only when accepting a ranged offer) - **options.offer.terms.loan.currency** (string) - Required - Address of the ERC20 contract being used as principal/interest - **options.offer.terms.loan.principal** (number) - Required - Sum of money transferred from lender to borrower at the beginning of the loan - **options.offer.terms.loan.repayment** (number) - Required - Maximum amount of money that the borrower would be required to retrieve their collateral - **options.offer.terms.loan.origination** (number) - Required - Sum of money transferred to the lender at the beginning of the loan - **options.offer.terms.loan.duration** (number) - Required - Amount of time (measured in seconds) that may elapse before the lender can liquidate the loan - **options.offer.terms.loan.expiry.seconds** (number) - Required - Timestamp (in seconds) of when the signature expires - **options.borrower.address** (string) - Optional - The address of the borrower (owner of nft) - **options.offer.lender.address** (string) - Required - Address of the lender that signed the offer - **options.offer.lender.nonce** (string) - Required - Nonce used by the lender when they signed the offer - **options.offer.nftfi.fee.bps** (number) - Optional - Percent (measured in basis points) of the interest earned that will be taken as a fee by the contract admins when the loan is repaid - **options.offer.nftfi.contract.name** (string) - Optional - Name of contract used to facilitate the loan: `v2-3.loan.fixed`, `v2-3.loan.fixed.collection` - **options.offer.signature** (string) - Required - ECDSA signature of the lender ### Request Example ```json { "options": { "type": "v3.asset", "nft": { "address": "0x22222222", "id": "2" }, "borrower": { "address": "0x11111111" }, "lender": { "address": "0x22222222" }, "terms": { "principal": "1000000000000000000", "repayment": "1100000000000000000", "origination": "100000000000000000", "interest": { "prorated": true }, "duration": 31536000, "currency": "0x00000000", "expiry": { "seconds": 1722260287 } }, "signature": "0x000000000" } } ``` ### Response #### Success Response (200) - **response** (object) - Response object #### Response Example ```json { "txHash": "0xabc123..." } ``` ``` -------------------------------- ### Initialize NFTfi.js SDK with Web3 Provider Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Initializes the NFTfi.js SDK using a Web3 provider. This method requires an NFTfi API key, the wallet address, and the Web3 Ethereum provider object. It supports interactions that require user signatures. ```javascript import NFTfi from '@nftfi/js'; const nftfi = await NFTfi.init({ config: { api: { key: } }, ethereum: { account: { address: }, web3: { provider: } } }); ``` -------------------------------- ### Get ERC721 Token Owner Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves the owner's address of a specific ERC721 token. Requires the token's address and ID as input. ```javascript const address = await nftfi.nft.erc721.ownerOf({ token: { address: '0x00000000', id: '0' } }); ``` -------------------------------- ### GET /immutables/bundle Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves a bundle of an immutable object. This method allows you to fetch details associated with a specific immutable, using different contract versions for compatibility. ```APIDOC ## GET /immutables/bundle ### Description Retrieves a bundle of an immutable object. This method allows you to fetch details associated with a specific immutable, using different contract versions for compatibility. ### Method GET ### Endpoint `/immutables/bundle` ### Parameters #### Query Parameters - **options.immutable.id** (string) - Required - The ID of the immutable object. - **options.nftfi.contract.name** (string) - Required - Name of the contract used to facilitate the bundle: `v1.immutable.bundle` (deprecated), `v1-1.immutable.bundle`. ### Request Example ```json { "options": { "immutable": { "id": "42" }, "nftfi": { "contract": { "name": "v1.immutable.bundle" } } } } ``` ### Response #### Success Response (200) - **bundle** (Object) - An object containing information about an bundle. #### Response Example ```json { "bundle": { "example_data": "bundle_info" } } ``` ``` -------------------------------- ### Offer Creation: Asset and Collection Types Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Demonstrates how to create offers specifically for single assets or entire collections using the 'type' field. ```APIDOC ## POST /offers/create ### Description Creates a new offer to borrow or lend NFTs. Supports specifying whether the offer is for a single asset or an entire collection. ### Method POST ### Endpoint /offers/create ### Parameters #### Request Body - **type** (string) - Required - Specifies the offer type. Use 'v3.asset' for single assets or 'v3.collection' for entire collections. - **terms** (object) - Required - Details of the loan terms (principal, repayment, interest, origination fee). - **interest** (object) - Required - Interest terms. - **prorated** (boolean) - Required - Set to true for flexible (prorated) loans, false for fixed loans. - **origination** (string) - Required - The origination fee amount (e.g., in wei). - **principal** (string) - Required - The principal amount of the loan (e.g., in wei). - **repayment** (string) - Required - The total repayment amount of the loan (e.g., in wei). ### Request Example ```json { "type": "v3.asset", "terms": { "interest": { "prorated": false }, "origination": "0", "principal": "1000000000000000000", "repayment": "2000000000000000000" } } ``` ### Response #### Success Response (200) - **offer** (object) - Details of the created offer. #### Response Example ```json { "offer": { "id": "offer_id_123", "type": "v3.asset", "terms": { "principal": "1000000000000000000", "repayment": "2000000000000000000", "interest": { "prorated": false }, "origination": "0" } } } ``` ``` -------------------------------- ### Get Immutable Bundle Data using nftfi.js Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves immutable data for a specified bundle. This method requires the bundle ID and the name of the contract used to facilitate the bundle, such as 'v1-1.bundler'. ```javascript // Get an immutable of a v1-1 bundle. const bundle = await nftfi.bundles.getImmutable({ bundle: { id: '42' }, nftfi: { contract: { name: 'v1-1.bundler' } } }); ``` -------------------------------- ### Refinance Loan with NFTfi.js Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md This snippet demonstrates how to refinance an active loan using the nftfi.js library. It includes fetching active loans, retrieving a v3 offer, minting an obligation receipt, approving necessary tokens (NFT and ERC20), and finally executing the refinance transaction. Ensure that the NFT_ID and other relevant loan/offer details are correctly provided. ```javascript // Fetch active loans const loans = await borrower.loans.get({ filters: { status: 'active' } }); const loan = loans.data.results[0]; // Get a v3 offer const offers = await borrower.offers.get({ filters: { nft: { address: loan.nft.address }, loan: { currency: { address: { eq: loan.terms.loan.currency } } }, type: 'v3.collection' } }); const offer = offers[0]; // Mint Obligation Receipt await nftfi.loans.mintObligationReceipt({ loan }); // Allow the contract to manage your ORs await borrower.nft.approve({ token: { address: nftfi.config.protocol.v3.obligationReceipt.v1.address }, nftfi: { contract: { name: 'v3.refinance.v1' } } }); // If the refinancing proceed is negative, also allow the contract to manage your ERC20 to pay the proceed await borrower.erc20.approveMax({ token: { address: borrower.config.erc20.weth.address }, nftfi: { contract: { name: 'v3.refinance.v1' } } }); // Refinance const result = await borrower.loans.refinance({ loan, offer: { ...offer, nft: { ...offer.nft, id: NFT_ID } } }); ``` -------------------------------- ### Offer Validation Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Explains how to validate a v3 offer using an upgraded mechanism to ensure it meets specified rules and structures. ```APIDOC ## POST /offers/validate ### Description Validates a v3 offer to ensure it adheres to the specified structure and rules. This process checks various aspects of the offer, such as signature and terms. ### Method POST ### Endpoint /offers/validate ### Parameters #### Request Body - **offer** (object) - Required - The offer object to validate. - **checks** (array) - Required - An array of checks to perform on the offer. Examples: 'signature', 'terms.principal', 'lender.nonce'. ### Request Example ```json { "offer": { "id": "offer_id_123", "type": "v3.asset", "terms": { "principal": "1000000000000000000", "repayment": "2000000000000000000" }, "lender": { "nonce": "offer_nonce_123" } }, "checks": [ "signature", "terms.principal", "lender.nonce" ] } ``` ### Response #### Success Response (200) - **validation** (object) - The result of the validation checks. #### Response Example ```json { "validation": { "signature": true, "terms.principal": true, "lender.nonce": true } } ``` ``` -------------------------------- ### Initialize NFTfi.js SDK with Chain ID Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Initializes the NFTfi.js SDK with an NFTfi API key and chain ID, without providing a private key, Web3 provider, or provider URL. This configuration further restricts interactions that require direct blockchain operations. ```javascript import NFTfi from '@nftfi/js'; const nftfi = await NFTfi.init({ config: { api: { key: } }, ethereum: { account: { address: }, chain: { id: } } }); ``` -------------------------------- ### Get Active Loans by Lender (JavaScript) Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves active loans where the current account is the lender. This method utilizes filters for lender address and loan status, returning an array of loan objects. ```javascript const { data: { results } } = await nftfi.loans.get({ filters: { lender: { address: nftfi.account.getAddress() }, status: 'active' } }); ``` -------------------------------- ### Offers Create API Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Creates a new offer on a NFT or collection. Supports both flexible and fixed offer types for individual assets or collections. ```APIDOC ## POST /offers/create ### Description Creates a new offer on a NFT or collection. ### Method POST ### Endpoint /offers/create ### Parameters #### Request Body - **options** (object) - Required - Config options for this method - **type** (string) - Required - Type of the offer (e.g., 'v3.asset', 'v3.collection') - **nft** (object) - Required - NFT to place an offer on - **address** (string) - Required - NFT contract address - **id** (number) - Optional - Starting ID of the NFT range (inclusive). Requires options.type to be 'v3.collection'. - **ids** (object) - Optional - Range of NFT IDs for collection offers - **from** (number) - Optional - Starting ID of the NFT range (inclusive) - **to** (number) - Optional - Ending ID of the NFT range (inclusive) - **borrower** (object) - Optional - Owner of the NFT - **address** (string) - Required - Borrower wallet address - **terms** (object) - Required - Terms of the offer - **principal** (string) - Required - Principal amount of the loan - **repayment** (string) - Required - Repayment amount of the loan - **origination** (string) - Required - Origination fee - **interest** (object) - Required - Interest details - **prorated** (boolean) - Required - Whether interest is prorated - **duration** (number) - Required - Duration of the loan in seconds - **currency** (string) - Required - Currency contract address for the loan - **expiry** (object) - Required - Expiry details for the offer - **seconds** (number) - Required - Expiry time in seconds ### Request Example (Flexible Offer on NFT) ```json { "options": { "type": "v3.asset", "nft": { "address": "0x22222222", "id": "2" }, "borrower": { "address": "0x11111111" }, "terms": { "principal": "1000000000000000000", "repayment": "1100000000000000000", "origination": "100000000000000000", "interest": { "prorated": true }, "duration": 31536000, "currency": "0x00000000", "expiry": { "seconds": 3600 } } } } ``` ### Request Example (Fixed Offer on Collection) ```json { "options": { "type": "v3.collection", "nft": { "address": "0x22222222" }, "terms": { "principal": "1000000000000000000", "repayment": "1100000000000000000", "origination": "0", "interest": { "prorated": false }, "duration": 31536000, "currency": "0x00000000", "expiry": { "seconds": 3600 } } } } ``` ### Request Example (Flexible Offer on NFT Range) ```json { "options": { "type": "v3.collection", "nft": { "address": "0x22222222", "ids": { "from": 1, "to": 10 } }, "terms": { "principal": "1000000000000000000", "repayment": "1100000000000000000", "origination": "0", "interest": { "prorated": true }, "duration": 31536000, "currency": "0x00000000", "expiry": { "seconds": 3600 } } } } ``` ### Response #### Success Response (200) - **object** - Response object containing details of the created offer. #### Response Example ```json { "id": "offer_123abc", "status": "active" } ``` ``` -------------------------------- ### Mint Promissory Note for v3 Loan using nftfi.js Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Demonstrates the process of minting a Promissory Note (PN) for a v3 loan. This is another new feature for managing loan documentation. ```javascript // Mint Promissory Note for a v3 loan const receipt = await lender.loans.mintPromissoryNote({ loan: { id: 1 } }); ``` -------------------------------- ### Get ERC20 Token Allowance Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves the ERC20 token allowance for a specified NFTfi contract and account. This method requires the token address and the NFTfi contract name. It returns the allowance in base units. ```javascript const balance = await nftfi.erc20.allowance({ token: { address: '0x00000000' }, nftfi: { contract: { name: 'v2-3.loan.fixed' } } }); ``` -------------------------------- ### Get ERC20 Token Balance Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/README.md Retrieves the balance of a specified ERC20 token for an account. If no account is specified, it defaults to the current user's account. Requires the token address and returns the balance in base units. ```javascript const balance = await nftfi.erc20.balanceOf({ token: { address: '0x00000000' } }); ``` -------------------------------- ### Approvals for ERC721 and ERC20 Tokens Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Covers the necessary approval steps for borrowers and lenders involving NFTs and ERC20 tokens with specific NFTfi contracts. ```APIDOC ## POST /approve ### Description Grants necessary approvals for NFT (ERC721) and ERC20 tokens to NFTfi contracts. This is required for both borrowers and lenders to engage in v3 loans. ### Method POST ### Endpoint /approve ### Parameters #### Path Parameters - **token_address** (string) - Required - The address of the ERC721 or ERC20 token. - **nftfi_contract_name** (string) - Required - The name of the NFTfi contract requiring approval (e.g., 'v3.escrow.v1', 'v3.erc20Manager.v1', 'v3.refinance.v1'). #### Query Parameters - **amount** (string) - Optional - The amount of ERC20 tokens to approve. Required for ERC20 approvals. ### Request Example ```json // Borrower approves NFT with Escrow contract await borrower.nft.approve({ "token": {"address": "0xnft_address"}, "nftfi": {"contract": {"name": "v3.escrow.v1"}} }); // Lender approves principal with ERC20 Manager contract await lender.erc20.approve({ "token": {"address": "0xerc20_address"}, "amount": "1000000000000000000", "nftfi": {"contract": {"name": "v3.erc20Manager.v1"}} }); // Borrower approves ERC20 and obligation receipt with Refinancing contract await borrower.erc20.approve({ "token": {"address": "0xerc20_address"}, "amount": "2000000000000000000", "nftfi": {"contract": {"name": "v3.refinance.v1"}} }); await borrower.nft.approve({ "token": {"address": "0xobligation_receipt_address"}, "nftfi": {"contract": {"name": "v3.refinance.v1"}} }); ``` ### Response #### Success Response (200) - **result** (string) - Indicates the success of the approval transaction. #### Response Example ```json { "result": "approval_successful" } ``` ``` -------------------------------- ### Loan Repayment and Liquidation Source: https://github.com/nftfi-genesis/nftfi.js/blob/main/RELEASE.md Details how to repay or liquidate loans. For v3 loans, the nftfi.contract.name is not required, simplifying the process. ```APIDOC ## POST /loans/repay ### Description Repays a loan or initiates liquidation. For v3 loans, the nftfi.contract.name is not required. For older versions (v1, v2), the contract name must be specified. ### Method POST ### Endpoint /loans/repay ### Parameters #### Request Body - **loan** (object) - Required - Information about the loan. - **id** (string or number) - Required - The unique identifier of the loan. - **nftfi** (object) - Optional - NFTfi contract details. Only required for v1 and v2 loans. - **contract** (object) - Required for v1/v2 loans. - **name** (string) - Required for v1/v2 loans - The name of the nftfi contract associated with the loan. ### Request Example ```json // Repay a v3 loan await borrower.loans.repay({ "loan": {"id": 1} }); // Repay a v2 loan await borrower.loans.repay({ "loan": {"id": 2}, "nftfi": {"contract": {"name": "v2-3.loan.fixed.collection"}} }); ``` ### Response #### Success Response (200) - **result** (string) - Indicates the success status of the repayment or liquidation. #### Response Example ```json { "result": "repayment_successful" } ``` ```