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

# Stellar

> Sign messages and transactions, send XLM and Stellar assets, manage trustlines, and query balances using the Dynamic Swift SDK.

## Overview

`StellarModule` provides native Stellar blockchain operations including message signing, transaction envelope signing, XLM and asset transfers, trustlines, balance queries, and network details. Access it via `DynamicSDK.instance().stellar`.

## Prerequisites

* Dynamic SDK initialized (see [Quickstart](/docs/swift/quickstart))
* User authenticated (see [Authentication](/docs/swift/authentication))
* Stellar enabled in the [Dynamic dashboard](https://app.dynamic.xyz/dashboard/chains-and-networks)

## Get a Stellar Wallet

If Stellar is enabled in the dashboard, the user gets a Stellar wallet on signup. Find it via `userWallets`:

```swift theme={"system"}
let sdk = DynamicSDK.instance()

let stellarWallet = sdk.wallets.userWallets.first(where: { $0.chain == "STELLAR" })
```

## Get Balance

Query the XLM balance for a wallet. Returned as a string to preserve precision. Pass `assetCode` and `assetIssuer` to query a non-native asset instead.

```swift theme={"system"}
let balance = try await sdk.stellar.getBalance(walletId: wallet.id)
print("Balance: \(balance) XLM")
```

## Get Network

Query the Stellar network the wallet is connected to:

```swift theme={"system"}
let network = try await sdk.stellar.getNetwork(walletId: wallet.id)
print("Network: \(network)") // e.g. "PUBLIC"
```

## Sign a Message

Sign a message using the connected Stellar wallet:

```swift theme={"system"}
let signature = try await sdk.stellar.signMessage(
  walletId: wallet.id,
  message: "Hello, Stellar!"
)
print("Signature: \(signature)")
```

## Sign a Transaction

Sign a base64-encoded transaction envelope XDR. Returns the signed envelope XDR:

```swift theme={"system"}
let signedXdr = try await sdk.stellar.signTransaction(
  walletId: wallet.id,
  transactionXdr: envelopeXdr
)
print("Signed XDR: \(signedXdr)")
```

## Send a Balance

Send XLM, or a Stellar asset, to a recipient. Returns the transaction hash.

```swift theme={"system"}
let hash = try await sdk.stellar.sendBalance(
  walletId: wallet.id,
  toAddress: "GBUQWP3BOUZX34ULNQG23RQ6F4BV7DVOV4SJQ6FYMJNL3LQO5QFCP5O4",
  amount: "0.01"
)
print("Hash: \(hash)")
```

| Parameter | Type | Description |
| - | - | - |
| `walletId` | `String` | The wallet ID to send from |
| `toAddress` | `String` | Recipient Stellar address (public key) |
| `amount` | `String` | Amount to send |
| `tokenAddress` | `String?` | Optional asset in `CODE:ISSUER` form. Omit for native XLM |
| `tokenDecimals` | `Int?` | Optional asset decimals. Stellar uses 7 by default |

## Add a Trustline

Add a trustline for a non-native asset. An account must hold a trustline for an asset before it can receive it:

```swift theme={"system"}
let hash = try await sdk.stellar.addTrustline(
  walletId: wallet.id,
  assetCode: "USDC",
  assetIssuer: "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5",
  limit: nil // optional
)
print("Hash: \(hash)")
```

| Parameter | Type | Description |
| - | - | - |
| `walletId` | `String` | The wallet ID |
| `assetCode` | `String` | The asset code, e.g. `USDC` |
| `assetIssuer` | `String` | Public key of the asset issuer |
| `limit` | `String?` | Optional trustline limit |

## API Reference

| Method | Returns | Description |
| - | - | - |
| `getBalance` | `String` | Get wallet balance |
| `getNetwork` | `String` | Get the connected network, e.g. `PUBLIC` |
| `signMessage` | `String` | Sign a message |
| `signTransaction` | `String` | Sign an envelope XDR |
| `sendBalance` | `String` | Send XLM or an asset, returns tx hash |
| `addTrustline` | `String` | Add an asset trustline, returns tx hash |

## Next Steps

* [Bitcoin Operations](/docs/swift/wallets/bitcoin/overview): Bitcoin operations
* [SUI Operations](/docs/swift/wallets/sui/overview): SUI operations
* [Token Balances](/docs/swift/wallets/general/token-balances): Multi-chain balance queries


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.