Skip to content

Soneso/stellar_wallet_flutter_sdk

Repository files navigation

Dart Flutter

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.

Installation

From pub.dev

  1. Add the dependency to your pubspec.yaml file:
dependencies:
  stellar_wallet_flutter_sdk: ^0.3.0
  1. Install it (command line or IDE):
flutter pub get
  1. 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();

Manual

Here is a step by step that we recommend:

  1. Clone this repo.
  2. Open the project in your IDE (e.g. Android Studio).
  3. Open the file pubspec.yaml and press Pub get in your IDE.
  4. Go to the project's test directory, run a test from there and you are good to go!

Add it to your app:

  1. In your Flutter app add the local dependency in pubspec.yaml and then run pub get:
dependencies:
   flutter:
     sdk: flutter
   stellar_wallet_flutter_sdk:
     path: ../stellar_wallet_flutter_sdk
  1. 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();

Functionality

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.

Getting started

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:

var wallet = Wallet.testNet;

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

var wallet = Wallet(StellarConfiguration.publicNet);

Configuring a custom HTTP client

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.

Stellar Basics

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.

Stellar Flutter SDK

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();

Anchor Basics

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.

Recovery

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.

Quotes

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.

Programmatic Deposit and Withdrawal

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.

Docs and Examples

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.