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
isAllowanceValidandapprovemethods 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 }wheredatais 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.isAllowanceValidandsodax.swaps.approve.Destination Chain (Stellar): Call
ensureTrustline(above) for the destination token before callingsodax.swaps.swap.
Money Market
Source Chain (Stellar): Trustlines are automatically handled by
sodax.moneyMarket.isAllowanceValidandsodax.moneyMarket.approve.Destination Chain (Stellar): Call
ensureTrustlinefor the destination token before executing money market actions.
Bridge
Source Chain (Stellar): Trustlines are automatically handled by
sodax.bridge.isAllowanceValidandsodax.bridge.approve.Destination Chain (Stellar): Call
ensureTrustlinefor the destination token before callingsodax.bridge.bridge.
Migration
Source Chain (Stellar): Trustlines are automatically handled by the migration service's allowance/approve methods.
Destination Chain (Stellar): Call
ensureTrustlinefor the destination token before executing migration operations.
Staking
Source Chain (Stellar): Trustlines are automatically handled by
sodax.staking.isAllowanceValidandsodax.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
Always check trustlines before operations: Use
hasSufficientTrustlineto verify trustline status before any operation where Stellar is the destination chain.Set appropriate trustline limits: When establishing a trustline via
requestTrustline, the limit is set to the Stellar maximum by default (Operation.changeTrustwithout an explicit limit). Ensure the wallet has sufficient XLM for the transaction fee.Wait for confirmation: Always wait for the trustline transaction to be confirmed (use
waitForTransactionReceipt) before proceeding with the main operation.Handle errors via
Result<T>: All public service methods returnPromise<Result<T>>. Checkresult.okbefore usingresult.value. On failure, inspectresult.error.messageandresult.error.cause.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
Related Documentation
Swaps - Cross-chain intent-based swaps
Money Market - Cross-chain lending and borrowing
Bridge - Cross-chain token bridging
Migration - Token migration
Staking - SODA token staking
Architecture Reference - Full v2 architecture reference
Last updated