Skip to content

Installation

DartSV 3.1.2 needs Dart SDK 2.17 or later, and works with Dart 3. It has no native code, so the same package runs on the Dart VM, in Flutter on every platform, and when compiled to JavaScript for Flutter web.

From your project directory:

Terminal window
dart pub add dartsv # Dart
flutter pub add dartsv # Flutter

Alternatively, add it to pubspec.yaml and run dart pub get:

dependencies:
dartsv: ^3.1.2

Some of the examples use three small packages alongside DartSV. DartSV already depends on them, but Dart only lets you import the packages you list yourself:

dependencies:
dartsv: ^3.1.2
hex: ^0.2.0 # HEX.encode / HEX.decode, for keys, hashes and scripts as hex
decimal: ^2.3.3 # Decimal, for BSV amounts with Coin.ofBtc
buffer: ^1.1.1 # ByteDataReader, for reading variable-length integers

A single import gives us the whole public API:

// import 'package:dartsv/dartsv.dart';
final key = SVPrivateKey(networkType: NetworkType.TEST);
final address = key.toAddress(networkType: NetworkType.TEST);
print('Fund this testnet address: $address');

If that prints a testnet Address (starting with m or n), the package works.

Pass the network to toAddress every time. SVPrivateKey(networkType: NetworkType.TEST) only sets the network used for the WIF encoding, and toAddress() without an argument returns a mainnet Address. See Private and public keys.

The code on these pages lives in examples/dartsv/ in the twostack/www repository, as a Dart package whose tests pin DartSV 3.1.2. To run them:

Terminal window
cd examples/dartsv
dart pub get
dart test