Getting Started
This guide is available on three different programming languages: Typescript, Kotlin and Flutter (Dart). You can change the shown version on each page via the buttons above.
Installation
First, you need to add the SDK dependency to your project.
- bash
yarn add @stellar/typescript-wallet-sdk
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:
- TypeScript
let wallet = walletSdk.Wallet.TestNet();
The wallet instance can be further configured. For example, to connect to the public network:
- TypeScript
let wallet = new Wallet({
stellarConfiguration: StellarConfiguration.MainNet(),
});
Configuring the Client
The Typescript wallet SDK uses the axios client for all network requests. You can read more about how to configure the axios client here.
For example, we can configure our axios client to be globally configured with a timeout:
- TypeScript
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.
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:
- TypeScript
const stellar = wallet.stellar();
This example will create a Stellar class that manages the connection to Horizon service.
Default configuration connects to the public Stellar Horizon instance. You can change this behavior as described above.
You can read more about working with the Stellar network in the respective section.
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:
- TypeScript
let anchor = wallet.anchor({ homeDomain: "testanchor.stellar.org" });
If the anchor home domain uses http, then you need to set the allowHttp
flag when creating the anchor:
- TypeScript
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:
- TypeScript
let resp = 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.