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'
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
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.