'Buy Now, Pay Later' financing
This guide provides an initial overview of using the Unlockd SDK for the 'Buy Now, Pay Later' functionality. As we're in the early stages of documentation, your feedback is crucial. We encourage developers to explore this use case and help shape these materials.
We're committed to supporting your integration journey. If you need personalized assistance or have suggestions, please reach out to us directly. Your input will help us create more comprehensive and useful documentation for the developer community.
Overview
'Buy Now, Pay Later' (BNPL) financing is a payment solution that allows users to purchase tokenized assets immediately while deferring payment indefinitely (thanks to Unlockd's open-ended loans).
By integrating BNPL functionalities using the Unlockd SDK, developers can provide a seamless and flexible financing option directly at the point of sale, backed by Real-World Assets.
How BNPL Works
User Selection: During the checkout process, users select the 'Buy Now, Pay Later' option as their preferred payment method.
Risk Assessment: Unlockd conducts a real-time appraisal of the user's tokenized assets to determine their value. This appraisal helps in setting an appropriate Loan-to-Value (LTV) ratio for the loan.
Down Payment Selection: Users are required to select a down payment amount, which may sometimes be a minimum required amount based on the value of the asset and the LTV ratio.
Loan Origination: Once the down payment is made, a loan is originated on the Unlockd protocol. The user's tokenized assets are used as collateral to secure the loan.
Instant Payment: The merchant receives the full payment for the asset immediately from Unlockd's liquidity pool, ensuring they do not bear any financial risk.
Open-Ended Loan: The loan remains open-ended, allowing the user to repay at their convenience as long as the health factor of their collateralized asset remains within acceptable limits. There are no fixed repayment schedules.
Collateral Management: The user’s collateralized assets are held securely in their Unlockd Account. These assets remain in the user’s custody and ownership, with Unlockd intervening only to prevent unauthorized transactions during the loan period.
Health Factor Monitoring: Users need to maintain the health factor of their loan, which is continuously monitored. If the health factor drops below a certain threshold, the user may need to add more collateral or repay part of the loan to restore the balance.
Completion: Once the loan is fully repaid, the collateralized assets are released back to the user without any restrictions.
Benefits of BNPL with Unlockd
Seamless Integration: Easily incorporate BNPL options into existing checkout flows using the Unlockd SDK.
Enhanced Flexibility: Users enjoy the flexibility of deferred payments without immediate financial burden.
Improved Cash Flow for Merchants: Merchants receive full payment upfront, improving their cash flow and reducing financial risk.
Lower Risk: The use of tokenized assets as collateral reduces the risk for both users and the protocol, enabling better loan terms and interest rates.
How-To Guide
This guide will walk you through the process of implementing a borrowing feature using the Unlockd SDK, allowing users to borrow against RWAs.
Prerequisites
Before you begin, ensure you have the following set up:
A React-based project
The Unlockd SDK installed (
@verislabs/unlockd-sdk
)Wagmi library and its dependencies (viem, react-query) for Ethereum interactions. You can Create a Project or Install it manually into your Project.
Basic understanding of React hooks and Ethereum transactions
This example is written in TypeScript and uses the wagmi library along with its dependencies. However, it's important to note that wagmi is not required to use the Unlockd SDK. The SDK itself is only dependent on viem.
Developers are free to use their preferred tools and libraries for wallet connection and blockchain interactions. This example serves as one possible implementation approach.
Implementation Steps
Set up the React component with necessary state variables and hooks.
Implement login, connection and authentication
Create or refresh Unlockd wallet (Unlockd Account).
Implement BNPL transaction execution.
Render the user interface with all interactive elements.
Code Overview
Implementing the Buy Now, Pay Later (buyNow in the SDK) functionality in a testnet environment is more complex due to the following reasons:
Two-wallet setup: You need one wallet to mint and list an NFT for sale on https://testnets.reservoir.tools/sepolia, and a second wallet to execute the purchase.
Testnet limitations: Reservoir does not allow token swaps on testnets, including Sepolia. This affects how BNPL transactions are structured in the test environment.
Currency differences: In the testnet implementation, we use WETH. However, on mainnet, USDC is typically used for RWA purchases.
These factors make recreating a full BNPL flow on testnet more challenging. Keep these differences in mind when testing and developing your BNPL integration, as the actual mainnet implementation will differ.
If you need any help, contact us. We actually like being bothered.
1. Set up the React component with necessary state variables and hooks
Initialize the main App component and set up all required state variables using React hooks. This includes states for managing user accounts, selected assets, and BNPL transaction details.
In this example, all the code is contained within the root component (App) for simplicity. However, this functionality can be implemented in any React component.
The hooks used (useAccount
, useDisconnect
, etc.) are imported from wagmi, while useState
is from React. These reactive variables can be stored and managed using any state management solution you prefer.
It's important to note the initialization of the Unlockd SDK, which is a crucial step:
This line, found at the end of the component, sets up the Unlockd API instance for interacting with the Sepolia testnet. Make sure to initialize the SDK appropriately in your implementation.
2. Implement login, connection and authentication
Set up functionality authenticating with Unlockd. This step calls the Unlockd SDK for obtaining an authentication token for the user's currently connected address by signing a blockchain message. The auth token is essential for user's interaction with the Unlockd SDK
3. Create or refresh Unlockd wallet (Unlockd Account)
Implement logic to create a new Unlockd wallet if the user doesn't have one, or refresh an existing one. This step is crucial for managing the user's assets and loans.
4. Implement BNPL transaction execution
Set up the core BNPL functionality using the Unlockd SDK. This involves getting the buy now signature, calculating the loan terms, and executing the BNPL transaction.
5. Render the user interface with all interactive elements
Create and render the user interface components that tie all the functionality together. This includes elements for wallet connection, asset selection, and initiating the BNPL transaction.
Last updated