Getting Started with Suilend SDK
This guide will walk you through setting up and using the Suilend SDK to interact with the Suilend lending protocol on Sui.
Prerequisites
Node.js 16+ or Bun
Basic knowledge of TypeScript/JavaScript
A Sui wallet with some SUI tokens for gas fees
Installation
Install the SDK and peer dependencies:
npm install @suilend/sdk @mysten/[email protected] @mysten/[email protected] @suilend/sui-fe@^0.3.5Set up your environment:
Create a .env file in your project root:
# Optional: Use beta market for testing
NEXT_PUBLIC_SUILEND_USE_BETA_MARKET=false
# Your Sui RPC endpoint (optional, defaults to mainnet)
SUI_RPC_URL=https://fullnode.mainnet.sui.ioBasic Setup
1. Initialize the Client
2. Check Your Existing Obligations
Before performing any operations, check if you already have obligations:
Tutorial 1: Your First Deposit
Let's start by depositing SUI tokens to earn interest:
Tutorial 2: Borrowing Against Your Collateral
Now let's borrow USDC against your SUI collateral:
Tutorial 3: Claiming Rewards
Claim rewards from liquidity mining programs:
Tutorial 4: Repaying Your Loan
Repay borrowed tokens to reduce your debt:
Tutorial 5: Withdrawing Your Collateral
Withdraw your deposited collateral:
Complete Example: Full Lending Flow
Here's a complete example that demonstrates the full lending lifecycle:
Best Practices
1. Error Handling
Always wrap SDK calls in try-catch blocks and handle specific error cases:
2. Gas Management
Set appropriate gas budgets for complex transactions:
3. State Refreshing
Always refresh obligation state before operations that depend on current prices:
4. Batching Operations
Combine multiple operations in a single transaction for better gas efficiency:
Next Steps
Read the [API Reference] for detailed method documentation
Explore the [main README] for advanced features
Check out the admin functions for protocol management
Join our Discord for support
Common Issues
"Obligation not found"
Make sure you're using the correct lending market type arguments
Verify the obligation ID exists and belongs to your address
"Insufficient collateral"
Check your collateral ratio before borrowing
Add more collateral or repay some debt
"Price staleness"
Call
refreshAll()to update price feedsCheck if Pyth price feeds are working properly
"Gas budget exceeded"
Increase your gas budget for complex transactions
Consider splitting operations across multiple transactions