Pact Swap

Compose swap transaction based on send amount


Composes a swap transaction based on the amount of source tokens you want to send. This endpoint queries available market maker orders, calculates the expected receive amount, and constructs a transaction that can be signed and broadcast to execute the swap. The transaction is composed for the source blockchain and includes all necessary parameters. For Bitcoin-like transactions (BTC, LTC, DOGE), you must provide UTXO information and a public key. The response includes the raw transaction data and optional EVM-specific fields (chainId, value, to, type) for EVM-compatible blockchains. The composed transaction can then be signed by the user's wallet and broadcast to the blockchain to execute the swap.

GET
/pactswap_cm/composeSwapTxByAmountFrom

Query Parameters

fromTypestring

The type of the source token blockchain. Used to determine the blockchain type for the source token (e.g., "btc", "eth", "usdc", "ltc", "doge"). This determines which blockchain the swap transaction will be created for.

Default"eth"
Value in"eth" | "btc" | "ltc" | "doge" | "bnb" | "pol" | "trx" | "usdt_trx" | "usdt_bnb" | "usdc_bnb" | "usd1_bnb" | "wbtc_bnb" | "usdt_eth" | "wbtc_eth" | "usdc_eth" | "usd1_eth" | "usdt_pol"
toTypestring

The type of the destination token blockchain. Used to determine the blockchain type for the destination token (e.g., "btc", "eth", "usdc", "ltc", "doge"). This determines which blockchain will receive the swapped tokens.

Default"btc"
Value in"eth" | "btc" | "ltc" | "doge" | "bnb" | "pol" | "trx" | "usdt_trx" | "usdt_bnb" | "usdc_bnb" | "usd1_bnb" | "wbtc_bnb" | "usdt_eth" | "wbtc_eth" | "usdc_eth" | "usd1_eth" | "usdt_pol"
toWalletAddressstring

The wallet address on the destination blockchain that will receive the swapped tokens. This should be a valid address for the destination blockchain type (e.g., Bitcoin address for BTC, Ethereum address for ETH).

fromPublicKey?string

The public key for the source wallet. Required only when fromType is "btc" (or other UTXO-based chains). This is used to construct the transaction for Bitcoin-like blockchains. Should be a hex string without 0x prefix.

fromWalletAddressstring

The wallet address on the source blockchain that will send the tokens. This should be a valid address for the source blockchain type (e.g., Bitcoin address for BTC, Ethereum address for ETH).

fromC1ContractIdstring

The C1 contract address for the source token. This is the L2 contract address of the C1 (consumer) contract that handles the source token in the swap.

fromC2ContractIdstring

The C2 contract address for the source token. This is the L2 contract address of the C2 (market maker) contract that handles the source token in the swap.

toC1ContractIdstring

The C1 contract address for the destination token. This is the L2 contract address of the C1 (consumer) contract that handles the destination token in the swap.

toC2ContractIdstring

The C2 contract address for the destination token. This is the L2 contract address of the C2 (market maker) contract that handles the destination token in the swap.

amountFromnumber

The amount of source tokens you want to send. This is specified in the smallest unit of the source token (e.g., satoshis for BTC, wei for ETH). The endpoint will calculate how much of the destination token you will receive and compose the transaction accordingly.

marketMaker?string

Optional filter to use a specific market maker for the swap. If provided, the swap will use orders from this market maker. The market maker is identified by their public key (hex string without 0x prefix).

utxos?string

JSON string containing UTXO information for Bitcoin-like transactions. Required only when fromType is "btc", "ltc", or "doge". Format: JSON array of objects with structure: [{txid: string, vout: number, value: number}, ...]. Each object represents an unspent transaction output that will be used to fund the swap.

backendUrl?string

Backend URL. Default is https://api-cloud.coinweb.io/wallet. This URL is used to query available market maker orders and compose the swap transaction.

Formaturi
presetnumber

Preset ID for swap configuration. This identifies a specific swap configuration preset that defines transaction parameters, routing preferences, or other swap settings. Different presets may have different fee structures, routing strategies, or execution parameters.

Response Body

curl -X GET "https://cwap-api.coinhq.store/pactswap_cm/composeSwapTxByAmountFrom?fromType=eth&toType=eth&toWalletAddress=string&fromPublicKey=020a89e0698443aaf4ecd613317d2fdf90ef73b99244182fc7bb3c6b85f375b876&fromWalletAddress=string&fromC1ContractId=0x6f20d1802288c90d2a044d3f7afae73fda261b27d85c0e01fdaaf3199b2c0e85&fromC2ContractId=0x6f20d1802288c90d2a044d3f7afae73fda261b27d85c0e01fdaaf3199b2c0e85&toC1ContractId=0x6f20d1802288c90d2a044d3f7afae73fda261b27d85c0e01fdaaf3199b2c0e85&toC2ContractId=0x6f20d1802288c90d2a044d3f7afae73fda261b27d85c0e01fdaaf3199b2c0e85&amountFrom=0&marketMaker=020a89e0698443aaf4ecd613317d2fdf90ef73b99244182fc7bb3c6b85f375b876&utxos=%5B%7B%22txid%22%3A%22a1075db55d416d3ca199f55b6084e2115b9345e16c5cf302fc80e9d5fbf5d48d%22%2C%22vout%22%3A0%2C%22value%22%3A50000000%7D%5D&backendUrl=https%3A%2F%2Fapi-cloud.coinweb.io%2Fwallet&preset=0"
{
  "rawTx": "0100000001...",
  "chainId": 1,
  "value": "0",
  "to": "0x6f20d1802288c90d2a044d3f7afae73fda261b27d85c0e01fdaaf3199b2c0e85",
  "type": "eip1559"
}

Was this documentation helpful? Any suggestions?