# BRC20

When selecting a token pair and clicking swap, if it is a BRC20 token, a pre-swap request is required.

## POST /brc20swap/get\_swap\_psbt\_txsize

> Get the tx size of the PSBT-based exchange

```json
{"openapi":"3.0.1","info":{"title":"Backend API","version":"1.0.0"},"servers":[{"url":"https://api-testnet4.dotswap.app","description":"Swap test"},{"url":"https://api.dotswap.app","description":"Swap official"}],"security":[],"paths":{"/brc20swap/get_swap_psbt_txsize":{"post":{"summary":"Get the tx size of the PSBT-based exchange","deprecated":false,"description":"","tags":[],"parameters":[],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"send_coin_type":{"type":"string","title":"The type of coin to send"},"send_tick":{"type":"string","title":"The tick of the coin to send"},"send_amount":{"title":"The amount to send","type":"string"},"receive_coin_type":{"type":"string","title":"The type of coin to receive"},"receive_tick":{"type":"string","title":"The tick of the coin to receive"},"receive_amount":{"type":"string","title":"The amount to receive"},"address":{"type":"string","title":"Address"},"slipper":{"type":"string","title":"Slippage"},"fee_rate":{"type":"integer","title":"Fee rate"},"ins":{"type":"array","items":{"type":"string"},"title":"Inscription ID","description":"Only needed when exchanging with BRC20"},"method":{"type":"string","description":"Non-cross-pool swap, cross-pool pools_swap, just pass 'pools_swap'"}},"required":["send_coin_type","send_tick","send_amount","receive_coin_type","receive_tick","receive_amount","address","fee_rate","slipper","ins","method"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"integer"},"msg":{"type":"string"},"data":{"type":"object","properties":{"tx_size":{"type":"integer","title":"PSBT tx size","description":"Pass the original value to the get_swap_psbt interface"},"ins_contain_sats":{"type":"integer","description":"The sum of satoshis in the input inscriptions"},"checksum":{"type":"string","description":"Pass the original value to the get_swap_psbt interface"},"vins":{"type":"array","items":{"type":"string"},"description":"Pass the original value to the get_swap_psbt interface"},"usr_cnt":{"type":"integer","description":"Pass the original value to the get_swap_psbt interface"}},"required":["tx_size","vins","usr_cnt"],"nullable":true}},"required":["code","msg","data"]}}},"headers":{}}}}}}}
```

{% hint style="info" %}
Use the same address for both address and btc\_address.

The response from this endpoint should be passed as is to the get\_swap\_psbt endpoint.

The current slipper (slippage) limit is 12%.
{% endhint %}

## POST /brc20swap/get\_swap\_psbt

> Get the unsigned PSBT for BRC20 exchange

```json
{"openapi":"3.0.1","info":{"title":"Backend API","version":"1.0.0"},"servers":[{"url":"https://api-testnet4.dotswap.app","description":"Swap test"},{"url":"https://api.dotswap.app","description":"Swap official"}],"security":[],"paths":{"/brc20swap/get_swap_psbt":{"post":{"summary":"Get the unsigned PSBT for BRC20 exchange","deprecated":false,"description":"","tags":[],"parameters":[],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"send_coin_type":{"type":"string","title":"The type of coin to send"},"send_tick":{"type":"string","title":"The tick of the coin to send"},"send_amount":{"title":"The amount to send","type":"string"},"receive_coin_type":{"type":"string","title":"The type of coin to receive"},"receive_tick":{"type":"string","title":"The tick of the coin to receive"},"receive_amount":{"type":"string","title":"The amount to receive"},"address":{"type":"string","title":"Address"},"slipper":{"type":"string"},"fee_rate":{"type":"integer"},"ins":{"type":"array","items":{"type":"string"},"description":"Only needed when exchanging with BRC20","title":"Inscription ID"},"user_public_key":{"type":"string"},"tx_size":{"type":"integer","description":"Obtained from the get_swap_psbt_txsize interface"},"checksum":{"type":"integer","description":"Obtained from the get_swap_psbt_txsize interface"},"vins":{"type":"array","items":{"type":"string"},"description":"Obtained from the get_swap_psbt_txsize interface"},"usr_cnt":{"type":"integer","description":"Obtained from the get_swap_psbt_txsize interface"},"chl":{"type":"string"},"method":{"type":"string","description":"Non-cross-pool swap, cross-pool pools_swap, just pass 'pools_swap'"}},"required":["send_coin_type","send_tick","send_amount","receive_coin_type","receive_tick","receive_amount","address","fee_rate","slipper","tx_size","checksum","vins","usr_cnt","user_public_key","ins","chl","method"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"integer"},"msg":{"type":"string"},"data":{"type":"object","properties":{"order_id":{"type":"string","title":"PSBT tx size"},"psbt":{"type":"string"},"check_sign_only":{"type":"boolean"}},"required":["order_id","psbt","check_sign_only"]}},"required":["code","msg","data"]}}},"headers":{}}}}}}}
```

> After a successful pre-swap request, obtain the unsigned PSBT. Some request parameters will be from the pre-swap response.

## Important Notes

{% hint style="info" %}

1. After obtaining the unsigned PSBT, the user must sign it within 30 seconds.
2. The `checksum` field should use the value from the previous request, even though the field name may differ.
3. Use the same address for both `btc_address` and `address`.
4. For `user_public_key`, provide the parameter as `public_key:public_key` for a wallet with one address, or `btc_public_key:ordi_public_key` for a wallet with two addresses.
   {% endhint %}

## POST /brc20swap/send\_swap\_psbt

> Send the signed PSBT for exchange

```json
{"openapi":"3.0.1","info":{"title":"Backend API","version":"1.0.0"},"servers":[{"url":"https://api-testnet4.dotswap.app","description":"Swap test"},{"url":"https://api.dotswap.app","description":"Swap official"}],"security":[],"paths":{"/brc20swap/send_swap_psbt":{"post":{"summary":"Send the signed PSBT for exchange","deprecated":false,"description":"","tags":[],"parameters":[],"requestBody":{"content":{"application/json":{"schema":{"type":"object","properties":{"order_id":{"type":"string","title":"Order ID"},"psbt":{"type":"string","title":"Signed PSBT"}},"required":["order_id","psbt"]}}}},"responses":{"200":{"description":"","content":{"application/json":{"schema":{"type":"object","properties":{"code":{"type":"integer"},"msg":{"type":"string"},"data":{"type":"object","properties":{"tx_id":{"type":"string","title":"The txid of the rawtx in PSBT"},"order_id":{"type":"string","title":"The corresponding order ID"},"need_show_task":{"type":"boolean"}},"required":["tx_id"]}},"required":["code","msg","data"]}}},"headers":{}}}}}}}
```

Finally, send the signed PSBT. If the response indicates success, the swap is successful.


---

# 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://docs.on.nexus/dotswap/developers/l1-swap-and-liquidity-apis/swap_v2/brc20.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.
