Installation
Requirements
Section titled “Requirements”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.
Adding the package
Section titled “Adding the package”From your project directory:
dart pub add dartsv # Dartflutter pub add dartsv # FlutterAlternatively, add it to pubspec.yaml and run dart pub get:
dependencies: dartsv: ^3.1.2Extra packages used in these docs
Section titled “Extra packages used in these docs”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 integersChecking the installation
Section titled “Checking the installation”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
toAddressevery time.SVPrivateKey(networkType: NetworkType.TEST)only sets the network used for the WIF encoding, andtoAddress()without an argument returns a mainnet Address. See Private and public keys.
Running the tested examples
Section titled “Running the tested examples”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:
cd examples/dartsvdart pub getdart test
