LI.FI Documentation
LI.FI WebsiteAPI ReferenceHelp / FAQ / Create support ticketRequest API Key
  • 🏡Getting Started
    • ❓What is LI.FI
    • 🌟Why LI.FI?
    • 🆚LI.FI vs Aggregators/DEXs/Bridges
    • 📖LI.FI Terminology
    • ❓FAQ
    • 💡Use Cases
      • Mobile/Gaming Wallets
    • 🏹LI.FI vs. Other Aggregators
    • 🤝Partnership
    • 🌐Powered by LI.FI
  • 🔐Security First
  • ✅List: Chains, Bridges, DEX Aggregators, Solvers
  • 💲Monetization / Take Fees
  • 🔎Transaction Explorer
  • 🔏Rate Limits & API Key
  • How to get integrated by LI.FI?
    • For Bridges
    • For DEXs/Aggregators/Solvers
  • 🆘Technical FAQ
  • LI.FI PRODUCTS
    • Glacis
    • LI.FI Solver
    • LI.FI Intents System
  • LI.FI API
    • ⚙️LI.FI API
      • Transferring Tokens (Example)
      • Requesting supported Chains
      • Requesting all supported Tools
      • Requesting all known Tokens
      • Getting Token Information
      • Getting all possible Connections
      • Requesting a Quote
        • Token Transfer
        • Optimizing quote response timing
        • Cross-Chain Contract Calls
        • Possible Tool Errors
        • Testing your integration
      • Status of a Transaction
      • Requesting Analytics Data
    • ⚔️TX-Batching aka "Zaps"
    • 🏄Solana
      • Request examples
    • 🪙Bitcoin
      • Request examples
    • ⛽LI.Fuel
  • Integrate LI.FI SDK
    • 🚀LI.FI SDK Overview
    • 📦Install LI.FI SDK
    • ⚙️Configure SDK
    • 🪐Configure SDK Providers
    • 📜Request Routes/Quotes
    • 🎯Execute Routes/Quotes
    • ⛓️Chains and Tools
    • 💰Token Management
    • 🕵️Testing Integration
    • 🚗Migrate from v2 to v3
  • INTEGRATE LI.FI WIDGET
    • 🧩LI.FI Widget Overview
    • 📦Install Widget
    • 🎮Select Widget Variants
    • ⚙️Configure Widget
    • 🎨Customize Widget
    • ⚡Widget Events
    • 👛Wallet Management
    • 🌍Internationalization
    • ⚛️Compatibility with Next.js, Remix, Nuxt, etc.
    • 🛣️React Router Compatibility
    • 📖Widget API Reference
    • 🚗Migrate from v2 to v3
  • Smart Contracts
    • Overview
    • Deployments/Contract Addresses
    • Audits
  • Support & Misc.
    • API Status
    • Technical Help Desk & FAQ
    • Create a Partner Ticket
    • Discord Support
    • Telegram Support
    • Twitter
    • Github
    • Licenses
Powered by GitBook
LogoLogo

Connect with us

  • Github
  • Twitter
  • Discord
  • LinkedIn

More Information

  • Help Desk / FAQ
  • API Reference
  • Website
On this page
  • Requesting Bitcoin-specific information via the API
  • Requesting a Quote
  • Bitcoin to Ethereum
  • Ethereum to Bitcoin
  • Executing the transaction
  • Transaction Data
  • Retrieving memo from PSBT

Was this helpful?

Export as PDF
  1. LI.FI API

Bitcoin

LI.FI is live on Bitcoin!

LI.FI REST API offers seamless integration for native Bitcoin bridging and swaps through Thorswap.

NOTE: Thorswap is only supported for Bitcoin <> Ethereum, Avalanche, or BSC transfers

In this documentation, we will explore how to use the API for Bitcoin related requests, executing transactions, getting routes, and checking the status of transactions.

Currently only native SegWit addresses are supported which are addresses that start with “bc1q”

Requesting Bitcoin-specific information via the API

Chains

curl --request GET \
     --url 'https://li.quest/v1/chains?chainTypes=UTXO' \
     --header 'accept: application/json'

Tools

curl --request GET \
  --url 'https://li.quest/v1/tools?chains=20000000000001' \
  --header 'accept: application/json'

Tokens

curl --request GET \
     --url 'https://li.quest/v1/tokens?chains=BTC' \
     --header 'accept: application/json'

Token details

curl --request GET \
     --url 'https://li.quest/v1/token?chain=20000000000001&token=bitcoin' \
     --header 'accept: application/json'

Requesting a Quote

Bitcoin to Ethereum

const request {
    fromAddress="YOUR_BTC_ADDRESS"
    fromAmount=50000000
    fromChain=20000000000001
    fromToken=bitcoin
    toAddress="YOUR_EVM_ADDRESS"
    toChain=1
    toToken=USDC
}

Ethereum to Bitcoin

const request {
    fromAddress="YOUR_EVM_ADDRESS"
    fromAmount=50000000
    fromChain=1
    fromToken=bitcoin
    toAddress="YOUR_BTC_ADDRESS"
    toChain=20000000000001
    toToken=USDC
}

Executing the transaction

Transaction Data

BTC to Ethereum, Avalanche, or BNB Smart Chain (BSC)

After retrieving the quote, the funds need to be sent to the BTC vault address provided in the response, along with a memo.

  • Transaction Handling: The transaction that leaves BTC and goes to EVM needs to be sent to an EVM address. The memo ensures that the swap details are correctly processed by the validators.

NOTE: Only send tx n a timely manner (30min), it is always recommended to request an up-to-date quote to ensure to get the latest information.

The following is an example of transaction data:

"transactionRequest": {
    "to": "bc1qawcdxplxprc64fh38ryy4crndmfgwrffpac743", //thorswap vault to send BTC to
    "data": "70736274ff0100c30200000001e8396f02ae2dccdea558b4b5f41f760d967751bfa06d3e0a318e15c9c6c15cd80100000000fdffffff03803e000000000000160014ff8210bf2cf71b0ad5d5c7e740ab43482c1045be0000000000000000496a473d3a653a3078303263333141376336333833303246373966664435383235663743314162393344353132346439333a3a6c6966692f2d5f3a302f32307c3078656534383336313882fc000000000000160014311564348890e005880a9bc834aaa5884f1b5932000000000001011fc23f010000000000160014311564348890e005880a9bc834aaa5884f1b593200000000",
    "value": "500000"
  }

'data' in transactionRequest object is PSBT (partially signed bitcoin transaction) and memo needs to be retrieved from PSBT by decoding it.

Retrieving memo from PSBT

Here's an example using bitcoinjs

const psbtHex = transactionRequest.data

// Create PSBT object from hex data
const psbt = Psbt.fromHex(psbtHex, { network: networks.bitcoin })

// Find OP_RETURN output in the transaction outputs
const opReturnOutput = psbt.txOutputs.find((output) => {
  if (output?.script) {
    // Convert the output script to hex string for checking
    const scriptHex = Array.from(output.script)
      .map((b) => b.toString(16).padStart(2, '0'))
      .join('')

    // Check if script starts with OP_RETURN opcode (0x6a)
    return scriptHex.startsWith('6a')
  }
  return false
})

// If an OP_RETURN output exists, decode its script data as UTF-8 text (memo)
const memo = opReturnOutput?.script 
  ? new TextDecoder().decode(
      new Uint8Array(Object.values(opReturnOutput.script))
    )
  : undefined

Last updated 4 months ago

Was this helpful?

To request a quote for a transaction between Bitcoin and Ethereum, Avalanche, or BSC, you can use the provided . Below is an example of a request to get a quote for transferring 0.5 BTC to USDC on Ethereum:

To request a quote for a transaction between Ethereum and Bitcoin, you can use the provided . Below is an example of a request to get a quote for transferring 50 USDC on Ethereum to native BTC:

Memo Functionality: Similar to Thorchain, uses memos for BTC to EVM swaps. The memo in the BTC transaction specifies the swap's destination address and chain.

PSBT can be decoded using any library like or .

🪙
guide
guide
LI.FI
bitcoinjs
scure-btc-signer