stellar 0.3.2

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • new54

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 packages get

Alternatively, your editor might support pub get or flutter packages 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';
  
Version Uploaded Documentation Archive
0.3.2 Nov 22, 2018 Go to the documentation of stellar 0.3.2 Download stellar 0.3.2 archive
0.3.1 Nov 22, 2018 Go to the documentation of stellar 0.3.1 Download stellar 0.3.1 archive
0.3.0 Nov 21, 2018 Go to the documentation of stellar 0.3.0 Download stellar 0.3.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
18
Health:
Code health derived from static analysis. [more]
96
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
54
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: Flutter, web, other

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

Health suggestions

Fix lib/src/memo.dart. (-2.48 points)

Analysis of lib/src/memo.dart reported 5 hints:

line 75 col 17: Always override hashCode if overriding ==.

line 170 col 17: Always override hashCode if overriding ==.

line 187 col 17: Always override hashCode if overriding ==.

line 217 col 17: Always override hashCode if overriding ==.

line 266 col 17: Always override hashCode if overriding ==.

Fix lib/src/base32.dart. (-0.50 points)

Analysis of lib/src/base32.dart reported 1 hint:

line 3 col 7: Name types using UpperCamelCase.

Fix lib/src/operation.dart. (-0.50 points)

Analysis of lib/src/operation.dart reported 1 hint:

line 1342 col 17: Always override hashCode if overriding ==.

Fix additional 3 files with analysis or formatting issues. (-0.50 points)

Additional issues in the following files:

  • lib/src/transaction.dart (1 hint)
  • lib/src/request.dart (Run dartfmt to format lib/src/request.dart.)
  • lib/src/response.dart (Run dartfmt to format lib/src/response.dart.)

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
convert ^2.0.2 2.0.2
crypto ^2.0.6 2.0.6
eventsource ^0.2.1 0.2.1
fixnum ^0.10.9 0.10.9
http ^0.11.3+17 0.11.3+17 0.12.0
tweetnacl ^0.3.1 0.3.1
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
logging 0.11.3+2
meta 1.1.6
path 1.6.2
source_span 1.4.1
string_scanner 1.0.4
sync 0.2.0
typed_data 1.1.6
Dev dependencies
mockito ^3.0.0
test ^1.0.0