For the complete documentation index, see llms.txt. This page is also available as Markdown.

Handle Stellar Trustline

Stellar blockchain requires trustlines to be established before you can receive or hold tokens. This document explains how to handle trustlines when using Stellar with the Sodax SDK across different operations.

Overview

In Stellar, trustlines are required to:

  • Receive tokens: You must establish a trustline before receiving any token on Stellar

  • Hold tokens: You cannot hold tokens without an active trustline

The SDK handles trustlines differently depending on whether Stellar is used as the source chain or destination chain:

  • Source Chain (Stellar): The SDK automatically handles trustlines through the standard isAllowanceValid and approve methods on each feature service (e.g. sodax.swaps.isAllowanceValid, sodax.bridge.isAllowanceValid).

  • Destination Chain (Stellar): You must manually check and establish trustlines before executing operations.

Architecture

In the v2 SDK there are no caller-constructed spoke provider objects. The Sodax facade exposes a spoke property of type SpokeService, which owns a stellar: StellarSpokeService instance. All Stellar-specific logic is accessed through that path.

The Stellar wallet provider is IStellarWalletProvider (from @sodax/wallet-sdk-core). When calling methods with raw: false, the chain-narrowed provider type is resolved from the srcChainKey via GetWalletProviderType<ChainKeys.STELLAR_MAINNET> — there is no manual spoke provider construction.

StellarSpokeService Methods

StellarSpokeService (accessed via sodax.spoke.stellar) provides three methods for managing Stellar trustlines.

hasSufficientTrustline

Checks if a sufficient trustline exists for a given token and wallet address.

Returns: Promise<boolean>true if the trustline exists and has sufficient available limit, false otherwise. Native XLM and legacy bnUSD always return true (no trustline required).

requestTrustline

Establishes (or increases) a trustline for a given token. Accepts RequestTrustlineParams<StellarChainKey, Raw>:

Returns: Promise<TxReturnType<StellarChainKey, Raw>>

  • raw: false → transaction hash (string)

  • raw: true{ from, to, value, data } where data is the unsigned transaction XDR string

Source-Chain Trustline Flow (Automated)

When Stellar is the source chain, isAllowanceValid delegates to hasSufficientTrustline and approve delegates to requestTrustline internally. The exact signatures for swaps and bridge are shown below.

SwapService

BridgeService

Destination-Chain Trustline Flow (Manual)

When Stellar is the destination chain, the SDK cannot establish a trustline on your behalf — you must check and establish it before executing any operation that delivers tokens to a Stellar address.

Usage by Operation Type

Swaps

  • Source Chain (Stellar): Trustlines are automatically handled by sodax.swaps.isAllowanceValid and sodax.swaps.approve.

  • Destination Chain (Stellar): Call ensureTrustline (above) for the destination token before calling sodax.swaps.swap.

Money Market

  • Source Chain (Stellar): Trustlines are automatically handled by sodax.moneyMarket.isAllowanceValid and sodax.moneyMarket.approve.

  • Destination Chain (Stellar): Call ensureTrustline for the destination token before executing money market actions.

Bridge

  • Source Chain (Stellar): Trustlines are automatically handled by sodax.bridge.isAllowanceValid and sodax.bridge.approve.

  • Destination Chain (Stellar): Call ensureTrustline for the destination token before calling sodax.bridge.bridge.

Migration

  • Source Chain (Stellar): Trustlines are automatically handled by the migration service's allowance/approve methods.

  • Destination Chain (Stellar): Call ensureTrustline for the destination token before executing migration operations.

Staking

  • Source Chain (Stellar): Trustlines are automatically handled by sodax.staking.isAllowanceValid and sodax.staking.approve.

  • Note: Staking operations always flow from spoke chains (including Stellar) to the hub chain (Sonic), so Stellar is only ever the source chain for staking.

Best Practices

  1. Always check trustlines before operations: Use hasSufficientTrustline to verify trustline status before any operation where Stellar is the destination chain.

  2. Set appropriate trustline limits: When establishing a trustline via requestTrustline, the limit is set to the Stellar maximum by default (Operation.changeTrust without an explicit limit). Ensure the wallet has sufficient XLM for the transaction fee.

  3. Wait for confirmation: Always wait for the trustline transaction to be confirmed (use waitForTransactionReceipt) before proceeding with the main operation.

  4. Handle errors via Result<T>: All public service methods return Promise<Result<T>>. Check result.ok before using result.value. On failure, inspect result.error.message and result.error.cause.

  5. Reuse trustlines: Once established, trustlines persist on the Stellar ledger. You do not need to recreate them for subsequent operations with the same token.

Common Patterns

Complete Example: Swap with Stellar Destination

Last updated