Bark Dart SDK
Integrate fast, low-cost, scalable Bitcoin payments into your Flutter/Dart apps with the Bark Dart SDK. Combine on-chain, Ark and Lightning Network payments with one simple integration, no channel management and fully self-custodial.
Overview
This package provides Dart bindings for bark, an implementation of the Ark protocol on Bitcoin led by Second. These bindings allow Dart and Flutter applications to integrate Ark wallet functionality, enabling instant, low-cost Bitcoin payments via the Ark protocol without losing custody of funds.
Bark enables:
- 🏃♂️ Instant onboarding: No channels to open, start transacting immediately
- 🤌 Simplified UX: Send and receive without managing channels or liquidity
- 🌐 Universal payments: Send Ark, Lightning, and on-chain payments
- 💸 Lower costs: Instant payments at a fraction of on-chain fees
- 🔒 Self-custodial: Full control of your funds at all times
Installation
Requirements
- Dart SDK ≥ 3.10.0 (for Native Assets support)
- Rust toolchain (cargo, rustc) for building native library
- Flutter 3.x+ (for Flutter apps)
Add to your project
Via pub.dev:
dependencies:
bark_bitcoin: ^0.1.2-beta.32+bark.0.1.0-beta.8
Via git (for latest development or specific versions):
dependencies:
bark_bitcoin:
git:
url: https://gitlab.com/ark-bitcoin/bark-ffi-bindings
path: dart/
ref: v0.1.2-beta.32+bark.0.1.0-beta.8 # or specific tag
Then run:
dart pub get # or flutter pub get
The native library will be automatically built by Dart's Native Assets system when you run your app.
Beta/Pre-release Versions
To use a beta or pre-release version:
dependencies:
bark_bitcoin:
git:
url: https://gitlab.com/ark-bitcoin/bark-ffi-bindings
path: dart/
ref: v0.1.2-beta.32+bark.0.1.0-beta.8 # Specific beta tag
Usage
Create a new wallet
import 'package:bark_bitcoin/bark_bitcoin.dart';
// Configure for signet
final config = Config(
'https://ark.signet.2nd.dev',
'https://esplora.signet.2nd.dev',
Network.signet,
null, // vtxoRefreshExpiryThreshold - use defaults
null, // vtxoExitMargin - use defaults
null, // htlcRecvClaimDelta - use defaults
);
// Create wallet with BIP39 mnemonic
final wallet = Wallet.create(
'your twelve word mnemonic phrase goes here today',
config,
'/path/to/wallet/data',
false, // forceRescan
);
print('Wallet fingerprint: ${wallet.properties().fingerprint}');
Open existing wallet
final wallet = Wallet.open(
'your twelve word mnemonic phrase goes here today',
config,
'/path/to/wallet/data',
);
Sync and check balance
// Lightweight sync
wallet.sync_();
// Get balance
final balance = wallet.balance();
print('Spendable: ${balance.spendableSats} sats');
print('Pending in round: ${balance.pendingInRoundSats} sats');
print('Pending exit: ${balance.pendingExitSats} sats');
Receive payments
// Generate Ark address
final arkAddress = wallet.newAddress();
print('Send funds to: $arkAddress');
// Or create a Lightning invoice
final invoice = wallet.bolt11Invoice(10000);
print('Lightning invoice: ${invoice.invoice}');
Send payments
// Pay Lightning invoice
try {
final result = wallet.payLightningInvoice('lnbc...', null);
print('Payment successful! Preimage: ${result.preimage}');
} on BarkError catch (e) {
print('Payment failed: $e');
}
// Pay to Lightning Address
final result = wallet.payLightningAddress(
'user@domain.com',
5000,
'Coffee payment',
);
// Send to Ark address (instant, out-of-round)
wallet.sendArkoorPayment('ark1...', 1000);
Claim Lightning receives
// Claim all pending Lightning receives
wallet.tryClaimAllLightningReceives(true);
Offboard to on-chain
// Offboard all funds to Bitcoin address
final result = wallet.offboardAll('bc1q...');
print('Offboarded in round: ${result.roundId}');
Maintenance
// Full maintenance (recommended periodic operation)
wallet.maintenance();
Error Handling
The package uses typed errors via BarkError:
try {
wallet.payLightningInvoice('lnbc...', null);
} on BarkError catch (e) {
switch (e) {
case BarkError_InsufficientFunds():
print('Not enough balance');
case BarkError_InvalidInvoice():
print('Invalid invoice format');
case BarkError_ServerConnection():
print('Cannot connect to server');
default:
print('Error: $e');
}
}
Example
Pure Dart Example
See example/main.dart for a pure Dart example demonstrating how to also use a default onchain wallet or how to integrate your own existing onchain wallet for on- and offboarding operations.
To run the example:
dart run example/main.dart
Flutter App Example
See example/flutter_app for a Flutter app example integrating the Bark Dart SDK.
Development
For Package Maintainers
⚠️ The following instructions are for bark package maintainers only. End users of the bark package do not need to build from source or run the generator script.
Generating bindings after changes
When bark-ffi is modified, the Dart bindings must be regenerated to reflect the changes.
-
Copy the updated UDL file from bark-ffi to rust/src/bark.udl. For the build hook and bindgen script to work with uniffi-dart, we need it in this location.
-
Run the bindings generator script:
From the
dart/directory, run:bash ./generate-bindings.shor from the root of the repository, you can also run:
make dartThis script:
- Builds bark-ffi from the workspace
- Generates Dart bindings into
lib/bark.dart
-
Test the generated bindings:
cd .. dart pub get dart test -
Commit the changes and generated files:
git add . git commit -m "chore: update Dart bindings"
For End Users
End users installing bark do not need to run generate-bindings.sh.
When you add bark as a dependency and run your app, Dart's Native Assets system automatically:
- Finds the Rust source in the
rust/directory - Compiles it for your platform
- Links it to your Dart/Flutter application
You only need:
- Dart SDK ≥ 3.10.0
- Rust toolchain (cargo, rustc) installed on your system: run
rustup install stableif you don't have it yet.
Documentation
License
CC0-1.0 - See LICENSE for details.
Contributing
See CONTRIBUTING.md for contribution guidelines.