import { BorrowSDK, ChainType } from '@satsterminal-sdk/borrow';
async function getLoan() {
const sdk = new BorrowSDK({
apiKey: process.env.API_KEY!,
chain: ChainType.ARBITRUM,
wallet: {
address: userBtcAddress,
signMessage: async (msg) => wallet.signMessage(msg),
sendBitcoin: async (to, sats) => wallet.send(to, sats)
}
});
try {
const result = await sdk.getLoan({
collateralBTC: 0.1,
loanAmountUSD: 5000,
ltv: 70,
onStatusUpdate: (status) => {
updateUI({ step: status.step, label: status.label });
},
onDepositReady: async (info) => {
showDepositModal(info);
// Or send automatically
// await sdk.sendBitcoin(info.address, info.amount);
},
onComplete: () => {
showSuccessModal('Loan created successfully!');
router.push('/dashboard');
},
onError: (error) => {
showErrorModal(error);
}
});
console.log('Loan workflow started:', result.workflowId);
} catch (error) {
console.error('Failed to start loan:', error);
}
}