Skip to content

Examples

These are programs you can run, not fragments. The first is this site’s tutorial. The rest are libspiffy’s own end-to-end tests, which drive real wallets against localnet-teranode. Each one shows one feature working from start to finish.

examples/first_payment is the complete tutorial: two wallets, a faucet payment imported with its proof, an invoice, a BEEF validated and broadcast, and both wallets confirming it. It uses libspiffy 5.0.0.

Terminal window
git clone https://github.com/twostack/libspiffy.dev
cd libspiffy.dev/examples/first_payment
dart pub get
LOCALNET_TERANODE=/path/to/localnet-teranode dart run bin/first_payment.dart

It needs localnet-teranode running and takes about a minute and a half.

example/coordinator_example.dart in the libspiffy repository shows the coordinator API with no network at all. It uses in-memory storage, creates a wallet and an invoice with ask, handles a failure as a CoordinatorFailure, and follows balance changes with on<E>(). Run it from a libspiffy checkout:

Terminal window
dart run example/coordinator_example.dart

These are in test/integration/ in the libspiffy repository. They share a harness, localnet_harness.dart. Its LocalnetNode is a complete LibSpiffyActorSystem that syncs headers from Teranode and broadcasts through Arcade. Its receiveMined funds a wallet from the faucet with a proof, the same way the tutorial does.

Test file What it shows
localnet_payment_e2e_test.dart Invoice payments: both wallets confirm; paying from a payment not yet mined; a payment handed over twice is received once; a restart between receiving and the block
localnet_deferred_e2e_test.dart Deferred payments: the payer broadcasts, cancels or reclaims a payment the payee never sent; first seen wins against a reclaim
localnet_channel_e2e_test.dart Payment channels: open, pay three times, close; settling at the margin; claiming a refund when the other side is gone
localnet_delegated_payment_e2e_test.dart A service takes a payment on a delegated chain for an offline recipient, who later takes it in
localnet_type42_payment_e2e_test.dart Paying to a type-42 (BRC-42) destination of a recipient’s anchor key
localnet_reorg_e2e_test.dart Chain reorganizations: wallets follow a confirmed payment that moves to another block or height
localnet_node_e2e_test.dart Header sync from Teranode, following new blocks, and restarting at the tip

Run one from a libspiffy checkout, with localnet-teranode running beside it:

Terminal window
dart test -P localnet test/integration/localnet_payment_e2e_test.dart

LOCALNET_LOG=1 prints the library’s log records, tagged by node. These tests mine blocks on the shared regtest chain, as the localnet scripts do. Testing against localnet has the details.