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
isAllowanceValidandapprovemethodsDestination Chain (Stellar): You must manually check and establish trustlines before executing operations
StellarSpokeService Methods
The SDK provides two methods for managing Stellar trustlines:
hasSufficientTrustline
Checks if a sufficient trustline exists for a given token and amount.
import { StellarSpokeService } from "@sodax/sdk";
const hasTrustline = await StellarSpokeService.hasSufficientTrustline(
tokenAddress, // The Stellar token address
amount, // The amount you need to receive
stellarSpokeProvider
);Returns: Promise<boolean> - true if trustline exists and has sufficient limit, false otherwise
requestTrustline
Establishes a trustline for a given token.
Returns: Transaction hash or raw transaction data depending on the raw parameter
Usage by Operation Type
Swaps
For Stellar-based swap operations:
Source Chain (Stellar): Trustlines are automatically handled by
isAllowanceValidandapprovemethodsDestination Chain (Stellar): You must manually establish trustlines before executing swaps
Money Market
For Stellar-based money market operations:
Source Chain (Stellar): Trustlines are automatically handled by
isAllowanceValidandapprovemethodsDestination Chain (Stellar): You must manually establish trustlines before executing money market actions
Bridge
For Stellar-based bridge operations:
Source Chain (Stellar): Trustlines are automatically handled by
isAllowanceValidandapprovemethodsDestination Chain (Stellar): You must manually establish trustlines before executing bridge operations
Migration
For Stellar-based migration operations:
Source Chain (Stellar): Trustlines are automatically handled by
isAllowanceValidandapprovemethodsDestination Chain (Stellar): You must manually establish trustlines before executing migration operations
Staking
For Stellar-based staking operations:
Source Chain (Stellar): Trustlines are automatically handled by
isAllowanceValidandapprovemethodsNote: Staking operations always flow from spoke chains (including Stellar) to the hub chain (Sonic), so Stellar is only used as a source chain for staking operations
Best Practices
Always check trustlines before operations: Use
hasSufficientTrustlineto verify trustline status before executing any operation where Stellar is the destination chainSet appropriate trustline limits: When establishing a trustline, set the limit to at least the amount you expect to receive, with some buffer for safety
Wait for confirmation: Always wait for the trustline transaction to be confirmed before proceeding with the main operation
Handle errors gracefully: Trustline establishment can fail due to network issues or insufficient XLM balance (required for transaction fees)
Reuse trustlines: Once established, trustlines persist, so you don't 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
Last updated