Handle Refunds & Failures
Refund EVM HTLC
Refund stablecoins locked in an EVM HTLC smart contract when a swap fails or times out.
EVM Refunds: Unlike BTC refunds which the SDK handles, EVM HTLC refunds can be done through the LendaSwap web interface or programmatically using the SDK's getEvmRefundCallData().
When to Refund
Refunds are typically needed when:
- You sent stablecoins but didn't receive BTC
- The swap timed out (service didn't complete)
- The counterparty didn't claim your BTC (for EVM→BTC swaps)
- Network issues prevented swap completion
Refund via Web Interface
The easiest way to refund an EVM HTLC is through the LendaSwap web interface:
- Go to app.lendaswap.com
- Connect your wallet (MetaMask, WalletConnect, etc.)
- Navigate to your swap history
- Find the expired swap
- Click "Refund" button
The web interface handles all the smart contract interaction for you.
Refund with wagmi/viem (React)
import { useWriteContract } from "wagmi";
const refund = await client.getEvmRefundCallData(swapId);
if (!refund.timelockExpired) {
const expiresIn = refund.timelockExpiry - Math.floor(Date.now() / 1000);
console.log(`Timelock expires in ${Math.ceil(expiresIn / 60)} minutes`);
} else {
const { writeContract } = useWriteContract();
await writeContract({
address: refund.to as `0x${string}`,
data: refund.data as `0x${string}`,
});
}Refund with ethers.js
import { BrowserProvider } from "ethers";
const provider = new BrowserProvider(window.ethereum);
const signer = await provider.getSigner();
const refund = await client.getEvmRefundCallData(swapId);
if (refund.timelockExpired) {
const tx = await signer.sendTransaction({
to: refund.to,
data: refund.data,
});
await tx.wait();
console.log("Refunded! TX:", tx.hash);
}Check HTLC Status
Query the smart contract to check refund eligibility:
const refund = await client.getEvmRefundCallData(swapId);
console.log("Timelock expired:", refund.timelockExpired);
console.log("Expiry:", new Date(refund.timelockExpiry * 1000).toISOString());
const swap = await client.getSwap(swapId);
console.log("Swap status:", swap.status);Important Notes
Gas Fees Required: Unlike claiming via Gelato (which is gasless), refunding an EVM HTLC requires paying gas fees in ETH (Ethereum) or MATIC (Polygon).
- Use web interface when possible - It's the simplest approach
- Wait for timelock - Refunds are blocked until timelock expires
- Gas fees - You need ETH/MATIC for gas to execute the refund
- Check both states - Ensure swap isn't already claimed or refunded
- Contract address varies - Different HTLC contracts for different networks