The Stellar Wallet SDK for Flutter is a library that allows developers to build wallet applications on the Stellar Network faster. It utilizes Flutter Stellar SDK to communicate with Stellar Horizon and Anchors.
- Add the dependency to your pubspec.yaml file:
dependencies:
stellar_wallet_flutter_sdk: ^0.3.4
stellar_flutter_sdk: ^1.8.4
- Install it (command line or IDE):
flutter pub get
- In your source file import the SDK, initialize and use it:
import 'package:stellar_wallet_flutter_sdk/stellar_wallet_flutter_sdk.dart';
Wallet wallet = Wallet.testNet;
Anchor anchor = wallet.anchor(anchorDomain);
AnchorServiceInfo serviceInfo = await anchor.sep24().getServiceInfo();
Here is a step by step that we recommend:
- Clone this repo.
- Open the project in your IDE (e.g. Android Studio).
- Open the file
pubspec.yaml
and pressPub get
in your IDE. - Go to the project's
test
directory, run a test from there and you are good to go!
Add it to your app:
- In your Flutter app add the local dependency in
pubspec.yaml
and then runpub get
:
dependencies:
flutter:
sdk: flutter
stellar_wallet_flutter_sdk:
path: ../stellar_wallet_flutter_sdk
- In your source file import the SDK, initialize and use it:
import 'package:stellar_wallet_flutter_sdk/stellar_wallet_flutter_sdk.dart';
Wallet wallet = Wallet.testNet;
Anchor anchor = wallet.anchor(anchorDomain);
AnchorServiceInfo serviceInfo = await anchor.sep24().getServiceInfo();
The Wallet SDK provides an easy way to communicate with Anchors. It supports:
Furthermore the wallet SDK provides extra functionality on top of the Flutter Stellar SDK. For interaction with the Stellar Network, the Flutter Wallet SDK covers the basics used in a typical wallet flow.
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:
var wallet = Wallet.testNet;
The wallet instance can be further configured. For example, to connect to the public network:
var wallet = Wallet(StellarConfiguration.publicNet);
The Flutter Wallet SDK uses the standard Client from the http package 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 to be used across the app.
The client can be globally configured:
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 of this SDK use for example MockClient
.
The Flutter Wallet SDK provides extra functionality on top of the existing Flutter Stellar SDK. For interaction with the Stellar Network, the Flutter Wallet SDK covers the basics used in a typical wallet flow. For more advanced use cases, the underlying Flutter Stellar SDK should be used instead.
To interact with the Horizon instance configured in the previous steps, simply do:
var stellar = wallet.stellar();
This example will create a Stellar class that manages the connection to the Horizon service.
You can read more about working with the Stellar Network in the respective doc section.
The Flutter Stellar SDK is included as a dependency in the Flutter Wallet SDK.
It's very simple to use the Flutter Stellar SDK connecting to the same Horizon instance as a Wallet class. To do so, simply call:
var stellar = wallet.stellar();
var server = stellar.server;
var transactions = await server.transactions.forAccount(accountId).execute();
But you can also import and use it for example like this:
import 'package:stellar_flutter_sdk/stellar_flutter_sdk.dart' as flutter_sdk;
final sdk = flutter_sdk.StellarSDK.TESTNET;
var accountId = "GASYKQXV47TPTB6HKXWZNB6IRVPMTQ6M6B27IM5L2LYMNYBX2O53YJAL";
var transactions = await sdk.transactions.forAccount(accountId).execute();
Primary use of the Flutter Wallet 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:
var anchor = wallet.anchor("https://testanchor.stellar.org");
And the most basic interaction of fetching a SEP-001: Stellar Info File:
var info = await anchor.getInfo();
The anchor class also supports SEP-010: Stellar Authentication, SEP-024: Hosted Deposit and Withdrawal features, SEP-012: KYC API and SEP-009: Standard KYC Fields.
You can read more about working with Anchors in the respective doc section.
SEP-030 defines the standard way for an individual (e.g., a user or wallet) to regain access to their Stellar account after losing its private key without providing any third party control of the account. During this flow the wallet communicates with one or more recovery signer servers to register the wallet for a later recovery if it's needed.
You can read more about working with Recovery Servers in the respective doc section.
SEP-038 defines a way for anchors to provide quotes for the exchange of an off-chain asset and a different on-chain asset, and vice versa.
You can read more about requesting quotes in the respective doc section.
The SEP-06 standard defines a way for anchors and wallets to interact on behalf of users. Wallets use this standard to facilitate exchanges between on-chain assets (such as stablecoins) and off-chain assets (such as fiat, or other network assets such as BTC).
You can read more about programmatic deposit and withdrawal in the respective doc section.
Docmumentation can be found in the doc folder and on the official Stellar Build a Wallet with the Wallet SDK page.
Examples can be found in the test cases and in the example app.