Lendasat LogoLendasat Docs
Create Swaps

EVM → BTC

Create a swap from stablecoins on Polygon or Ethereum to Bitcoin (via Arkade or Lightning).

Overview

EVM to BTC swaps allow you to convert stablecoins like USDC or USDT to Bitcoin. The process:

  1. Create swap - Request a swap and get HTLC contract details
  2. Deposit stablecoins - Send tokens to the HTLC contract (requires wallet signature)
  3. Receive BTC - Bitcoin is sent to your Arkade wallet or Lightning invoice

EVM to BTC swaps require signing a transaction with your EVM wallet (e.g., MetaMask). We recommend using wagmi with viem for React apps, or ethers.js for vanilla JS/TS.


EVM → Arkade

Swap USDC/USDT to BTC on your Arkade wallet:

const result = await client.createEvmToArkadeSwap({
  sourceChain: "polygon",
  sourceToken: "usdc_pol",
  sourceAmount: 100, // 100 USDC
  targetAddress: "ark1q...", // Your Arkade address
  userAddress: "0xYourEvmAddress",
});

console.log("Approve token:", result.response.source_token_address);
console.log("HTLC contract:", result.response.htlc_address_evm);
console.log("Swap ID:", result.response.id);

EVM → Lightning

Swap stablecoins to receive BTC via Lightning:

const result = await client.createEvmToLightningSwap({
  sourceChain: "polygon",
  sourceToken: "usdc_pol",
  bolt11Invoice: "lnbc...", // Lightning invoice to pay
  userAddress: "0xYourEvmAddress",
});

console.log("HTLC contract:", result.response.htlc_address_evm);
console.log("Swap ID:", result.response.id);

Deposit with wagmi/viem (React)

Use getEvmFundingCallData() from the SDK to get the deposit transaction data:

import { useWriteContract } from "wagmi";

// Get funding call data from the SDK
const funding = await client.getEvmFundingCallData(
  result.response.id,
  6, // USDC decimals
);

// Step 1: Approve token spend
const { writeContract } = useWriteContract();
await writeContract({
  address: funding.approve.to as `0x${string}`,
  abi: erc20Abi,
  functionName: "approve",
  args: [funding.approve.to, funding.approve.data],
});

// Step 2: Fund the HTLC
await writeContract({
  address: funding.createSwap.to as `0x${string}`,
  data: funding.createSwap.data as `0x${string}`,
});

Deposit with ethers.js

import { BrowserProvider } from "ethers";

const provider = new BrowserProvider(window.ethereum);
const signer = await provider.getSigner();

// Get funding call data from the SDK
const funding = await client.getEvmFundingCallData(
  result.response.id,
  6, // USDC decimals
);

// Step 1: Approve token spend
const approveTx = await signer.sendTransaction({
  to: funding.approve.to,
  data: funding.approve.data,
});
await approveTx.wait();

// Step 2: Fund the HTLC
const fundTx = await signer.sendTransaction({
  to: funding.createSwap.to,
  data: funding.createSwap.data,
});
await fundTx.wait();

Swap Request Parameters

EVM → Arkade

ParameterTypeRequiredDescription
userAddressstringYesYour EVM wallet address
sourceAmountnumberYesAmount of stablecoins to swap
sourceTokenstringYesToken ID (usdc_pol, usdc_eth, etc.)
targetChainstringYesTarget chain (polygon, ethereum)
referralCodestringNoOptional referral code

EVM → Lightning

ParameterTypeRequiredDescription
bolt11InvoicestringYesLightning invoice to receive payment
userAddressstringYesYour EVM wallet address
sourceTokenstringYesToken ID (usdc_pol, usdc_eth, etc.)
targetChainstringYesTarget chain (polygon, ethereum)
referralCodestringNoOptional referral code

Swap Response

FieldTypeDescription
idstringUnique swap ID
sourceAmountnumberStablecoin amount
targetAmountnumberBTC amount in sats
contractAddressstringHTLC contract address
hashLockstringHash lock for HTLC
timelocknumberHTLC expiration timestamp
recipientstringService's address in HTLC
statusstringCurrent swap status
createdAtstringCreation timestamp

Important Notes

Token Approval Required: Before depositing, you must approve the HTLC contract to spend your tokens. The SDK's getEvmFundingCallData() handles this for you.

  1. Two transactions - Approve + Deposit (can be combined with Permit2)
  2. Gas fees - You pay gas for the EVM deposit transaction
  3. Timelock - Deposit before the timelock expires, or the swap will fail
  4. Automatic BTC - Once deposit is confirmed, BTC is sent automatically

Next Steps

After creating a swap:

  1. Approve tokens - Approve HTLC contract to spend your tokens
  2. Deposit - Send tokens to the HTLC contract
  3. Monitor status - Check swap status using Get Swap by ID
  4. Receive BTC - Bitcoin is sent to your Arkade wallet or Lightning invoice automatically