# Token Exchange Protocol for UTXO-based Overlay Networks

Ty Everett (<ty@projectbabbage.com>)

## Abstract

We propose a peer-to-peer token exchange protocol under which two parties can securely exchange digital tokens (assets) within Bitcoin SV's BRC-22 UTXO-based Overlay Networks.

## Motivation

The motivation behind this protocol is the need for an efficient and secure mechanism to exchange different types of tokenized assets on top of overlay networks between two parties in the BSV ecosystem.

## Specification

The protocol is initiated when two parties, Alice and Bob, desire to conduct an asset exchange. It assumes that both parties are online. We specify this protocol conceptually, by example:

1. **Offer Initiation:** Alice wants to sell 5 apples for 3 USD. She creates a new transaction moving her 5 apples into a new output. This output includes her exchange request, peer-to-peer contact information (such as [BRC-33](/peer-to-peer/0033.md)), and the asset ID for the asset she would like to exchange, reflected in a new transaction on the overlay network.
2. **Revocation by the Initiator:** If Alice decides to cancel her proposition, she can spend the offer output and move her apples back, retracting the offer.
3. **Offer Acceptance:** Bob is looking to purchase 5 apples for his 3 USD. He sees Alice's offer, verifying her offered UTXO(s) are registered on the overlay. Bob creates a new transaction, conditionally signing his USD over to Alice using `SIGHASH_SINGLE`. He ensures the signature is only valid over all the inputs from both Alice and Bob. The single output which he signs pays himself the 5 apples from Alice's inputs.
4. **Offer Presentation:** Bob contacts Alice, identifies himself and shares the transaction and signature with her.
5. **Verification:** Alice verifies the information and conducts due diligence to confirm Bob's outpoints on the overlay network. She verifies the signature and the validity of the transaction. If she decides not to proceed, she can simply do nothing or send Bob a rejection message.
6. **Transaction Settlement:** Alice responds by signing her inputs with a `SIGHASH_ALL` signature, spending her inputs, and adding an output that pays her Bob's 3 USD. She adds her signature to the transaction, and broadcasts it to Bob and the overlay network. Once her transaction reaches the overlay network, Alice now possesses Bob's 3 USD and Bob is the owner of Alice's 5 apples.

## Implementation

This Token Exchange Protocol can be implemented on any UTXO-based overlay network adhering to [BRC-59](/opinions/0059.md), [BRC-45](/tokens/0045.md), [BRC-22](/overlays/0022.md) and [BRC-24](/overlays/0024.md). This protocol has security built-in, stipulating both `SIGHASH` type usage and broadcasting and topical membership verification methods.

## Future work

In general, overlay network recovery mechanisms for uncooperative participant handling (non-registration or improper broadcast of transactions) need to be defined as part of future specifications. Further tooling and guidance for developers would expand adoption.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://bsv.brc.dev/tokens/0079.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
