> ## Documentation Index
> Fetch the complete documentation index at: https://docs.compasslabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Transfer tokens to/from account

> Transfer tokens between an owner's wallet and their Earn Account.

Use `DEPOSIT` to move tokens from the owner's wallet into their Earn Account. Use `WITHDRAW` to move tokens from the Earn Account back to the owner's wallet.

**Gas-sponsored deposits** require two steps:

**Step 1 (once per token):** Set up Permit2 allowance
1. Call [/gas_sponsorship/approve_transfer](https://docs.compasslabs.ai/v2/api-reference/gas-sponsorship/approve-token-transfer) to get EIP-712 typed data
2. Owner signs the typed data
3. Submit signature + typed data to [/gas_sponsorship/prepare](https://docs.compasslabs.ai/v2/api-reference/gas-sponsorship/prepare-gas-sponsored-transaction)

**Step 2 (each transfer):** Execute the gas-sponsored transfer
1. Call this endpoint with `gas_sponsorship=true` to get EIP-712 typed data
2. Owner signs the typed data
3. Submit signature + typed data to [/gas_sponsorship/prepare](https://docs.compasslabs.ai/v2/api-reference/gas-sponsorship/prepare-gas-sponsored-transaction)

**Note:** This endpoint moves tokens to/from the Earn Account itself—not into yield venues. To deposit into a vault or Aave market, use the [manage endpoint](https://docs.compasslabs.ai/v2/api-reference/earn/manage-earn-position).



## OpenAPI

````yaml /v2/combined_spec.json post /v2/earn/transfer
openapi: 3.1.0
info:
  title: Compass API
  description: Compass Labs DeFi API
  version: 0.0.1
servers:
  - url: https://api.compasslabs.ai
    description: Production server
security:
  - ApiKeyAuth: []
paths:
  /v2/earn/transfer:
    post:
      tags:
        - Earn
      summary: Transfer tokens to/from account
      description: >-
        Transfer tokens between an owner's wallet and their Earn Account.


        Use `DEPOSIT` to move tokens from the owner's wallet into their Earn
        Account. Use `WITHDRAW` to move tokens from the Earn Account back to the
        owner's wallet.


        **Gas-sponsored deposits** require two steps:


        **Step 1 (once per token):** Set up Permit2 allowance

        1. Call
        [/gas_sponsorship/approve_transfer](https://docs.compasslabs.ai/v2/api-reference/gas-sponsorship/approve-token-transfer)
        to get EIP-712 typed data

        2. Owner signs the typed data

        3. Submit signature + typed data to
        [/gas_sponsorship/prepare](https://docs.compasslabs.ai/v2/api-reference/gas-sponsorship/prepare-gas-sponsored-transaction)


        **Step 2 (each transfer):** Execute the gas-sponsored transfer

        1. Call this endpoint with `gas_sponsorship=true` to get EIP-712 typed
        data

        2. Owner signs the typed data

        3. Submit signature + typed data to
        [/gas_sponsorship/prepare](https://docs.compasslabs.ai/v2/api-reference/gas-sponsorship/prepare-gas-sponsored-transaction)


        **Note:** This endpoint moves tokens to/from the Earn Account itself—not
        into yield venues. To deposit into a vault or Aave market, use the
        [manage
        endpoint](https://docs.compasslabs.ai/v2/api-reference/earn/manage-earn-position).
      operationId: v2_earn_transfer
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EarnTransferRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EarnTransferResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: python
          label: Python (SDK)
          source: |-
            from compass_api_sdk import CompassAPI, models


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

                res = compass_api.earn.earn_transfer(owner="0x06A9aF046187895AcFc7258450B15397CAc67400", chain=models.Chain.BASE, token="USDC", amount="0.01", action=models.EarnTransferRequestAction.DEPOSIT, gas_sponsorship=False)

                # Handle response
                print(res)
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { CompassApiSDK } from "@compass-labs/api-sdk";

            const compassApiSDK = new CompassApiSDK({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await compassApiSDK.earn.earnTransfer({
                owner: "0x06A9aF046187895AcFc7258450B15397CAc67400",
                chain: "base",
                token: "USDC",
                amount: "0.01",
                action: "DEPOSIT",
              });

              console.log(result);
            }

            run();
components:
  schemas:
    EarnTransferRequest:
      properties:
        owner:
          type: string
          title: Owner
          description: The owner's wallet address.
          default: '0x06A9aF046187895AcFc7258450B15397CAc67400'
          examples:
            - '0x06A9aF046187895AcFc7258450B15397CAc67400'
        chain:
          $ref: '#/components/schemas/Chain'
          description: Blockchain network
          default: base
          examples:
            - base
        token:
          type: string
          title: Token
          description: The token you would like to transfer.
          examples:
            - USDC
            - WETH
            - '0xA0b86a33E6441ccF30EE5DdEF1E9b652C91ac1c8'
          default: USDC
        amount:
          anyOf:
            - type: number
              exclusiveMinimum: 0
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
          title: Amount
          description: The amount of 'token' to transfer.
          examples:
            - 1.5
          default: '0.01'
        action:
          type: string
          enum:
            - DEPOSIT
            - WITHDRAW
          title: Action
          description: Whether you are depositing to or withdrawing from your earn account.
          default: DEPOSIT
          examples:
            - DEPOSIT
        gas_sponsorship:
          type: boolean
          title: Gas Sponsorship
          description: >-
            Optionally request gas sponsorship. If set to `true`, EIP-712
            signature data will be returned that must be signed by the `owner`
            and submitted to the `/gas_sponsorship/prepare` endpoint.
          default: false
        spender:
          anyOf:
            - type: string
            - type: 'null'
          title: Spender
          description: >-
            The address that will call Permit2's permitTransferFrom to execute
            the transfer. When `action` is 'DEPOSIT' and `gas_sponsorship` is
            `true`: - If provided, the signature will authorize this address
            (typically a gas sponsor) to pull tokens. - If not provided,
            defaults to the Earn Account (Safe) address, allowing the transfer
            to be included in a bundle transaction where the Safe pulls the
            tokens itself.
        recipient:
          anyOf:
            - type: string
            - type: 'null'
          title: Recipient
          description: >-
            Optional recipient address for withdrawals. When `action` is
            'WITHDRAW': - If provided, tokens will be sent to this address
            instead of the owner. - If not provided, defaults to the owner's
            address. 
      type: object
      required:
        - owner
        - chain
        - token
        - amount
        - action
      title: EarnTransferRequest
      default:
        owner: '0x06A9aF046187895AcFc7258450B15397CAc67400'
        chain: base
        token: USDC
        amount: '0.01'
        action: DEPOSIT
    EarnTransferResponse:
      properties:
        transaction:
          anyOf:
            - $ref: '#/components/schemas/UnsignedTransaction'
            - type: 'null'
          description: >-
            Unsigned transaction for direct execution. Present when
            gas_sponsorship=false.
        eip_712:
          anyOf:
            - $ref: '#/components/schemas/BatchedSafeOperationsResponse-Output'
            - $ref: '#/components/schemas/Permit2TypedData-Output'
            - type: 'null'
          title: Eip 712
          description: >-
            EIP-712 typed data for gas-sponsored execution. Present when
            gas_sponsorship=true.
      type: object
      title: EarnTransferResponse
      example:
        transaction:
          chainId: '0x2105'
          data: >-
            0xa9059cbb0000000000000000000000006b90e8b4e3e971e74c1a47a3a20976377e2db4b10000000000000000000000000000000000000000000000000000000005f5e100
          from: '0x4A83b4413CF41C3244027e1590E35a0F48403F0c'
          gas: '0x5208'
          maxFeePerGas: '0x59682f00'
          maxPriorityFeePerGas: '0x3b9aca00'
          nonce: '0x5'
          to: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
          value: '0x0'
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    Chain:
      type: string
      enum:
        - base
        - ethereum
        - arbitrum
        - hyperevm
        - tempo
      title: Chain
      description: The chain to use.
    UnsignedTransaction:
      properties:
        chainId:
          type: string
          title: Chainid
          description: The chain id of the transaction
        data:
          type: string
          title: Data
          description: The data of the transaction
        from:
          type: string
          title: From
          description: The sender of the transaction
        gas:
          anyOf:
            - type: string
            - type: 'null'
          title: Gas
          description: The gas of the transaction
        to:
          type: string
          title: To
          description: The recipient of the transaction
        value:
          type: string
          title: Value
          description: The value of the transaction
        nonce:
          type: string
          title: Nonce
          description: The nonce of the address
        maxFeePerGas:
          type: string
          title: Maxfeepergas
          description: The max fee per gas of the transaction
        maxPriorityFeePerGas:
          type: string
          title: Maxpriorityfeepergas
          description: The max priority fee per gas of the transaction
      type: object
      required:
        - chainId
        - data
        - from
        - gas
        - to
        - value
        - nonce
        - maxFeePerGas
        - maxPriorityFeePerGas
      title: UnsignedTransaction
      example:
        chainId: '0x2105'
        data: >-
          0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d
        from: '0x4A83b4413CF41C3244027e1590E35a0F48403F0c'
        gas: '0x7a120'
        maxFeePerGas: '0x59682f00'
        maxPriorityFeePerGas: '0x3b9aca00'
        nonce: '0x5'
        to: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67'
        value: '0x0'
    BatchedSafeOperationsResponse-Output:
      properties:
        domain:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Domain
          description: EIP-712 domain separator
        types:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Types
          description: EIP-712 type definitions
        primaryType:
          type: string
          const: SafeTx
          title: Primarytype
          description: Primary type for the structured data
        message:
          $ref: '#/components/schemas/SafeTxMessage'
          description: Safe transaction message data
      type: object
      required:
        - domain
        - types
        - primaryType
        - message
      title: BatchedSafeOperationsResponse
      description: Response containing EIP-712 typed data for Safe transaction signing.
      example:
        domain:
          chainId: 8453
          verifyingContract: '0x6B90E8B4E3E971E74C1A47a3a20976377E2dB4b1'
        message:
          baseGas: '0'
          data: >-
            0x8d80ff0a0000000000000000000000000000000000000000000000000000000000000020
          gasPrice: '0'
          gasToken: '0x0000000000000000000000000000000000000000'
          nonce: '7'
          operation: 1
          refundReceiver: '0x0000000000000000000000000000000000000000'
          safeTxGas: '0'
          to: '0x93C23AAE4793C14D6DF35D2A2A2234204e1559dA'
          value: '0'
        primaryType: SafeTx
        types:
          EIP712Domain:
            - name: chainId
              type: uint256
            - name: verifyingContract
              type: address
          SafeTx:
            - name: to
              type: address
            - name: value
              type: uint256
            - name: data
              type: bytes
            - name: operation
              type: uint8
            - name: safeTxGas
              type: uint256
            - name: baseGas
              type: uint256
            - name: gasPrice
              type: uint256
            - name: gasToken
              type: address
            - name: refundReceiver
              type: address
            - name: nonce
              type: uint256
    Permit2TypedData-Output:
      properties:
        types:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__gas_sponsorship__permit_2_typed_data__EIP712Types
          description: All type definitions
        primaryType:
          type: string
          const: PermitTransferFrom
          title: Primarytype
          description: Root type for signing
          default: PermitTransferFrom
        domain:
          $ref: >-
            #/components/schemas/compass__api_backend__v2__models__gas_sponsorship__permit_2_typed_data__EIP712Domain
          description: EIP-712 domain separator
        message:
          $ref: '#/components/schemas/PermitTransferFromMessage'
          description: The permit data to sign
      type: object
      required:
        - types
        - domain
        - message
      title: Permit2TypedData
      example:
        domain:
          chainId: 8453
          name: Permit2
          verifyingContract: '0x000000000022D473030F116dDEE9F6B43aC78BA3'
        message:
          deadline: 1735689600
          nonce: 0
          permitted:
            amount: 100000000
            token: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
          spender: '0x6B90E8B4E3E971E74C1A47a3a20976377E2dB4b1'
        primaryType: PermitTransferFrom
        types:
          EIP712Domain:
            - name: name
              type: string
            - name: chainId
              type: uint256
            - name: verifyingContract
              type: address
          PermitTransferFrom:
            - name: permitted
              type: TokenPermissions
            - name: spender
              type: address
            - name: nonce
              type: uint256
            - name: deadline
              type: uint256
          TokenPermissions:
            - name: token
              type: address
            - name: amount
              type: uint256
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Domain:
      properties:
        chainId:
          type: integer
          title: Chainid
          description: Chain ID
        verifyingContract:
          type: string
          title: Verifyingcontract
          description: Address of the Product Account
      type: object
      required:
        - chainId
        - verifyingContract
      title: EIP712Domain
      description: The EIP-712 domain separator.
    compass__api_backend__v2__models__safe__transact__response__batched_safe_operations__EIP712Types:
      properties:
        EIP712Domain:
          items:
            $ref: '#/components/schemas/EIP712DomainField'
          type: array
          title: Eip712Domain
          description: EIP712Domain type definition
        SafeTx:
          items:
            $ref: '#/components/schemas/SafeTxField'
          type: array
          title: Safetx
          description: SafeTx type definition
      type: object
      required:
        - EIP712Domain
        - SafeTx
      title: EIP712Types
      description: The type definitions for EIP-712 structured data.
    SafeTxMessage:
      properties:
        to:
          type: string
          title: To
          description: Destination address
        value:
          type: string
          title: Value
          description: Value in wei as a string
        data:
          type: string
          title: Data
          description: Transaction data as hex string
        operation:
          $ref: '#/components/schemas/OperationType'
          description: Operation type (0=Call, 1=DelegateCall)
        safeTxGas:
          type: string
          title: Safetxgas
          description: Gas for the transaction
        baseGas:
          type: string
          title: Basegas
          description: Base gas costs
        gasPrice:
          type: string
          title: Gasprice
          description: Gas price
        gasToken:
          type: string
          title: Gastoken
          description: Token address for gas payment
        refundReceiver:
          type: string
          title: Refundreceiver
          description: Address to receive gas refund
        nonce:
          type: string
          title: Nonce
          description: Transaction nonce
      type: object
      required:
        - to
        - value
        - data
        - operation
        - safeTxGas
        - baseGas
        - gasPrice
        - gasToken
        - refundReceiver
        - nonce
      title: SafeTxMessage
      description: The message data for the transaction.
    compass__api_backend__v2__models__gas_sponsorship__permit_2_typed_data__EIP712Types:
      properties:
        EIP712Domain:
          items:
            $ref: '#/components/schemas/EIP712Field'
          type: array
          title: Eip712Domain
          description: Standard EIP-712 domain type
          default:
            - name: name
              type: string
            - name: chainId
              type: uint256
            - name: verifyingContract
              type: address
        TokenPermissions:
          items:
            $ref: '#/components/schemas/EIP712Field'
          type: array
          title: Tokenpermissions
          description: TokenPermissions struct
          default:
            - name: token
              type: address
            - name: amount
              type: uint256
        PermitTransferFrom:
          items:
            $ref: '#/components/schemas/EIP712Field'
          type: array
          title: Permittransferfrom
          description: Main permit message type
          default:
            - name: permitted
              type: TokenPermissions
            - name: spender
              type: address
            - name: nonce
              type: uint256
            - name: deadline
              type: uint256
      type: object
      title: EIP712Types
    compass__api_backend__v2__models__gas_sponsorship__permit_2_typed_data__EIP712Domain:
      properties:
        name:
          type: string
          const: Permit2
          title: Name
          description: Must be 'Permit2'
          default: Permit2
        chainId:
          type: integer
          title: Chainid
          description: EVM chain ID
        verifyingContract:
          type: string
          title: Verifyingcontract
          description: Permit2 contract address
      type: object
      required:
        - chainId
        - verifyingContract
      title: EIP712Domain
    PermitTransferFromMessage:
      properties:
        permitted:
          $ref: '#/components/schemas/TokenPermissions'
          description: Token and max amount
        spender:
          type: string
          title: Spender
          description: Address allowed to transfer (caller of permitTransferFrom)
        nonce:
          type: integer
          minimum: 0
          title: Nonce
          description: Unique nonce to prevent replay
        deadline:
          type: integer
          minimum: 0
          title: Deadline
          description: Unix timestamp after which signature expires
      type: object
      required:
        - permitted
        - spender
        - nonce
        - deadline
      title: PermitTransferFromMessage
    EIP712DomainField:
      properties:
        name:
          type: string
          title: Name
        type:
          type: string
          title: Type
      type: object
      required:
        - name
        - type
      title: EIP712DomainField
      description: A field in the EIP712Domain type definition.
    SafeTxField:
      properties:
        name:
          type: string
          title: Name
        type:
          type: string
          title: Type
      type: object
      required:
        - name
        - type
      title: SafeTxField
      description: A field in the SafeTx type definition.
    OperationType:
      type: integer
      enum:
        - 0
        - 1
      title: OperationType
      description: Safe operation types.
    EIP712Field:
      properties:
        name:
          type: string
          title: Name
          description: Field name in the struct
        type:
          type: string
          title: Type
          description: EVM type (e.g., address, uint256, TokenPermissions)
      type: object
      required:
        - name
        - type
      title: EIP712Field
    TokenPermissions:
      properties:
        token:
          type: string
          title: Token
          description: ERC-20 token address
        amount:
          type: integer
          minimum: 0
          title: Amount
          description: Maximum amount allowed to transfer
      type: object
      required:
        - token
        - amount
      title: TokenPermissions
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your Compass API Key. Get your key
        [here](https://www.compasslabs.ai/dashboard).

````