Skip to main content
This guide walks you through a complete swap flow from Bitcoin (BTC) to Ethereum USDC using the LeoKit API. We’ll cover all five steps: getting a quote, generating a deposit transaction, signing and broadcasting, saving the transaction hash, and tracking the swap status.

Overview

The complete swap flow consists of 5 steps:
  1. Get Quote - Request swap rates from multiple protocols
  2. Generate Deposit - Create an unsigned transaction
  3. Sign & Broadcast - Sign with wallet and broadcast to blockchain
  4. Save Transaction - Register the transaction hash with LeoKit
  5. Track Status - Monitor swap progress until completion

Example: BTC → ETH USDC

Let’s swap 1 BTC (100,000,000 satoshis) to USDC on Ethereum.

Step 1: Get Quote

Request quotes from all supported protocols to find the best rate.
Response:
Save the quote_id - you’ll need it for all subsequent steps. Quote IDs expire after 15 minutes.

Step 2: Generate Deposit Transaction

Create an unsigned transaction using the quote ID and your selected protocol.
Response:
For Bitcoin transactions, LeoKit returns a PSBT (Partially Signed Bitcoin Transaction) that you’ll sign in the next step.

Step 3: Sign & Broadcast (Client-Side)

Sign the transaction with your wallet and broadcast it to the Bitcoin network.
Never expose your private keys. This example is for educational purposes. Use secure wallet libraries in production.

Step 4: Save Transaction Hash

Register the transaction hash with LeoKit to enable status tracking.

Step 5: Track Status

Poll the status endpoint to monitor your swap progress.

Status Values

Best Practices

Use appropriate polling intervals - Poll every 10-15 seconds. Faster polling won’t speed up the swap.
Save quote_id persistently - Store it in your database to track swaps even after page refreshes.
Handle timeouts gracefully - Cross-chain swaps can take 5-10 minutes. Show progress indicators to users.
Test with small amounts first - Always test new integrations with minimal amounts on testnet/mainnet.

Next Steps

ERC20 Approvals

Learn how to handle token approvals for ERC20 swaps

Error Debugging

Debug failed swaps using trace IDs