Creation of a cross-chain exchange

The method allows you to create a cross-chain exchange. Cross-chain exchange allows you to exchange one asset for another

Creation of a cross-chain exchange

POSThttps://ocp.onchainpay.io/api-gateway/swaps/create
Header parameters
Body
advancedBalanceId*string

Identifier of the upfront balance specified when creating the commission token

Example: "1503cf18-597f-447f-b172-112dfe377e1b"
clientIdstring

Unique exchange identifier in the merchant system (to prevent duplicate requests)

Example: "merchant_unique_id"
addressFromId*string

Identifier of the outgoing address from which the specified amount will be debited

Example: "42a54680-0511-4aa0-ba46-5cf1b7de1fd3"
addressToId*string

Identifier of the destination address where the coins will be credited after the swap

Example: "3ee40864-55ea-4c9e-bf28-5fd61cce4334"
feeToken*string

Commission Token

Example: "U2FsdGVkX1+50eNroHexE3RVIJPCwFGVzDjn5Vd2KFXufep4UlF6TeNv0Ef31oVz7ViIZpwdGwZa1aClSH2zG5b8qwWtFKHH6kzwwGkx0LObMCz/LYoudvKlmjReNqj6GppdgQUhppFS3sOIQJ8q+x88zxybJO99Y4o3ApIWyqEne0bggCsjqmywf10LCDKO/cXcb9KRV6TudjhSdx8/jQ=="
webhookUrlstring

URL address for notifying about the change in the status of the swap operation

Example: "https://merchant.domain/webhooks/swap"
Response
Body
success*boolean

Request success indicator

response*SwapResponse (object)

The body of the response to the request for obtaining data from the swap

Request
const response = await fetch('https://ocp.onchainpay.io/api-gateway/swaps/create', {
    method: 'POST',
    headers: {
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      "advancedBalanceId": "1503cf18-597f-447f-b172-112dfe377e1b",
      "addressFromId": "42a54680-0511-4aa0-ba46-5cf1b7de1fd3",
      "addressToId": "3ee40864-55ea-4c9e-bf28-5fd61cce4334",
      "feeToken": "U2FsdGVkX1+50eNroHexE3RVIJPCwFGVzDjn5Vd2KFXufep4UlF6TeNv0Ef31oVz7ViIZpwdGwZa1aClSH2zG5b8qwWtFKHH6kzwwGkx0LObMCz/LYoudvKlmjReNqj6GppdgQUhppFS3sOIQJ8q+x88zxybJO99Y4o3ApIWyqEne0bggCsjqmywf10LCDKO/cXcb9KRV6TudjhSdx8/jQ=="
    }),
});
const data = await response.json();
Response
{
  "success": false,
  "response": {
    "id": "2e4014b2-8549-4caa-b8c8-b699b807313c",
    "clientId": "merchant_unique_id",
    "advancedBalanceId": "1503cf18-597f-447f-b172-112dfe377e1b",
    "addressFromId": "42a54680-0511-4aa0-ba46-5cf1b7de1fd3",
    "addressToId": "3ee40864-55ea-4c9e-bf28-5fd61cce4334",
    "currencyFrom": "USDT",
    "currencyTo": "USDC",
    "networkFrom": "ethereum",
    "networkTo": "tron",
    "status": "PENDING",
    "rejectMessage": "null",
    "amountFrom": "200",
    "amountTo": "200",
    "price": "1",
    "serviceBlockchainFeeSource": "ADVANCE",
    "serviceBlockchainFee": "2",
    "serviceBlockchainFeeUSD": "2",
    "providerBlockchainFeeSource": "AMOUNT",
    "providerBlockchainFee": "2",
    "providerBlockchainFeeUSD": "2",
    "serviceFeeSource": "ADVANCE",
    "serviceFee": "2",
    "serviceFeeUSD": "2",
    "webhookUrl": "https://merchant.domain/webhooks/swap",
    "createdAt": "2024-12-26T08:21:33.218Z"
  }
}

Last updated