Skip to main content
Blockfront

Crypto markets, protocols and policy

How Do I Encode a Bridge Request in Bitcoin OP_RETURN?

How to encode a bridge request in a Bitcoin OP_RETURN output: pack the documented fields as raw bytes, add the correct push prefix, and use a zero-value output.

Blockfront Editorial

3 min read

How Do I Encode a Bridge Request in Bitcoin OP_RETURN?

Build a zero-value Bitcoin output whose OP_RETURN payload contains the bridge’s request fields in its documented order. The relay reads that output to identify the destination chain, recipient and action, so field order, widths and byte encoding must match the bridge specification.

Start with the bridge docs, not a layout of your own. For TeleSwap, use the documented order: destination chain ID, app ID, EVM recipient and fee field; encode integer fields big-endian at the specified widths. An EVM address such as 0x1111111111111111111111111111111111111111 is 20 raw bytes: remove the 0x prefix and encode the hex pairs as bytes. Do not put the 42-character ASCII address into the payload; it takes 42 bytes and shifts every later field the parser reads.

Say the request targets chain ID 137, uses app ID 20, names that sample recipient, and includes the fee value required by the request. Serialize each value using TeleSwap’s documented widths, then concatenate the bytes in that order. The payload length is the sum of those fixed field widths. For payloads up to 75 bytes, the script is 0x6a, one byte containing the payload length, then the payload; that makes the script length payload plus two bytes. For 76–255 data bytes, use OP_PUSHDATA1 (0x4c) followed by a one-byte length.

TeleSwap’s documentation supplies the request layout; bitcoin defi adds background on the wider setting for this bridge request. Bitcoin’s Developer Guide describes OP_RETURN as provably unspendable and says the output must pay exactly zero satoshis. It records an 80-data-byte default relay limit in older Bitcoin Core versions; check the policy of the node you use, and keep the payload within 80 bytes when broad compatibility matters.

Before signing or broadcasting the PSBT, decode the built transaction and compare the OP_RETURN data byte for byte with the intended payload. Also verify the output value is zero and the BTC deposit goes to the designated Locker address. A wrong order, endianness, ASCII address, non-zero value or other deposit address can prevent the request from being parsed or the mint from being triggered.

Check these two cases before integrating

What happens to BTC sent to a Locker with a malformed OP_RETURN?

The bridge may not recognize a valid request, so the expected mint may not happen. Check TeleSwap’s recovery process before sending funds; do not treat a malformed payload as a successful deposit.

Can one Bitcoin transaction carry requests for two recipients?

Do not assume it can. Follow the bridge’s rules for outputs and requests, and confirm whether its parser supports multiple requests before building one transaction for two recipients.