diff --git a/example/lib/bdk_library.dart b/example/lib/bdk_library.dart index 9722dba..b7a50b1 100644 --- a/example/lib/bdk_library.dart +++ b/example/lib/bdk_library.dart @@ -20,10 +20,7 @@ class BdkLibrary { } Future initializeBlockchain() async { - return await Blockchain.create( - config: const BlockchainConfig.esplora( - config: EsploraConfig( - baseUrl: 'https://mutinynet.com/api', stopGap: 10))); + return Blockchain.createMutinynet(); } Future restoreWallet(Descriptor descriptor) async { @@ -95,7 +92,11 @@ class BdkLibrary { } sendBitcoin( - Blockchain blockchain, Wallet aliceWallet, String addressStr) async { + Blockchain blockchain, + Wallet aliceWallet, + String addressStr, + int amountSat, + ) async { try { final txBuilder = TxBuilder(); final address = await Address.fromString( @@ -104,7 +105,7 @@ class BdkLibrary { final script = await address.scriptPubkey(); final feeRate = await estimateFeeRate(25, blockchain); final (psbt, _) = await txBuilder - .addRecipient(script, 750) + .addRecipient(script, amountSat) .feeRate(feeRate.satPerVb) .finish(aliceWallet); final isFinalized = await aliceWallet.sign(psbt: psbt); diff --git a/example/lib/simple_wallet.dart b/example/lib/simple_wallet.dart index 9c8544d..4202776 100644 --- a/example/lib/simple_wallet.dart +++ b/example/lib/simple_wallet.dart @@ -25,11 +25,12 @@ class _SimpleWalletState extends State { generateMnemonicKeys() async { final res = await lib.createMnemonic(); + final mnemonic = await res.asString(); setState(() { - displayText = res.toString(); + displayText = mnemonic; }); if (kDebugMode) { - print(await res.asString()); + print(mnemonic); } } @@ -49,11 +50,13 @@ class _SimpleWalletState extends State { } getNewAddress() async { - final res = (await (await lib.getAddress(aliceWallet)).address.asString()); - debugPrint(res); + final addressInfo = await lib.getAddress(aliceWallet); + final address = await addressInfo.address.asString(); + + debugPrint(address); setState(() { - displayText = "Address: $res"; + displayText = "Address: $address \n Index: ${addressInfo.index}"; }); } @@ -152,9 +155,13 @@ class _SimpleWalletState extends State { } } - sendBit() async { + sendBit(int amountSat) async { await lib.sendBitcoin( - blockchain!, aliceWallet, "tb1qyhssajdx5vfxuatt082m9tsfmxrxludgqwe52f"); + blockchain!, + aliceWallet, + "tb1qyhssajdx5vfxuatt082m9tsfmxrxludgqwe52f", + amountSat, + ); } @override @@ -286,9 +293,9 @@ class _SimpleWalletState extends State { fontWeight: FontWeight.w800), )), TextButton( - onPressed: () => sendBit(), + onPressed: () => sendBit(100000), child: const Text( - 'Press to send 1200 satoshi', + 'Press to send 100k sats', style: TextStyle( color: Colors.indigoAccent, fontSize: 12, diff --git a/lib/src/root.dart b/lib/src/root.dart index f501252..74f5781 100644 --- a/lib/src/root.dart +++ b/lib/src/root.dart @@ -61,6 +61,30 @@ class Blockchain extends BdkBlockchain { } } + static Future createMutinynet({ + int stopGap = 20, + }) async { + final config = BlockchainConfig.esplora( + config: EsploraConfig( + baseUrl: 'https://mutinynet.ltbl.io/api', + stopGap: stopGap, + ), + ); + return create(config: config); + } + + static Future createTestnet({ + int stopGap = 20, + }) async { + final config = BlockchainConfig.esplora( + config: EsploraConfig( + baseUrl: 'https://testnet.ltbl.io/api', + stopGap: stopGap, + ), + ); + return create(config: config); + } + ///Estimate the fee rate required to confirm a transaction in a given target of blocks @override Future estimateFee({required int target, hint}) async {