A JavaScript SDK for interacting with the NFTfi Protocol.
NFTfi is a smart contract platform for P2P (Peer-2-Peer) loans using NFTs as collateral. P2P loans are directly between a Borrower and Lender — the Borrower uses an NFT as collateral to borrow ETH or DAI, and the Lender provides liquidity. The NFT is then held in an escrow contract until the loan is repaid. If the Borrower fails to repay in time, the Lender can claim the NFT.
Please note that this SDK is in closed beta, and is constantly under development. USE AT YOUR OWN RISK.
yarn installTo begin experimenting, please ensure that the following are available:
- a NFTfi API key (contact the team)
- an Ethereum RPC Provider URL
- a Private Key of an Ethereum wallet (funded with some ETH, wETH, and DAI (optional))
You will need the values above when initialising the SDK. We recommend that you start by using the SDK on the Goerli network, to get a feeling for the various functionality. Then once you are ready, transitioning over to Mainnet.
Please note that if the SDK is configured to use Goerli, it will use the dApp located at https://goerli-integration.nftfi.com. If a Mainnet configuration is used, the SDK will use the dApp located at https://app.nftfi.com.
After you've set up and configured the environment, you need to initialise NFTfi.
// Import SDK
import NFTfi from '@nftfi/js';
// Initialise
const nftfi = await NFTfi.init({
config: {
api: { key: <nftfi-sdk-api-key> }
},
ethereum: {
account: { privateKey: <ethereum-account-private-key> },
provider: { url: <ethereum-provider-url> }
}
});Upon initialisation the NFTfi SDK is bound to the account that will be interacting with the NFTfi protocol. The account address is computed by using the private key specified.
We recommend that you don't hardcode your credentials into NFTfi.init(...), instead you could use environment vars, or a more secure mechanism.
Once the SDK is initialised, you can use all the methods documented below.
Class for working with bundles.
Kind: global class
- Bundles
.mint()⇒Object.add(options)⇒Object.remove(options)⇒Object.seal(options)⇒Object.empty(options)⇒Object.elements(options)⇒Object
Mint a new bundle.
Kind: instance method of Bundles
Returns: Object - An object containing information about the minted bundle.
Example
// Mint a new bundle.
const bundle = await nftfi.bundles.mint();Add one or more elements to a bundle.
Kind: instance method of Bundles
Returns: Object - An object containing information about the bundle and added elements.
| Param | Type | Description |
|---|---|---|
| options | Object |
An object containing options for the add operation. |
| options.bundle | Object |
An object containing the ID of the bundle to add elements to. |
| options.bundle.id | string |
The ID of the bundle to add elements to. |
| options.elements | Array.<Object> |
An array of objects containing information about the elements to add. |
| options.elements[].token | Object |
An object containing the address and IDs of the token contract and the elements to add. |
| options.elements[].token.address | string |
The address of the token contract. |
| options.elements[].token.ids | Array.<string> |
An array of strings containing the IDs of the elements to add. |
Example
// Add elements from multiple token contracts to a bundle.
const bundle = await nftfi.bundles.add({
bundle: { id: '123' },
elements: [
{ token: { address: '0xabc', ids: ['1', '2'] } },
{ token: { address: '0xdef', ids: ['3'] } }
]
});Remove one or more elements from a bundle.
Kind: instance method of Bundles
Returns: Object - An object containing information about the bundle and removed elements.
| Param | Type | Description |
|---|---|---|
| options | Object |
An object containing options for the remove operation. |
| options.bundle | Object |
An object containing the ID of the bundle to remove elements from. |
| options.bundle.id | string |
The ID of the bundle to remove elements from. |
| options.elements | Array.<Object> |
An array of objects containing information about the elements to remove. |
| options.elements[].token | Object |
An object containing the address and IDs of the token contract and the elements to remove. |
| options.elements[].token.address | string |
The address of the token contract. |
| options.elements[].token.ids | Array.<string> |
An array of strings containing the IDs of the elements to remove. |
Example
// Removes elements from multiple token contracts from a bundle.
const bundle = await nftfi.bundles.remove({
bundle: { id: '123' },
elements: [
{ token: { address: '0xabc', ids: ['1', '2'] } },
{ token: { address: '0xdef', ids: ['3'] } }
]
});Seal a bundle, making it immutable.
Kind: instance method of Bundles
Returns: Object - An object containing information about the immutable contract.
| Param | Type | Description |
|---|---|---|
| options | Object |
An object containing options for the seal operation. |
| options.bundle | Object |
An object containing the ID of the bundle to seal. |
| options.bundle.id | string |
The ID of the bundle to seal. |
Example
// Seals a bundle.
const immutable = await nftfi.bundles.seal({
bundle: { id: '123' }
});Empty a bundle.
Kind: instance method of Bundles
Returns: Object - An object containing a success property.
| Param | Type | Description |
|---|---|---|
| options | Object |
An object containing options for the empty operation. |
| options.bundle | Object |
An object containing the ID of the bundle to empty. |
| options.bundle.id | string |
The ID of the bundle to empty. |
Example
// Empties a bundle.
const result = await nftfi.bundles.empty({
bundle: { id: '123' }
});Get the elements inside a bundle.
Kind: instance method of Bundles
Returns: Object - An object containing information about the bundle and an array of elements.
| Param | Type | Description |
|---|---|---|
| options | Object |
An object containing options for the elements operation. |
| options.bundle | Object |
An object containing the ID of the bundle to get elements for. |
| options.bundle.id | string |
The ID of the bundle to get elements for. |
Example
// Gets the elements in a bundle.
const bundle = await nftfi.bundles.elements({
bundle: { id: '123' }
});
console.log(bundle.data.elements);Class for working with ERC20 tokens.
Kind: global class
- Erc20
.allowance(options)⇒number.approve(options)⇒boolean.approveMax(options)⇒boolean.balanceOf(options)⇒number
Returns the ERC20 allowance, for v1 & v2 NFTfi contracts, for your account (by default), or a specified account.
Kind: instance method of Erc20
Returns: number - The user account's token allowance for that contract, in base units (eg. 1000000000000000000 wei)
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| [options.account.address] | object |
The account address to get the allowance of (optional) |
| options.token.address | string |
The ERC20 token address |
| options.nftfi.contract.name | string |
The name of the contract NFTfi contract (eg. v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed) |
Example
const balance = await nftfi.erc20.allowance({
token: { address: '0x00000000' },
nftfi: { contract: { name: 'v2-1.loan.fixed' } }
});Approves your account's ERC20 spending amount, if not already approved, for v1 & v2 NFTfi contracts.
Kind: instance method of Erc20
Returns: boolean - Boolean value indicating whether the operation succeeded
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.token.address | string |
The ERC20 token address |
| options.nftfi.contract.name | string |
The name of the contract NFTfi contract (eg. v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed) |
| options.amount | number |
The token amount to approve, in base units (eg. 1000000000000000000 wei) |
Example
const results = await nftfi.erc20.approve({
amount: 1000000000000000000,
token: { address: '0x00000000' },
nftfi: { contract: { name: 'v2-1.loan.fixed' } }
});Approves your account's ERC20 maximum amount, if not already approved, for v1 & v2 NFTfi contracts.
Kind: instance method of Erc20
Returns: boolean - Boolean value indicating whether the operation succeeded
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.token.address | string |
The ERC20 token address |
| options.nftfi.contract.name | string |
The name of the contract NFTfi contract (eg. v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed) |
Example
const results = await nftfi.erc20.approveMax({
token: { address: '0x00000000' },
nftfi: { contract: { name: 'v2-1.loan.fixed' } }
});Returns the balance of a given ERC20 token for your account (by default), or a specified account.
Kind: instance method of Erc20
Returns: number - The user account's token balance, in base units (eg. 1000000000000000000 wei)
| Param | Type | Description |
|---|---|---|
| options | object |
Options |
| [options.account.address] | object |
The account address to get the balance of (optional) |
| options.token.address | string |
The ERC20 token address |
Example
const balance = await nftfi.erc20.balanceOf({
token: { address: '0x00000000' }
});Class for working with ERC721 non-fungible tokens.
Kind: global class
- Erc721
.ownerOf(options)⇒string.setApprovalForAll(options)⇒boolean.isApprovedForAll(options)⇒boolean
Returns the owner of the specified NFT.
Kind: instance method of Erc721
Returns: string - The NFT's owner address
| Param | Type | Description |
|---|---|---|
| options | object |
Options |
| options.token.address | string |
The ERC721 token address |
| options.token.id | string |
The ERC721 token ID |
Example
const address = await nftfi.erc721.ownerOf({
token: {
address: '0x00000000',
id: '0'
}
});Sets or unsets the approval of a given NFTfi contract. The NFTfi contract is allowed to transfer all tokens of the sender on their behalf.
Kind: instance method of Erc721
Returns: boolean - Boolean value indicating whether the operation succeeded
| Param | Type | Description |
|---|---|---|
| options | object |
Options |
| options.token.address | string |
The ERC721 token address |
| options.nftfi.contract.name | string |
The name of the NFTfi contract (eg. v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed) |
Example
const address = await nftfi.erc721.setApprovalForAll({
token: {
address: '0x00000000'
},
nftfi: { contract: { name: 'v2-1.loan.fixed' } }
});Retruns the approval of a given NFTfi contract. The NFTfi contract is allowed to transfer all tokens of the sender on their behalf.
Kind: instance method of Erc721
Returns: boolean - Boolean value indicating whether permission has been granted or not
| Param | Type | Description |
|---|---|---|
| options | object |
Options |
| options.token.address | string |
The ERC721 token address |
| options.nftfi.contract.name | string |
The name of the NFTfi contract (eg. v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed) |
Example
const address = await nftfi.erc721.isApprovalForAll({
token: {
address: '0x00000000'
},
nftfi: { contract: { name: 'v2-1.loan.fixed' } }
});Class for working with immutables.
Kind: global class
- Immutables
.unseal(options)⇒Object.getBundle(options)⇒Object
Unseal an immutable.
Kind: instance method of Immutables
Returns: Object - An object containing information about the bundle that was released from the immutable.
| Param | Type | Description |
|---|---|---|
| options | Object |
An object containing options for the unseal operation. |
| options.immutable | Object |
An object containing the ID of the immutable bundle to unseal. |
| options.immutable.id | string |
The ID of the immutable bundle to unseal. |
Example
// Unseal an immutable bundle.
const bundle = await nftfi.immutables.unseal({
immutable: { id: '123' }
});Get a bundle.
Kind: instance method of Immutables
Returns: Object - An object containing information about an bundle.
| Param | Type | Description |
|---|---|---|
| options | Object |
An object containing options for the get operation. |
| options.immutable | Object |
An object containing the ID of the immutable to get the corresponding bundle for. |
| options.immutable.id | string |
The ID of the immutable to get the corresponding bundle for. |
Example
// Get the corresponding immutable for a given bundle.
const bundle = await nftfi.immutables.getBundle({
immutable: { id: '123' }
});Class for working with listings.
Kind: global class
Gets all current listings.
Kind: instance method of Listings
Returns: Array.<object> - Array of listings hashmaps
| Param | Type | Description |
|---|---|---|
| [options] | object |
Hashmap of config options for this method |
| [options.filters.nftAddresses] | Array.<string> |
NFT contract addresses (optional) |
| [options.pagination.page] | number |
Pagination page (optional) |
| [options.pagination.limit] | number |
Pagination limit (optional) |
Example
// get listings without specifying pagination or filters
const listings = await nftfi.listings.get();Example
// get the first `page` of listings, filtered by `nftAddresses`
const listings = await nftfi.listings.get({
filters: {
nftAddresses: ['0x11111111', '0x22222222']
},
pagination: {
page: 1,
limit: 20
}
});Class for working with loans.
Kind: global class
- Loans
.get(options)⇒Array.<object>.begin(options)⇒object.liquidate(options)⇒object.repay(options)⇒object.revokeOffer(options)⇒object
Gets loans in which your account is a participant.
Kind: instance method of Loans
Returns: Array.<object> - Array of listing objects
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.filters.counterparty | string |
Loans where the counterparty is: lender or borrower |
| options.filters.status | string |
Loan status: escrow, defaulted, repaid or liquidated |
Example
// Get loans in `escrow` where your account is the `lender`
const loans = await nftfi.loans.get({
filters: {
counterparty: 'lender',
status: 'escrow'
}
});Begin a loan. Called by the borrower when accepting a lender's offer.
Kind: instance method of Loans
Returns: object - Response object
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.offer.nft.address | string |
Address of the NFT being used as collateral |
| options.offer.nft.id | string |
ID of NFT being used as collateral |
| options.offer.terms.loan.currency | string |
Address of the ERC20 contract being used as principal/interest |
| options.offer.terms.loan.principal | number |
Sum of money transferred from lender to borrower at the beginning of the loan |
| options.offer.terms.loan.repayment | number |
Maximum amount of money that the borrower would be required to retrieve their collateral |
| options.offer.terms.loan.duration | number |
Amount of time (measured in seconds) that may elapse before the lender can liquidate the loan |
| options.offer.terms.loan.expiry | number |
Timestamp (in seconds) of when the signature expires |
| options.offer.lender.address | string |
Address of the lender that signed the offer |
| options.offer.lender.nonce | string |
Nonce used by the lender when they signed the offer |
| options.offer.signature | string |
ECDSA signature of the lender |
| options.offer.nftfi.fee.bps | number |
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 |
Name of contract used to facilitate the loan: v2-1.loan.fixed, v2.loan.fixed.collection |
Example
// Begin a loan on a lender's offer.
const result = await nftfi.loans.begin({
offer: {
nft: {
id: '42',
address: '0x00000000',
},
lender: {
address: '0x00000000',
nonce: '314159265359'
},
terms: {
loan: {
principal: 1000000000000000000,
repayment: 1100000000000000000,
duration: 86400 * 7, // 7 days (in seconds)
currency: "0x00000000",
expiry: 1690548548 // Friday, 28 July 2023 14:49:08 GMT+02:00
}
},
signature: '0x000000000000000000000000000000000000000000000000000',
nftfi: {
fee: { bps: 500 },
contract: { name: 'v2-1.loan.fixed' }
}
}
});Liquidate defaulted loans in which your account is a participant.
Can be called once a loan has finished its duration and the borrower still has not repaid.
Kind: instance method of Loans
Returns: object - Response object
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.loan.id | string |
The ID of the loan being liquidated |
| options.nftfi.contract.name | string |
Name of contract used to facilitate the liquidation: v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed |
Example
// Liquidate a v1 fixed loan
const result = await nftfi.loans.liquidate({
loan: { id: 1 },
nftfi: {
contract: {
name: 'v1.loan.fixed'
}
}
});Example
// Liquidate a v2 fixed loan
const result = await nftfi.loans.liquidate({
loan: { id: 2 },
nftfi: {
contract: {
name: 'v2.loan.fixed'
}
}
});Example
// Liquidate a v2 fixed collection loan
const result = await nftfi.loans.liquidate({
loan: { id: 3 },
nftfi: {
contract: {
name: 'v2.loan.fixed.collection'
}
}
});Example
// Liquidate a v2.1 fixed loan
const result = await nftfi.loans.liquidate({
loan: { id: 2 },
nftfi: {
contract: {
name: 'v2-1.loan.fixed'
}
}
});Repay a loan. Can be called at any time after the loan has begun and before loan expiry.
Kind: instance method of Loans
Returns: object - Response object
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.loan.id | string |
The ID of the loan being repaid |
| options.nftfi.contract.name | string |
Name of contract used to facilitate the repayment: v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed, v2.loan.fixed.collection |
Example
// Repay a v1 fixed loan
const result = await nftfi.loans.repay({
loan: { id: 1 },
nftfi: {
contract: {
name: 'v1.loan.fixed'
}
}
});Example
// Repay a v2 fixed loan
const result = await nftfi.loans.repay({
loan: { id: 2 },
nftfi: {
contract: {
name: 'v2.loan.fixed'
}
}
});Example
// Repay a v2.1 fixed loan
const result = await nftfi.loans.repay({
loan: { id: 2 },
nftfi: {
contract: {
name: 'v2-1.loan.fixed'
}
}
});Example
// Repay a v2 fixed collection loan
const result = await nftfi.loans.repay({
loan: { id: 3 },
nftfi: {
contract: {
name: 'v2.loan.fixed.collection'
}
}
});Revokes an active offer made by your account.
Kind: instance method of Loans
Returns: object - Response object
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.offer.nonce | object |
The nonce of the offer to be deleted |
| options.nftfi.contract.name | string |
Name of contract which the offer was created for: v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed |
Example
// Revoke a v1 fixed loan offer
const revoked = await nftfi.loans.revoke({
offer: {
nonce: '42'
},
nftfi: {
contract: {
name: 'v1.loan.fixed'
}
}
});Example
// Revoke a v2 fixed loan offer
const revoked = await nftfi.loans.revoke({
offer: {
nonce: '42'
},
nftfi: {
contract: {
name: 'v2.loan.fixed'
}
}
});Example
// Revoke a v2.1 fixed loan offer
const revoked = await nftfi.loans.revoke({
offer: {
nonce: '42'
},
nftfi: {
contract: {
name: 'v2-1.loan.fixed'
}
}
});Class for working with offers.
Kind: global class
- Offers
.get([options])⇒Array.<object>.create(options)⇒object.delete(options)⇒object.revoke(options)⇒object
When called with no argument, gets all offers made by your account. When provided with filters, gets all offers by specified filters.
Kind: instance method of Offers
Returns: Array.<object> - Array of offers
| Param | Type | Default | Description |
|---|---|---|---|
| [options] | object |
Hashmap of config options for this method | |
| [options.filters.nft.address] | string |
NFT contract address to filter by (optional) | |
| [options.filters.nft.id] | string |
NFT id of the asset to filter by (optional) | |
| [options.filters.lender.address.eq] | string |
Lender wallet address to filter by (optional) | |
| [options.filters.lender.address.ne] | string |
Lender wallet address to exclude (optional) | |
| [options.filters.nftfi.contract.name] | string |
Contract name to filter by (optional) | |
| [options.pagination.page] | number |
Pagination page (optional) | |
| [options.pagination.limit] | number |
Pagination limit (optional) | |
| [options.pagination.sort] | string |
Field to sort by (optional) | |
| [options.pagination.direction] | 'asc' | 'desc' |
Direction to sort by (optional) | |
| [options.validation.check] | boolean |
true |
Validate offers and append error info (optional) |
Example
// Get all offers made by your account
const offers = await nftfi.offers.get();Example
// Get the first page of offers made by your account, for a given NFT
const offers = await nftfi.offers.get({
filters: {
nft: {
address: "0x00000000",
id: "42"
}
},
pagination:{
page: 1,
limit: 10
}
});Example
// Get all offers made by your account, for multiple NFTs in a collection
const offers = await nftfi.offers.get({
filters: {
nft: {
address: "0x00000000"
}
}
});Example
// Get the first page of collection offers made by a specific lender
const offers = await nftfi.offers.get({
filters: {
nft: {
address: "0x00000000",
},
lender:{
address: {
eq: "0x12345567"
}
},
nftfi: {
contract: {
name: "v2.loan.fixed.collection"
}
}
},
pagination:{
page: 1,
limit: 10
}
});Example
// Get all offers made by your account, and dont perform validation checks.
const offers = await nftfi.offers.get({
validation: {
check: false
}
});Creates a new offer on a NFT or collection.
Kind: instance method of Offers
Returns: object - Response object
| Param | Type | Description |
|---|---|---|
| options | object |
Config options for this method |
| options.terms | object |
Terms of the offer |
| options.nft | object |
NFT to place an offer on |
| options.borrower | object |
Owner of the NFT |
| options.nftfi | object |
NFTfi options |
Example
// Create an offer on a NFT
const offer = await nftfi.offers.create({
terms: {
principal: 1000000000000000000,
repayment: 1100000000000000000,
duration: 86400 * 7, // 7 days (in seconds)
currency: "0x00000000",
expiry: 21600 // 6 hours (in seconds)
},
nft: {
address: "0x00000000",
id: "42"
},
borrower: {
address: "0x00000000"
},
nftfi: {
contract: {
name: "v2-1.loan.fixed"
}
}
});Deletes an active offer made by your account.
Kind: instance method of Offers
Returns: object - Response object
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.offer.id | object |
The Id of the offer to be deleted |
Example
// Get first avilable offer made by your account
const offers = await nftfi.offers.get();
const offerId = offers[0]['id'];
// Delete the offer by Id
const deleted = await nftfi.offers.delete({
offer: {
id: offerId
}
});Revokes an active offer made by your account.
Kind: instance method of Offers
Returns: object - Response object
| Param | Type | Description |
|---|---|---|
| options | object |
Hashmap of config options for this method |
| options.offer.nonce | object |
The nonce of the offer to be deleted |
| options.nftfi.contract.name | string |
Name of contract which the offer was created for: v1.loan.fixed, v2.loan.fixed, v2-1.loan.fixed |
Example
// Get first avilable offer made by your account
const offers = await nftfi.offers.get();
const nonce = offers[0]['lender']['nonce'];
const contractName = offers[0]['nftfi']['contract']['name']
// Revoke offer
const revoked = await nftfi.offers.revoke({
offer: { nonce },
nftfi: { contract: { name: contractName } }
});Class with utility methods.
Kind: global class
- Utils
.getNonce()⇒string.getExpiry()⇒number.formatEther(wei)⇒string.formatUnits(wei, unit)⇒string.formatWei(value, unit)⇒BigNumber.calcRepaymentAmount(principal, apr, duration)⇒number.calcApr(principal, repayment, duration)⇒number
Gets random nonce.
Kind: instance method of Utils
Returns: string - Nonce
Example
// Get a random nonce
const nonce = nftfi.utils.getNonce();Gets an expiry timestamp.
Kind: instance method of Utils
Returns: number - Expiry
Example
// Get an expiry timestamp into the future
const expiry = nftfi.utils.getExpiry();Formats an amount of wei into a decimal string representing the amount of ether.
Kind: instance method of Utils
Returns: string - Ether denomination of the amount
| Param | Type | Description |
|---|---|---|
| wei | number |
Wei denomination of the amount |
Example
// Format wei into the amount of ether
const wei = 100;
const ether = nftfi.utils.formatEther(wei);Formats an amount of wei into a decimal string representing the amount of unit.
Kind: instance method of Utils
Returns: string - String representation of value formatted with unit digits
| Param | Type | Description |
|---|---|---|
| wei | BigNumber |
Wei denomination of the amount |
| unit | string |
Unit denomination to format value |
Example
// Format usdc wei amount into the amount of unit
const wei = '1000000';
const usdc = nftfi.utils.formatUnits(wei, 'mwei'); // 1 usdcExample
// Format wei into the amount of unit
const wei = '1000000000000000000';
const ether = nftfi.utils.formatUnits(wei, 'ether'); // 1 etherFormats value into a BigNumber representing the value in wei from the unit specified.
Kind: instance method of Utils
Returns: BigNumber - BigNumber representation of value parsed with unit digits
| Param | Type | Description |
|---|---|---|
| value | number |
Value |
| unit | string |
Unit denomination to format from |
Example
// Format usdc amount into the amount of wei
const value = 1;
const usdcWei = nftfi.utils.formatWei(value, 'mwei'); // 1000000Example
// Format ether amount into the amount of wei
const value = 100;
const wei = nftfi.utils.formatWei(value, 'ether'); // 100000000000000000000Calculates the loan repayment amount given its other parameters.
Kind: instance method of Utils
Returns: number - The result maximum repayment amount, in base units (eg. 1250000000000000000 wei)
| Param | Type | Description |
|---|---|---|
| principal | number |
The loan's principal amount, in base units (eg. 1000000000000000000 wei) |
| apr | number |
The APR (yearly percentage rate) |
| duration | number |
The duration of the loan denominated in days |
Example
// Calculate the loan repayment amount
const principal = 1000000000000000000;
const apr = 32;
const duration = 30;
const amount = nftfi.utils.calcRepaymentAmount(principal, apr, duration);Calculates the loan APR (yearly percentage rate) given its other parameters
Kind: instance method of Utils
Returns: number - The result APR
| Param | Type | Description |
|---|---|---|
| principal | number |
The loan's principal amount in base units (eg. 1000000000000000000 wei) |
| repayment | number |
The maximum repayment amount to be paid by the borrower, in base units (eg. 1230000000000000000 wei) |
| duration | number |
The duration of the loan denominated in days |
Example
// Calculate the APR
const principal = 1000000000000000000;
const repayment = 1500000000000000000;
const duration = 30;
const apr = nftfi.utils.calcApr(principal, repayment, duration);To experiment with common NFTfi SDK use cases, run the following scripts from the root directory:
node examples/get-listings.js
node examples/make-offer-on-listing.js
node examples/make-offer-on-nft.js
node examples/make-offer-on-collection.js
node examples/get-my-offers.js
node examples/get-offers-on-listing.js
node examples/get-offers-on-collection.js
node examples/delete-my-offers.js
node examples/revoke-and-delete-my-offers.js
node examples/begin-loan.js
node examples/get-my-active-loans.js
node examples/repay-loan.js
node examples/liquidate-my-defaulted-loans.js
node examples/bundles/basics.js
node examples/bundles/get-nfts-in-bundle-listing.jsnode examples/multisig/gnosis-safe/make-offer-on-listing.js
node examples/multisig/gnosis-safe/make-offer-on-nft.js
node examples/multisig/gnosis-safe/get-offers.js
node examples/multisig/gnosis-safe/delete-offers.js
node examples/multisig/gnosis-safe/get-active-loans.js
node examples/multisig/gnosis-safe/liquidate-defaulted-loans.js