BRC20

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

Get the tx size of the PSBT-based exchange

post
Body
send_coin_typestringRequired
send_tickstringRequired
send_amountstringRequired
receive_coin_typestringRequired
receive_tickstringRequired
receive_amountstringRequired
addressstringRequired
slipperstringRequired
fee_rateintegerRequired
insstring[]Required

Only needed when exchanging with BRC20

methodstringRequired

Non-cross-pool swap, cross-pool pools_swap, just pass 'pools_swap'

Responses
200Success
application/json
post
POST /brc20swap/get_swap_psbt_txsize HTTP/1.1
Host: test-api-proxy.ddpurse.com
Content-Type: application/json
Accept: */*
Content-Length: 216

{
  "send_coin_type": "text",
  "send_tick": "text",
  "send_amount": "text",
  "receive_coin_type": "text",
  "receive_tick": "text",
  "receive_amount": "text",
  "address": "text",
  "slipper": "text",
  "fee_rate": 1,
  "ins": [
    "text"
  ],
  "method": "text"
}
{
  "code": 1,
  "msg": "text",
  "data": {
    "tx_size": 1,
    "ins_contain_sats": 1,
    "checksum": "text",
    "vins": [
      "text"
    ],
    "usr_cnt": 1
  }
}

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

Get the unsigned PSBT for BRC20 exchange

post
Body
send_coin_typestringRequired
send_tickstringRequired
send_amountstringRequired
receive_coin_typestringRequired
receive_tickstringRequired
receive_amountstringRequired
addressstringRequired
slipperstringRequired
fee_rateintegerRequired
insstring[]Required

Only needed when exchanging with BRC20

user_public_keystringRequired
tx_sizeintegerRequired

Obtained from the get_swap_psbt_txsize interface

checksumintegerRequired

Obtained from the get_swap_psbt_txsize interface

vinsstring[]Required

Obtained from the get_swap_psbt_txsize interface

usr_cntintegerRequired

Obtained from the get_swap_psbt_txsize interface

chlstringRequired
methodstringRequired

Non-cross-pool swap, cross-pool pools_swap, just pass 'pools_swap'

Responses
200Success
application/json
post
POST /brc20swap/get_swap_psbt HTTP/1.1
Host: test-api-proxy.ddpurse.com
Content-Type: application/json
Accept: */*
Content-Length: 307

{
  "send_coin_type": "text",
  "send_tick": "text",
  "send_amount": "text",
  "receive_coin_type": "text",
  "receive_tick": "text",
  "receive_amount": "text",
  "address": "text",
  "slipper": "text",
  "fee_rate": 1,
  "ins": [
    "text"
  ],
  "user_public_key": "text",
  "tx_size": 1,
  "checksum": 1,
  "vins": [
    "text"
  ],
  "usr_cnt": 1,
  "chl": "text",
  "method": "text"
}
{
  "code": 1,
  "msg": "text",
  "data": {
    "order_id": "text",
    "psbt": "text",
    "check_sign_only": true
  }
}

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

Important Notes

  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.

Send the signed PSBT for exchange

post
Body
order_idstringRequired
psbtstringRequired
Responses
200Success
application/json
post
POST /brc20swap/send_swap_psbt HTTP/1.1
Host: test-api-proxy.ddpurse.com
Content-Type: application/json
Accept: */*
Content-Length: 1763

{
  "order_id": "swap_1072414914196275200",
  "psbt": "70736274ff0100fde401020000000663ba1a2fc81c71432bc99286b6b9e0c2607f5f9eb4b9a3f851bb83ef93d0c6530100000000fffffffffc20c54d42ccd93abc7c4d1f15c988d940b635d62222e230246bacc0239f73ef0500000000fffffffffc20c54d42ccd93abc7c4d1f15c988d940b635d62222e230246bacc0239f73ef0200000000fffffffffc20c54d42ccd93abc7c4d1f15c988d940b635d62222e230246bacc0239f73ef0100000000fffffffffc20c54d42ccd93abc7c4d1f15c988d940b635d62222e230246bacc0239f73ef0400000000fffffffffc20c54d42ccd93abc7c4d1f15c988d940b635d62222e230246bacc0239f73ef0300000000ffffffff074a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa1274a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa1274a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa1274a01000000000000160014464ef3759fcfb1eb3d76f3319ef58ec20301c6580000000000000000156a5d1200b29a040df246030000b402010000b40202c88b01000000000022512006161a3f67a1c67b1a39550c0e6c156852f22e9c9bfc67aa951010a27cdc324a456c370000000000160014464ef3759fcfb1eb3d76f3319ef58ec20301c658000000000001011fd0fb380000000000160014464ef3759fcfb1eb3d76f3319ef58ec20301c65801086b0247304402200fad011f732edb4c2cf77c079e3603adfe0ca9376a47475c5f348b5f3bee4dce02201506df6edce6a06096b8d9a120993a6be987b16216543ae00d98af03f9b8278f012102d3ac7452920b1cc4653516dd4f4381a2df0a8c0aac6e3446e633a73ea63eee810001011f4a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa127010304010000000001011f4a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa127010304010000000001011f4a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa127010304010000000001011f4a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa127010304010000000001011f4a01000000000000160014018960754f34943aa8ffa8cccdc56e1a875fa127010304010000000000000000000000"
}
{
  "code": 0,
  "msg": "",
  "data": {
    "tx_id": "045c00db3b398896756077f344de8893861788e26b6c3ee6e650e21eb2569524"
  },
  "req_id": "1887761723174592512"
}

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

Last updated

Was this helpful?