stellar 0.3.2

Stellar client library for Dart developers.

Usage #

A simple usage example:

import 'package:stellar/stellar.dart';
import 'package:http/http.dart' as http;

void createKey() {
  KeyPair pair = KeyPair.random();
  print("Account Id  : " + pair.accountId);
  print("Secret Seed : " + pair.secretSeed);
}

void createTestAccount(String accountId) {
  var url = "https://friendbot.stellar.org/?addr=${accountId}";
  http.get(url).then((response) {
    switch (response.statusCode) {
      case 200:
        {
          print("SUCCESS! You have a new account : \n${response.body}");
          print("Response body: ${response.body}");
          break;
        }
      default:
        {
          print("ERROR! : \n${response.body}");
        }
    }
  });
}

void getAccountDetails(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.accounts.account(pair).then((account) {
    print("Balances for account: ${pair.accountId}");

    for (Balance balance in account.balances) {
      print(
          "Type: ${balance.assetType}, Code: ${balance.assetCode}, Balance: ${balance.balance}");

      switch (balance.assetType) {
        case "native":
          {
            print("balance: ${balance.balance} XLM");
            break;
          }
        default:
          {
            print(
                "balance: ${balance.balance} ${balance.assetCode} issuer: ${balance.assetIssuer}");
          }
      }

      print("sequence number: ${account.sequenceNumber}");

      for (Signer signer in account.signers) {
        print("signer public key: ${signer.accountId}");
      }

      print("auth required: ${account.flags.authRequired}");
      print("auth revocable: ${account.flags.authRevocable}");

      for (String key in account.data.keys) {
        print("data key: ${key} value: ${account.data[key]}");
      }
    }
  });
}

void getAccountTransactions(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.transactions
      .forAccount(pair)
      .order(RequestBuilderOrder.DESC)
      .limit(200)
      .execute()
      .then((page) {
    for (TransactionResponse transactionResponse in page.records) {
      print(transactionResponse);
    }
  });
}

void sendPayment() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair source = KeyPair.fromSecretSeed(
      "SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2");
  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.accounts.account(source).then((sourceAccount) {
    Transaction transaction = new TransactionBuilder(sourceAccount)
        .addOperation(new PaymentOperationBuilder(
                destination, new AssetTypeNative(), "10")
            .build())
        .addMemo(Memo.text("Test Transaction"))
        .build();
    transaction.sign(source);

    server.submitTransaction(transaction).then((response) {
      print("Success!");
      print(response);
    }).catchError((error) {
      print("Something went wrong!");
    });
  });
}

void paymentStream() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.payments.forAccount(destination).stream().listen((response) {
    if (response is PaymentOperationResponse) {
      switch (response.assetType) {
        case "native":
          print(
              "Payment of ${response.amount} XLM from ${response.sourceAccount.accountId} received");
          break;
        default:
          print(
              "Payment of ${response.amount} ${response.assetCode} from ${response.sourceAccount.accountId}");
      }
    }
  });
}

/*
Account Id  : GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC
Secret Seed : SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2

Account Id  : GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3
Secret Seed : SAACNKL2BBFVU7BVAVI2EIYSZQPQANZNYBVYUR7RFWTTRTOB6FPDR4NY
 */

void main() {
  createKey();
  createTestAccount("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountDetails("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountTransactions("GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");
  sendPayment();
  paymentStream();
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

0.3.2 #

  • Remove "dart:mirrors" for Flutter

0.3.0 #

  • Initial version, created by Jeff Lee

example/example.dart

import 'package:stellar/stellar.dart';
import 'package:http/http.dart' as http;

void createKey() {
  KeyPair pair = KeyPair.random();
  print("Account Id  : " + pair.accountId);
  print("Secret Seed : " + pair.secretSeed);
}

void createTestAccount(String accountId) {
  var url = "https://friendbot.stellar.org/?addr=${accountId}";
  http.get(url).then((response) {
    switch (response.statusCode) {
      case 200:
        {
          print("SUCCESS! You have a new account : \n${response.body}");
          print("Response body: ${response.body}");
          break;
        }
      default:
        {
          print("ERROR! : \n${response.body}");
        }
    }
  });
}

void getAccountDetails(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.accounts.account(pair).then((account) {
    print("Balances for account: ${pair.accountId}");

    for (Balance balance in account.balances) {
      print(
          "Type: ${balance.assetType}, Code: ${balance.assetCode}, Balance: ${balance.balance}");

      switch (balance.assetType) {
        case "native":
          {
            print("balance: ${balance.balance} XLM");
            break;
          }
        default:
          {
            print(
                "balance: ${balance.balance} ${balance.assetCode} issuer: ${balance.assetIssuer}");
          }
      }

      print("sequence number: ${account.sequenceNumber}");

      for (Signer signer in account.signers) {
        print("signer public key: ${signer.accountId}");
      }

      print("auth required: ${account.flags.authRequired}");
      print("auth revocable: ${account.flags.authRevocable}");

      for (String key in account.data.keys) {
        print("data key: ${key} value: ${account.data[key]}");
      }
    }
  });
}

void getAccountTransactions(String accountId) {
  KeyPair pair = KeyPair.fromAccountId(accountId);

  Network.useTestNetwork();
  Server server = Server("https://horizon-testnet.stellar.org");
  server.transactions
      .forAccount(pair)
      .order(RequestBuilderOrder.DESC)
      .limit(200)
      .execute()
      .then((page) {
    for (TransactionResponse transactionResponse in page.records) {
      print(transactionResponse);
    }
  });
}

void sendPayment() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair source = KeyPair.fromSecretSeed(
      "SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2");
  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.accounts.account(source).then((sourceAccount) {
    Transaction transaction = new TransactionBuilder(sourceAccount)
        .addOperation(new PaymentOperationBuilder(
                destination, new AssetTypeNative(), "10")
            .build())
        .addMemo(Memo.text("Test Transaction"))
        .build();
    transaction.sign(source);

    server.submitTransaction(transaction).then((response) {
      print("Success!");
      print(response);
    }).catchError((error) {
      print("Something went wrong!");
    });
  });
}

void paymentStream() {
  Network.useTestNetwork();
  Server server = new Server("https://horizon-testnet.stellar.org");

  KeyPair destination = KeyPair.fromAccountId(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");

  server.payments.forAccount(destination).stream().listen((response) {
    if (response is PaymentOperationResponse) {
      switch (response.assetType) {
        case "native":
          print(
              "Payment of ${response.amount} XLM from ${response.sourceAccount.accountId} received");
          break;
        default:
          print(
              "Payment of ${response.amount} ${response.assetCode} from ${response.sourceAccount.accountId}");
      }
    }
  });
}

/*
Account Id  : GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC
Secret Seed : SB7IAVKZJCK2T5TAN4F25TC7XGFB4BVLRPFJUT662Y2RK4MK7NAT4FO2

Account Id  : GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3
Secret Seed : SAACNKL2BBFVU7BVAVI2EIYSZQPQANZNYBVYUR7RFWTTRTOB6FPDR4NY
 */

void main() {
  createKey();
  createTestAccount("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountDetails("GBHHJLRSEWACDUMZPGNEFVTMYW34OJIGOACK3H7WMKA3FQBHSHJPN5TC");
  getAccountTransactions(
      "GDNHJLN2WQ7HP6TPZK6SPU273TG6P3RLOPR6FWMC57HVJRB3SVE7F7G3");
  sendPayment();
  paymentStream();
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  stellar: ^0.3.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:stellar/stellar.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
53
Health:
Code health derived from static analysis. [more]
43
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
75
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Sep 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:stellar/stellar.dart.

Health suggestions

Fix lib/src/xdr/xdr_operation.dart. (-14.82 points)

Analysis of lib/src/xdr/xdr_operation.dart reported 32 hints, including:

line 10 col 21: Use ; instead of {} for empty constructor bodies.

line 40 col 26: Use ; instead of {} for empty constructor bodies.

line 86 col 25: Use ; instead of {} for empty constructor bodies.

line 118 col 23: Use ; instead of {} for empty constructor bodies.

line 136 col 27: Use ; instead of {} for empty constructor bodies.

Fix lib/src/xdr/xdr_entry.dart. (-12.22 points)

Analysis of lib/src/xdr/xdr_entry.dart reported 26 hints, including:

line 11 col 21: Use ; instead of {} for empty constructor bodies.

line 99 col 24: Use ; instead of {} for empty constructor bodies.

line 136 col 23: Use ; instead of {} for empty constructor bodies.

line 160 col 26: Use ; instead of {} for empty constructor bodies.

line 187 col 20: Use ; instead of {} for empty constructor bodies.

Fix lib/src/xdr/xdr_type.dart. (-9.99 points)

Analysis of lib/src/xdr/xdr_type.dart reported 21 hints, including:

line 7 col 14: Use ; instead of {} for empty constructor bodies.

line 24 col 14: Use ; instead of {} for empty constructor bodies.

line 41 col 15: Use ; instead of {} for empty constructor bodies.

line 58 col 15: Use ; instead of {} for empty constructor bodies.

line 75 col 16: Use ; instead of {} for empty constructor bodies.

Fix additional 20 files with analysis or formatting issues. (-43.25 points)

Additional issues in the following files:

  • lib/src/xdr/xdr_other.dart (13 hints)
  • lib/src/xdr/xdr_transaction.dart (13 hints)
  • lib/src/xdr/xdr_scp.dart (10 hints)
  • lib/src/operation.dart (9 hints)
  • lib/src/xdr/xdr_ledger.dart (9 hints)
  • lib/src/xdr/data_input.dart (6 hints)
  • lib/src/assets.dart (4 hints)
  • lib/src/key_pair.dart (4 hints)
  • lib/src/xdr/xdr_auth.dart (4 hints)
  • lib/src/xdr/xdr_asset.dart (3 hints)
  • lib/src/request.dart (2 hints)
  • lib/src/transaction.dart (2 hints)
  • lib/src/xdr/xdr_network.dart (2 hints)
  • lib/src/memo.dart (1 hint)
  • lib/src/network.dart (1 hint)
  • lib/src/response.dart (1 hint)
  • lib/src/response_effects.dart (1 hint)
  • lib/src/response_operations.dart (1 hint)
  • lib/src/xdr/data_output.dart (1 hint)
  • lib/src/xdr/xdr_data.dart (1 hint)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (http).

The package description is too short. (-15 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
convert ^2.0.2 2.1.1
crypto ^2.0.6 2.1.3
eventsource ^0.2.1 0.2.2
fixnum ^0.10.9 0.10.9
http ^0.11.3+17 0.11.3+17 0.12.0+2
tweetnacl ^0.3.1 0.3.2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
logging 0.11.3+2
meta 1.1.7
path 1.6.4
source_span 1.5.5
string_scanner 1.0.5
sync 0.2.0
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
mockito ^3.0.0
test ^1.0.0