POST /swap/bytecode

🔹 Execute Swap Transaction

🌐 Endpoint

POST https://client.deframe.io/v1/swap/bytecode

📝 Overview

Execute a token swap transaction by generating the necessary transaction data (bytecode) based on a previously obtained quote. This endpoint takes a swap quote and prepares the transaction data required to execute the swap on the blockchain.

🔑 Authentication

This API requires authentication using an API key. Include your API key in the request headers:

x-api-key: YOUR_API_KEY

📋 Request Body

Parameter
Type
Required
Description

destinationAddress

string

The destination wallet address to receive the swapped tokens

quote

object

The quote object obtained from the /swap/quote endpoint

walletAddress

string

User's wallet address for provider-specific logic

decimalsIn

number

Number of decimals for the input token

📦 Response

Returns a JSON object containing comprehensive transaction data:

  • type: Type of swap (e.g., "intra-chain-evm")

  • provider: Name of the swap provider used

  • chainId: Chain ID where the transaction should be executed

  • transactionData: Main transaction data for the swap

  • approveData: Token approval transaction data (if required)

  • swapDetails: Detailed information about the swap

  • rawSwapData: Raw provider-specific swap data

  • message: Success message

Example Response:

🔄 Swap Types

The endpoint automatically detects the swap type based on the quote:

  • Intra-chain Swap: When quote.fromChain equals quote.toChain

  • Cross-chain Swap: When quote.fromChain differs from quote.toChain

🛠️ Error Handling

The API returns appropriate error messages for:

  • Missing required parameters

  • Invalid quote object (missing provider information)

  • Provider not found for the specified quote

  • Provider-specific errors during transaction preparation

Example Error Response:

📝 Usage Examples

Execute Intra-chain Swap:

Execute Cross-chain Swap:

🔗 Workflow

  1. Get Quote: First, obtain a swap quote using the GET /swap/quote endpoint

  2. Execute Swap: Use the quote in this endpoint to generate transaction data

  3. Submit Transaction: Use the returned transaction data to execute the swap on the blockchain

📋 Response Fields Details

  • transactionData: Contains the main swap transaction data (to, data, value, gasLimit)

  • approveData: Contains token approval transaction data if the token needs to be approved first

  • swapDetails: Detailed information about the swap including token details and amounts

  • rawSwapData: Raw provider-specific data including the complete transaction object

Last updated