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:
- Create swap - Request a swap and get HTLC contract details
- Deposit stablecoins - Send tokens to the HTLC contract (requires wallet signature)
- Receive BTC - Bitcoin is sent to your Arkade wallet or Lightning invoice
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
| Parameter | Type | Required | Description |
|---|---|---|---|
userAddress | string | Yes | Your EVM wallet address |
sourceAmount | number | Yes | Amount of stablecoins to swap |
sourceToken | string | Yes | Token ID (usdc_pol, usdc_eth, etc.) |
targetChain | string | Yes | Target chain (polygon, ethereum) |
referralCode | string | No | Optional referral code |
EVM → Lightning
| Parameter | Type | Required | Description |
|---|---|---|---|
bolt11Invoice | string | Yes | Lightning invoice to receive payment |
userAddress | string | Yes | Your EVM wallet address |
sourceToken | string | Yes | Token ID (usdc_pol, usdc_eth, etc.) |
targetChain | string | Yes | Target chain (polygon, ethereum) |
referralCode | string | No | Optional referral code |
Swap Response
| Field | Type | Description |
|---|---|---|
id | string | Unique swap ID |
sourceAmount | number | Stablecoin amount |
targetAmount | number | BTC amount in sats |
contractAddress | string | HTLC contract address |
hashLock | string | Hash lock for HTLC |
timelock | number | HTLC expiration timestamp |
recipient | string | Service's address in HTLC |
status | string | Current swap status |
createdAt | string | Creation 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.
- Two transactions - Approve + Deposit (can be combined with Permit2)
- Gas fees - You pay gas for the EVM deposit transaction
- Timelock - Deposit before the timelock expires, or the swap will fail
- Automatic BTC - Once deposit is confirmed, BTC is sent automatically
Next Steps
After creating a swap:
- Approve tokens - Approve HTLC contract to spend your tokens
- Deposit - Send tokens to the HTLC contract
- Monitor status - Check swap status using Get Swap by ID
- Receive BTC - Bitcoin is sent to your Arkade wallet or Lightning invoice automatically