Skip to content

Latest commit

 

History

History
128 lines (96 loc) · 2.51 KB

File metadata and controls

128 lines (96 loc) · 2.51 KB

cdk_flutter

Ask DeepWiki

Ask questions about this project using DeepWiki AI

Flutter bindings for the Cashu Development Kit (CDK) - build cross-platform Cashu wallets with native performance.

Installation

Add to your pubspec.yaml:

dependencies:
  cdk_flutter:
    git:
      url: https://github.com/cashubtc/cdk_flutter.git

Quick Start

import 'package:cdk_flutter/cdk_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await CdkFlutter.init();

  // Generate or load mnemonic
  final mnemonic = generateMnemonic();

  // Create database and wallet
  final db = await WalletDatabase.newInstance(path: 'wallet.sqlite');
  final wallet = Wallet(
    mintUrl: 'https://mint.example.com',
    unit: 'sat',
    mnemonic: mnemonic,
    db: db,
  );

  runApp(MyApp());
}

Usage

Mint Tokens

final stream = wallet.mint(amount: BigInt.from(1000));

stream.listen((quote) {
  if (quote.state == MintQuoteState.unpaid) {
    print('Pay: ${quote.request}');
  } else if (quote.state == MintQuoteState.issued) {
    print('Minted ${quote.amount} sats');
  }
});

Send Tokens

final prepared = await wallet.prepareSend(amount: BigInt.from(100));
final token = await wallet.send(
  send: prepared,
  memo: 'Payment to Alice',
  includeMemo: true,
);
print('Token: ${token.encoded}');

Receive Tokens

final token = Token.parse(encoded: 'cashuA...');
final amount = await wallet.receive(token: token);

Melt (Pay Lightning)

final quote = await wallet.meltQuote(request: 'lnbc...');
await wallet.melt(quote: quote);

Multi-Mint Wallet

final multiWallet = await MultiMintWallet.newInstance(
  unit: 'sat',
  mnemonic: mnemonic,
  db: db,
);

await multiWallet.addMint(mintUrl: 'https://mint1.example.com');
final total = await multiWallet.totalBalance();

Balance Widget

WalletBalanceBuilder(
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      return Text('${snapshot.data} sats');
    }
    return CircularProgressIndicator();
  },
)

Development

git clone https://github.com/cashubtc/cdk_flutter.git
cd cdk_flutter
flutter pub get
cd rust && cargo build && cd ..
flutter_rust_bridge_codegen generate
cd example && flutter run

License

MIT License - see LICENSE.

Part of the Cashu Development Kit ecosystem.