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
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 usedchainId: Chain ID where the transaction should be executedtransactionData: Main transaction data for the swapapproveData: Token approval transaction data (if required)swapDetails: Detailed information about the swaprawSwapData: Raw provider-specific swap datamessage: Success message
Example Response:
🔄 Swap Types
The endpoint automatically detects the swap type based on the quote:
Intra-chain Swap: When
quote.fromChainequalsquote.toChainCross-chain Swap: When
quote.fromChaindiffers fromquote.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
Get Quote: First, obtain a swap quote using the
GET /swap/quoteendpointExecute Swap: Use the quote in this endpoint to generate transaction data
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