Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.deframe.io/llms.txt

Use this file to discover all available pages before exploring further.

In this section, you’ll learn how to execute a token swap using the transaction data generated from a previously obtained quote.
Prerequisites: Complete the Get a Quote guide first to obtain a valid quote.

Overview

After obtaining a quote, you can execute the swap by generating the necessary transaction data (bytecode) and submitting it to the blockchain. The Deframe API handles the complexity of preparing the transaction data for different providers and swap types.
Trustless Operation: You sign and submit all transactions yourself. Deframe never has custody of your funds.

Executing a Swap

Endpoint

POST /v2/swap/bytecode

Request Body

ParameterTypeRequiredDescription
quoteIdstringThe quote ID returned by GET /v2/swap/quote
originAddressstringThe wallet address that will sign and send the transaction
destinationAddressstringThe destination wallet address to receive the swapped tokens. For cross-chain swaps, this address is used as the receiverAddress on the destination chain.
rawQuoteanyOptionalProvider-specific quote data from the quote response. Only present for certain bridge providers; pass it when the quote response includes it.

Example Request

curl --request POST \
  --url https://api.deframe.io/v2/swap/bytecode \
  --header 'Content-Type: application/json' \
  --header 'x-api-key: YOUR_API_KEY' \
  --data '{
    "quoteId": "550e8400-e29b-41d4-a716-446655440000",
    "originAddress": "0x1234567890123456789012345678901234567890",
    "destinationAddress": "0x1234567890123456789012345678901234567890",
    "rawQuote": "..."
  }'

Response Format

The API returns transaction data ready to be signed and executed:
{
  "id": "65f1a2b3c4d5e6f789012345",
  "chainId": 137,
  "transactionData": [
    {
      "to": "0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174",
      "data": "0x095ea7b3000000000000000000000000111111125421ca6dc452d289314280a0f8842a6500000000000000000000000000000000000000000000000000000000000f4240",
      "value": "0",
      "chainId": 137
    },
    {
      "to": "0x111111125421ca6dc452d289314280a0f8842a65",
      "data": "0x07ed2379...",
      "value": "0",
      "chainId": 137
    }
  ]
}

Response Fields

ID created for execution tracking. Use this ID with GET /actions/{id} when you need execution status after transactions are submitted.
The chain ID where these transactions should be executed
EVM routes return an array of transactions to execute in order. Solana routes return provider-specific transaction data with a rawTransaction payload. EVM transaction arrays may include:
  • Approval transaction: Grants permission to the swap contract
  • Swap transaction: Executes the actual token swap
  • Tracking transaction: Records the swap in Deframe’s system
The contract address to send the transaction to
Encoded transaction data (bytecode) for the contract call
Amount of native token to send (in wei). Usually “0” unless swapping native tokens.
quoteId and id identify different resources. quoteId tracks the saved swap quote and is the {id} for GET /v2/swap/status/{id}. The id returned by this endpoint is used for execution tracking.

Transaction Execution

You’ll need to sign and submit the transaction data to the blockchain. This happens on your end - we don’t touch your funds, custody remains yours.

Using ethers.js

import { ethers } from 'ethers'

// 1. Create a provider and signer (ethers v6)
const provider = new ethers.BrowserProvider(window.ethereum)
const signer = await provider.getSigner()

// 2. Execute transactions in order
for (const tx of response.transactionData) {
  const transaction = await signer.sendTransaction({
    to: tx.to,
    data: tx.data,
    value: tx.value,
    chainId: tx.chainId
  })

  // Wait for confirmation
  await transaction.wait()
  console.log(`Transaction confirmed: ${transaction.hash}`)
}

Using wagmi/viem

import { useSendTransaction, useWaitForTransaction } from 'wagmi'

function SwapComponent() {
  const { sendTransaction } = useSendTransaction()

  const executeSwap = async (bytecode) => {
    for (const tx of bytecode.transactionData) {
      const { hash } = await sendTransaction({
        to: tx.to,
        data: tx.data,
        value: BigInt(tx.value),
        chainId: tx.chainId
      })

      console.log(`Transaction sent: ${hash}`)
    }
  }

  return <button onClick={() => executeSwap(response)}>Execute Swap</button>
}

Swap Types

The endpoint automatically handles different swap types:
Same-chain swaps (e.g., USDT to USDC on Ethereum):
  • Usually 2-3 transactions: approve + swap (+ tracking)
  • Executes immediately on the same blockchain
  • Lower fees, faster execution

Error Handling

The API returns appropriate error messages for:
  • Missing required parameters
  • Invalid or expired quote
  • Quote not found or already used
  • Provider-specific errors during transaction preparation
Example Error Response:
{
  "error": {
    "code": "QUOTE_NOT_FOUND",
    "message": "Quote not found or expired",
    "httpStatus": 404,
    "details": null
  }
}
Always check that the quote hasn’t expired before executing. Quotes are typically valid for 5 minutes.

Complete Workflow

1

Get Quote

Use GET /v2/swap/quote to get swap quote and pricing
2

Generate Bytecode

Use POST /v2/swap/bytecode with the quote to generate transaction data. Save the returned id.
3

Execute Transactions

Sign and send the transactions using your wallet
4

Track Status

For cross-chain swaps, use GET /v2/swap/status/{quoteId} to monitor quote progress.Pass the quoteId returned in step 1 as the {quoteId} path parameter. Use the id returned in step 2 with GET /actions/{id} when you need execution status.

Next Steps

Get Another Quote

Start a new swap

Check Status

Track cross-chain swap progress

Code Examples

View complete implementation examples