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:
{
"type": "intra-chain-evm",
"provider": "1inch",
"chainId": "polygon",
"transactionData": {
"to": "0x111111125421ca6dc452d289314280a0f8842a65",
"data": "0x07ed23790000000000000000000000001380f2f57553ada04b31ee7b1e039e496939db3d000000000000000000000000b5c064f955d8e7f38fe0460c556a72987494ee170000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c33590000000000000000000000001380f2f57553ada04b31ee7b1e039e496939db3d000000000000000000000000dae3a7024062ddfd36e636310e277b1c45461fea0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000005a710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001620000000000000000000000000000000000000000000001440000dd00004e00a0744c8c09b5c064f955d8e7f38fe0460c556a72987494ee1790cbe4bdd538d6e9b379bff5fe72c3d67a521de5000000000000000000000000000000000000000000000000000aa87bee5380000c20b5c064f955d8e7f38fe0460c556a72987494ee17f3eb2f17eafbf35e92c965a954c6e7693187057d6ae4071138002dc6c0f3eb2f17eafbf35e92c965a954c6e7693187057d6d9e8dbb2779853db00418d4dcf96f3987cfc9d200000000000000000000000000000000000000000000000001c5ba2299a3bbe1b5c064f955d8e7f38fe0460c556a72987494ee1700206ae40711b8002dc6c06d9e8dbb2779853db00418d4dcf96f3987cfc9d2111111125421ca6dc452d289314280a0f8842a650000000000000000000000000000000000000000000000000000000000005a710d500b1d8e8ef31e21c99d1db9a6444d3adf1270000000000000000000000000000000000000000000000000000000000000bffdec3c",
"value": "0",
"gasLimit": null
},
"approveData": {
"to": "0xb5c064f955d8e7f38fe0460c556a72987494ee17",
"data": "0x095ea7b3000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000d3c21bcecceda1000000",
"value": "0"
},
"swapDetails": {
"fromChain": "polygon",
"toChain": "polygon",
"fromToken": {
"contract": "0xb5c064f955d8e7f38fe0460c556a72987494ee17",
"symbol": "QUICK",
"decimals": 18,
"amount": "1000000000000000000",
"chainId": 137
},
"toToken": {
"contract": "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
"symbol": "USDC",
"decimals": 6,
"amount": "23315",
"chainId": 137
},
"effectiveAmountIn": "1000000000000000000",
"expectedAmountOut": "23315",
"destinationAddress": "0xdae3A7024062DdFD36e636310e277b1c45461Fea"
},
"rawSwapData": {
"dstAmount": "23387",
"tx": {
"from": "0xdae3a7024062ddfd36e636310e277b1c45461fea",
"to": "0x111111125421ca6dc452d289314280a0f8842a65",
"data": "0x07ed23790000000000000000000000001380f2f57553ada04b31ee7b1e039e496939db3d000000000000000000000000b5c064f955d8e7f38fe0460c556a72987494ee170000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c33590000000000000000000000001380f2f57553ada04b31ee7b1e039e496939db3d000000000000000000000000dae3a7024062ddfd36e636310e277b1c45461fea0000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000005a710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001620000000000000000000000000000000000000000000001440000dd00004e00a0744c8c09b5c064f955d8e7f38fe0460c556a72987494ee1790cbe4bdd538d6e9b379bff5fe72c3d67a521de5000000000000000000000000000000000000000000000000000aa87bee5380000c20b5c064f955d8e7f38fe0460c556a72987494ee17f3eb2f17eafbf35e92c965a954c6e7693187057d6ae4071138002dc6c0f3eb2f17eafbf35e92c965a954c6e7693187057d6d9e8dbb2779853db00418d4dcf96f3987cfc9d200000000000000000000000000000000000000000000000001c5ba2299a3bbe1b5c064f955d8e7f38fe0460c556a72987494ee1700206ae40711b8002dc6c06d9e8dbb2779853db00418d4dcf96f3987cfc9d2111111125421ca6dc452d289314280a0f8842a650000000000000000000000000000000000000000000000000000000000005a710d500b1d8e8ef31e21c99d1db9a6444d3adf1270000000000000000000000000000000000000000000000000000000000000bffdec3c",
"value": "0",
"gas": 0,
"gasPrice": "130000000025"
}
},
"message": "Dados da transaΓ§Γ£o preparados."
}
π Swap Types
The endpoint automatically detects the swap type based on the quote:
Intra-chain Swap: When
quote.fromChain
equalsquote.toChain
Cross-chain Swap: When
quote.fromChain
differs 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:
{
"error": "Invalid quote provided. Quote must include provider information."
}
π Usage Examples
Execute Intra-chain Swap:
POST /swap/bytecode
{
"destinationAddress": "0x1234567890123456789012345678901234567890",
"quote": {
"fromChain": {
"chainId": "1",
"name": "Ethereum"
},
"toChain": {
"chainId": "1",
"name": "Ethereum"
},
"expectedAmountOut": "1000000000000000000",
"provider": "1inch",
"tokenIn": "0xA0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
"tokenOut": "0xB0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
"amountIn": "500000000000000000"
},
"walletAddress": "0x1234567890123456789012345678901234567890",
"decimalsIn": 18
}
Execute Cross-chain Swap:
POST /swap/bytecode
{
"destinationAddress": "0x1234567890123456789012345678901234567890",
"quote": {
"fromChain": {
"chainId": "1",
"name": "Ethereum"
},
"toChain": {
"chainId": "137",
"name": "Polygon"
},
"expectedAmountOut": "1000000000000000000",
"provider": "socket",
"tokenIn": "0xA0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
"tokenOut": "0xB0b86a33E6441b8c4C8C1C1B8c4C8C1C1B8c4C8C1",
"amountIn": "500000000000000000"
}
}
π Workflow
Get Quote: First, obtain a swap quote using the
GET /swap/quote
endpointExecute 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