Skip to main content
POST
/
v2
/
earn
/
swap
Python (SDK)
from compass_api_sdk import CompassAPI, models


with CompassAPI(
    api_key_auth="<YOUR_API_KEY_HERE>",
) as compass_api:

    res = compass_api.earn.earn_swap(owner="0xC1be8f91480648De355a45f3E2562811b4e2D3FF", chain=models.Chain.BASE, token_in="USDC", token_out="USDT", amount_in="0.01", slippage="0.5", gas_sponsorship=False)

    # Handle response
    print(res)
{
  "transaction": {
    "chainId": "<string>",
    "data": "<string>",
    "from": "<string>",
    "gas": "<string>",
    "to": "<string>",
    "value": "<string>",
    "nonce": "<string>",
    "maxFeePerGas": "<string>",
    "maxPriorityFeePerGas": "<string>"
  },
  "eip_712": {
    "domain": {
      "chainId": 123,
      "verifyingContract": "<string>"
    },
    "types": {
      "EIP712Domain": [
        {
          "name": "<string>",
          "type": "<string>"
        }
      ],
      "SafeTx": [
        {
          "name": "<string>",
          "type": "<string>"
        }
      ]
    },
    "primaryType": "<string>",
    "message": {
      "to": "<string>",
      "value": "<string>",
      "data": "<string>",
      "operation": 0,
      "safeTxGas": "<string>",
      "baseGas": "<string>",
      "gasPrice": "<string>",
      "gasToken": "<string>",
      "refundReceiver": "<string>",
      "nonce": "<string>"
    }
  },
  "estimated_amount_out": "<string>"
}

Authorizations

x-api-key
string
header
required

Your Compass API Key. Get your key here.

Body

application/json
owner
string
required

The owner's wallet address.

chain
enum<string>
required

Target blockchain network where the swap will execute.

Available options:
base,
ethereum,
arbitrum
token_in
string
required

Token to sell (input). Provide a token symbol from a limited set (e.g., 'USDC') or any token address.

Examples:

"USDC"

"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"

token_out
string
required

Token to buy (output). Provide a token symbol from a limited set (e.g., 'USDT') or any token address.

Examples:

"USDT"

"0xdAC17F958D2ee523a2206206994597C13D831ec7"

amount_in
required

Human-readable amount of token_in to swap (token units, not wei).

Required range: x > 0
Examples:

1.5

slippage
required

Maximum slippage tolerance as a percentage (e.g., 0.5 = 0.5%).

Examples:

0.5

gas_sponsorship
boolean
default:false

Optionally request gas sponsorship. If true, EIP-712 typed data will be returned that must be signed by the owner and submitted to the 'Prepare gas-sponsored transaction' endpoint (/gas_sponsorship/prepare).

Response

Successful Response

transaction
object | null
required
eip_712
object | null
required

Response containing EIP-712 typed data for Safe transaction signing.

estimated_amount_out
string
required