Handle errors
Validate input before you call a state-changing method. Catch SDK errors at the boundary where your app can show a user-facing message or retry.
Validate the LTV result
Check the loan-to-value (LTV) result before you create a loan:
const ltv = client.quote.calculateLtv(request, pools, prices);
if (ltv.validationErrors.length > 0) {
return {
ok: false,
message: ltv.validationErrors.map((error) => error.message).join(" "),
};
}
Handle SDK errors
Catch exported SDK errors before you handle unknown errors:
import {
LiquidiumError,
LiquidiumErrorCode,
SimpleLoanCreatedError,
} from "@liquidium/client";
try {
const loan = await client.simpleLoans.create(request);
return loan;
} catch (error) {
if (error instanceof SimpleLoanCreatedError) {
// Runs the same checks as create(); throws VALIDATION_ERROR if the loan
// does not match `request` or has already started.
return client.simpleLoans.recoverCreated({ loanId: error.loanId }, request);
}
if (error instanceof LiquidiumError) {
if (error.code === LiquidiumErrorCode.REQUEST_TIMEOUT) {
// Show retry copy or use the app's retry path.
}
throw error;
}
throw error;
}
If your UI needs different messages for timeout, transport, validation, or protocol failures, use the exported LiquidiumErrorCode values.
NO_OUTSTANDING_DEBT means lending.supply(...) stopped a repayment because the profile has no debt in that pool. Nothing was sent. Reload the position before you offer another repayment.
SimpleLoanCreatedError means the remote loan was created but response hydration failed. Recover with client.simpleLoans.recoverCreated({ loanId: error.loanId }, request), passing the same request you passed to create(...). Do not call create(...) again because that can create a duplicate loan. If recoverCreated(...) fails to load the loan, you can call it again.
simpleLoans.create(...) and simpleLoans.recoverCreated(...) check the canister loan against the request: pools, assets, borrow amount, borrow and refund destinations, max LTV and deposit window. They also reject a loan that has already started or already seen a deposit. If any check fails, they throw VALIDATION_ERROR and return no deposit target. Do not fund that loan. Both build the initial deposit from the collateral amount in your request. Do not use get(...) to show deposit targets after SimpleLoanCreatedError: it skips these checks.
create(...) can throw that VALIDATION_ERROR, a timeout, or a transport error after the API has created a loan. The API creates the loan before it adds it to the search index, so an empty client.simpleLoans.find(...) result right after one of these errors does not prove that no loan exists. Do not resubmit automatically. Check find(...) on your borrow or refund address again later, and submit the same request again only after the user confirms.
Wallet-executed deposit, borrow, and withdraw amounts below SDK minimums throw or return validation errors before state-changing calls. To show the minimum next to an amount input, use getMinimumDepositAmount(asset), getMinimumBorrowAmount(asset), or getMinimumWithdrawAmount(asset). Manual deposit-address flows do not accept an amount, so callers must apply the deposit minimum before broadcasting.
Decide when to retry
Use the error type and the operation type before you retry:
| Condition | Action |
|---|---|
Read-only request fails with NETWORK_ERROR, SERVICE_UNAVAILABLE, or REQUEST_TIMEOUT | Retry with your app's bounded backoff policy |
| State-changing request times out | Reload the related loan, activity, position, or history before you decide whether to submit another request |
Request fails with VALIDATION_ERROR or a protocol error | Correct the input or wait for the protocol state to change before you retry |
simpleLoans.create(...) fails with VALIDATION_ERROR, a timeout, or a transport error | A loan may already exist, even if client.simpleLoans.find(...) returns nothing yet. Do not resubmit automatically; check find(...) on your borrow or refund address again later and call create(...) again only after the user confirms |
SimpleLoanCreatedError is thrown | Recover with client.simpleLoans.recoverCreated(...); do not create another loan |
LIQUIDATION_APPROVAL_FAILED is thrown | Liquidation was not submitted. Inspect cause and check the ledger allowance if approval may have succeeded before deciding to retry |
recover(...) or a recovery submit(...) fails with CANISTER_REJECTED | The update may have succeeded. Read getRecoveryBalance(...) before you prepare another recovery |
The SDK does not define an application retry interval. Do not automatically repeat a state-changing method because an error might have occurred after the remote operation succeeded.
Validate destinations
Lending outflow and Simple Loan destinations are validated against the selected asset and delivery chain:
| Asset path | Chain | Accepted destination family |
|---|---|---|
| BTC L1 | "BTC" | Bitcoin mainnet chain address |
| Native ETH | "ETH" | Ethereum address |
| Native SOL | "SOL" | Base58-encoded 32-byte Solana address |
| ETH L1 USDC/USDT | "ETH" | Ethereum address |
| ICP native | "ICP" | IC principal, ICRC account, or ICP account identifier |
| ckBTC, ckETH, ckUSDC, ckUSDT, ckSOL | "ICP" | IC principal |
Lending uses chain and receiver. Simple Loans use borrow.chain, borrow.destination, refund.chain, and refund.destination. Prefer typed destination objects when the account family matters.
For lending, native ETH borrow and withdrawal destinations use a best-effort deployed-bytecode check. The SDK rejects a destination only when the check succeeds and confirms deployed bytecode. This includes smart contract wallets.
The SDK throws LiquidiumError with code LiquidiumErrorCode.INVALID_ADDRESS for malformed or reserved Ethereum addresses. It uses LiquidiumErrorCode.CONTRACT_DESTINATION_UNSUPPORTED when the best-effort check confirms that a native ETH lending destination has deployed bytecode. The Simple Loans API reports deployed-contract destination rejections as SDK API errors. Asset, chain, or destination-family mismatches use LiquidiumErrorCode.VALIDATION_ERROR. Catch these errors at the form boundary before retrying the flow.
When chain.id identifies Ethereum mainnet, lending queries the configured Ethereum Virtual Machine (EVM) client's getCode method. If the configured EVM client does not provide both chain.id and getCode, the SDK queries the Liquidium SDK API. RPC failures, API failures, and malformed responses do not block the outflow.
The SDK also validates the sender account for wallet-executed native ETH and ERC-20 supply as an EVM address. Deposit-address queries validate that the requested asset matches the selected ETH pool and reject malformed addresses returned by the deposit canister.