USDT to Lightning
Buying BTC with USDC or USDT
This guide is about buying BTC using USDT and receive it via Lightning.
Swap USDT to Lightning
Follow these steps to complete a test swap from USDC (Polygon) to BTC (Lightning)
First create a new client
const client = await Client.builder()
.withSignerStorage(new InMemoryWalletStorage())
.withSwapStorage(new InMemorySwapStorage())
.withApiKey(process.env.API_KEY || "")
.build();You can find all available tokens to swap like this. For this example, we look for the token details for USDC on Polygon.
const tokens = await client.getTokens();
const usdtPolygon = tokens.evm_tokens.find(
(t) => t.symbol === "USDT" && t.chain === "137",
);Afterward we can create the swap request:
We only support invoices with amounts. However, you can provide an LNURL instead and we will fetch an invoice based on source or target amount.
const result = await client.createSwap({
sourceAsset: usdtPolygon,
targetAsset: BTC_LIGHTNING_INFO,
targetAddress: lightningInvoice,
});
const { response } = result;Next, create the swap by funding the contract.
// 1. Get unsigned Permit2 funding parameters
const params = await client.getPermit2FundingParamsUnsigned(
response.id,
polygonChainId,
);
// 2. Sign the EIP-712 typed data with the user's wallet (e.g. wagmi/viem)
// const signature = await walletClient.signTypedData(params.typedData);
const signature = "0x..."; // placeholder — use walletClient.signTypedData(params.typedData)
// 3. Encode the executeAndCreateWithPermit2 transaction calldata
// biome-ignore lint/correctness/noUnusedVariables: example code
const { to, data } = encodeExecuteAndCreateWithPermit2(
params.coordinatorAddress,
{
calls: params.calls,
preimageHash: params.preimageHash,
token: params.lockTokenAddress,
claimAddress: params.claimAddress,
timelock: params.timelock,
depositor: userWalletAddress,
sourceToken: params.sourceTokenAddress,
sourceAmount: params.sourceAmount,
nonce: params.nonce,
deadline: params.deadline,
signature,
},
);
// 4. Submit two transactions:
// a) One-time approve: source token → Permit2 (skip if already approved)
// await walletClient.sendTransaction({
// to: params.sourceTokenAddress,
// data: encodeApproveCallData(PERMIT2_ADDRESS, MaxUint256),
// });
//
// b) Fund the swap via the coordinator
// await walletClient.sendTransaction({ to, data });Wait for the status to become ServerFunded, the lightning invoice will settle in your lightning wallet automatically.
Build with AI
We have generated a llms-full.txt file that converts all our documentation into a single markdown document following the llmstxt.org standard. Feed it to any AI coding agent (Claude, Cursor, Copilot, etc.) and it will have everything it needs to integrate the LendaSwap SDK into your project.
Next Steps
- SDK & API Reference - Full SDK and REST API documentation