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

# Getting Started

> Learn how to build a wallet application on the Stellar network with the Wallet SDK. Explore key features, setup steps, Stellar fundamentals, and anchor basics.

> [!NOTE]
>
> This guide is available on four different programming languages: Typescript, Kotlin, Flutter (Dart) and Swift. You can change the shown version on each page via the buttons above.

> [!CAUTION]
>
> **Important**
>
> Documentation for this language is currently work in progress. Some of information may not be applicable for this language, or missing. Code samples may be incomplete.

## Installation

First, you need to add the SDK dependency to your project.

**TypeScript**

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
yarn add @stellar/typescript-wallet-sdk
```

**Kotlin**

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
// gradle.kts
implementation("org.stellar:wallet-sdk:[version]")
```

You can get the latest available version on the [project GitHub page](https://github.com/stellar/kotlin-wallet-sdk)

**Flutter**

```dart theme={"theme":{"light":"github-light","dark":"github-dark"}}
// pubspec.yaml
stellar_wallet_flutter_sdk: ^1.0.6
stellar_flutter_sdk: ^2.1.3
```

You can get the latest available version on the [project GitHub page](https://github.com/Soneso/stellar_wallet_flutter_sdk)

**Swift**

Add the repository ([https://github.com/Soneso/stellar-swift-wallet-sdk](https://github.com/Soneso/stellar-swift-wallet-sdk)) as a Package Dependency in your XCode project. Two new Package dependencies will appear: "stellar-wallet-sdk" and "stellarsdk".

## Working with the SDK

Let's start with the main class that provides all SDK functionality. It's advised to have a singleton wallet object shared across the application. Creating a wallet with a default configuration connected to Stellar's Testnet is simple:

**Kotlin**

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val wallet = Wallet(StellarConfiguration.Testnet)
```

**TypeScript**

```ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
let wallet = walletSdk.Wallet.TestNet();
```

**Flutter**

```dart theme={"theme":{"light":"github-light","dark":"github-dark"}}
var wallet = Wallet.testNet;
```

**Swift**

```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
let wallet = Wallet.testNet
```

The wallet instance can be further configured. For example, to connect to the public network:

**Kotlin**

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val walletTestnet = Wallet(StellarConfiguration(Network.TESTNET, "https://horizon-testnet.stellar.org"))
```

There is one more available configuration for a wallet that allows it to configure internal logic of the SDK. For example, to test with local servers on an HTTP protocol, HTTP can be manually enabled.

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val walletCustom = Wallet(
  StellarConfiguration.Testnet,
  ApplicationConfiguration { defaultRequest { url { protocol = URLProtocol.HTTP } } }
)
```

**TypeScript**

```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
let wallet = new Wallet({
  stellarConfiguration: StellarConfiguration.MainNet(),
});
```

**Flutter**

```dart theme={"theme":{"light":"github-light","dark":"github-dark"}}
var wallet = Wallet(StellarConfiguration.publicNet);
```

**Swift**

```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
let wallet = Wallet(stellarConfig: StellarConfig.publicNet)
```

### Configuring the Client

**Kotlin**

The Kotlin wallet SDK uses the [ktor client](https://ktor.io/docs/getting-started-ktor-client.html) for all network requests (excluding Horizon, where the Stellar SDK's HTTP client is used). Currently, the okhttp engine is configured to be used with the client. You can read more about how to configure the ktor client [here](https://ktor.io/docs/create-client.html#configure-client).

For example, the client can be globally configured:

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val walletCustomClient =
  Wallet(
    StellarConfiguration.Testnet,
    ApplicationConfiguration(
      defaultClientConfig = {
        engine { this.config { this.connectTimeout(Duration.ofSeconds(10)) } }
        install(HttpRequestRetry) {
          retryOnServerErrors(maxRetries = 5)
          exponentialDelay()
        }
      }
    )
  )
```

This Kotlin code will set the connect timeout to ten seconds via the [okhttp configuration](https://ktor.io/docs/http-client-engines.html#okhttp) and also installs the [retry plugin](https://ktor.io/docs/client-retry.html). You can also specify client configuration for specific wallet SDK classes.

For example, to change connect timeout when connecting to some anchor server:

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val anchorCustomClient =
  walletCustomClient.anchor("example.com") {
    engine { this.config { this.connectTimeout(Duration.ofSeconds(30)) } }
  }
```

### Closing Resources

After the wallet class is no longer used, it's necessary to close all clients used by it. While in some applications it may not be required (e.g. the wallet lives for the whole lifetime of the application), in other cases it can be required. If your wallet class is short-lived, it's recommended to close client resources using a close function:

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
fun closeWallet() {
  wallet.close()
}
```

**TypeScript**

The Typescript wallet SDK uses the [axios client](https://axios-http.com/docs/intro) for all network requests. You can read more about how to configure the axios client [here](https://axios-http.com/docs/instance).

For example, we can configure our axios client to be globally configured with a timeout:

```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const customClient: AxiosInstance = axios.create({
  timeout: 1000,
});
let appConfig = new ApplicationConfiguration(DefaultSigner, customClient);
let wal = new Wallet({
  stellarConfiguration: StellarConfiguration.TestNet(),
  applicationConfiguration: appConfig,
});
```

You can find more [configure options here.](https://axios-http.com/docs/req_config)

**Flutter**

The Flutter Wallet SDK uses the standard Client from the [http package](https://pub.dev/packages/http) for all network requests (excluding Horizon, where the Flutter Stellar SDK's HTTP client is used).

Optionally, you can set your own client from [http package](https://pub.dev/packages/http) to be used across the app.

The client can be globally configured:

```dart theme={"theme":{"light":"github-light","dark":"github-dark"}}
import 'package:http/http.dart';
// ...

// init and configure your HTTP client
// var myClient = ...

// set as default HTTP client
var appConfig = ApplicationConfiguration(defaultClient: myClient);
var walletCustomClient = Wallet(StellarConfiguration.testNet, applicationConfiguration: appConfig);
```

Some [test cases](https://github.com/Soneso/stellar_wallet_flutter_sdk/tree/main/test) of this SDK use for example the `MockClient`.

## Stellar Basics

The wallet SDK provides some extra functionality on top of the existing [Horizon SDK]. For interaction with the Stellar network, the wallet SDK covers only the basics used in a typical wallet flow. For more advanced use cases, the underlying [Horizon SDK] should be used instead.

To interact with the Horizon instance configured in the previous steps, simply do:

**Kotlin**

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val stellar = wallet.stellar()
```

**TypeScript**

```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
const stellar = wallet.stellar();
```

**Flutter**

```dart theme={"theme":{"light":"github-light","dark":"github-dark"}}
var stellar = wallet.stellar();
```

**Swift**

```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
let stellar = wallet.stellar
```

This example will create a Stellar class that manages the connection to Horizon service.

> [!NOTE]
>
> Default configuration connects to the public Stellar Horizon instance. You can change this behavior as described [above](#working-with-the-sdk).

You can read more about working with the Stellar network in the [respective section](https://developers.stellar.org/docs/build/apps/wallet/stellar.md).

## Anchor Basics

Primary use of the SDK is to provide an easy way to connect to anchors via sets of protocols known as SEPs. Let's look into connecting to the Stellar test anchor:

**Kotlin**

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
val anchor = wallet.anchor("https://testanchor.stellar.org")
```

**TypeScript**

```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
let anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
```

**Flutter**

```dart theme={"theme":{"light":"github-light","dark":"github-dark"}}
var anchor = wallet.anchor("testanchor.stellar.org")
```

**Swift**

```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
let anchor = wallet.anchor(homeDomain: "testanchor.stellar.org")
```

**TypeScript**

> [!NOTE]
>
> If the anchor home domain uses http, then you need to set the `allowHttp` flag when creating the anchor:
>
> ```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
> let anchor = wallet.anchor({ homeDomain: "example.com", allowHttp: true });
> ```
>
> This can only be used on Testnet.

And the most basic interaction of fetching a [SEP-1]: Stellar Info File:

**Kotlin**

```kotlin theme={"theme":{"light":"github-light","dark":"github-dark"}}
suspend fun anchorToml(): TomlInfo {
  return anchor.getInfo()
}
```

**TypeScript**

```typescript theme={"theme":{"light":"github-light","dark":"github-dark"}}
let resp = await anchor.sep1();
```

**Flutter**

```dart theme={"theme":{"light":"github-light","dark":"github-dark"}}
var resp = await anchor.sep1();
```

**Swift**

```swift theme={"theme":{"light":"github-light","dark":"github-dark"}}
let resp = try await anchor.sep1
```

Below you can find all the SEPs the anchor class currently supports:

* [SEP-1]: Stellar Info File as shown above
* [SEP-10]: explored on [Stellar Authentication] section
* [SEP-24]: explored on [Hosted Deposit and Withdrawal] section
* [SEP-6]: explored on [Programmatic Deposit and Withdrawal] section
* [SEP-12]: explored on [Providing KYC info] subsection
* [SEP-38]: explored on [Quote] section

Besides the SEPs supported by the anchor class the wallet SDK also has support for the [SEP-7] protocol which is explored on [URI Scheme to facilitate delegated signing] section.

[horizon sdk]: https://developers.stellar.org/docs/tools/sdks

[sep-1]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0001.md

[sep-6]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0006.md

[sep-7]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0007.md

[sep-10]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0010.md

[sep-12]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0012.md

[sep-24]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0024.md

[sep-38]: https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0038.md

[stellar authentication]: https://developers.stellar.org/docs/build/apps/wallet/sep10.md

[hosted deposit and withdrawal]: https://developers.stellar.org/docs/build/apps/wallet/sep24.md

[programmatic deposit and withdrawal]: https://developers.stellar.org/docs/build/apps/wallet/sep6.md

[providing kyc info]: https://developers.stellar.org/docs/build/apps/wallet/sep6.md#providing-kyc-info

[quote]: https://developers.stellar.org/docs/build/apps/wallet/sep38.md

[uri scheme to facilitate delegated signing]: https://developers.stellar.org/docs/build/apps/wallet/sep7.md
