Use natively compiled BDK in a nodejs context with TypeScript typings. Extremely experimental. Uses https://napi.rs/ to generate bindings.
Inspired by bdk-nodejs and a week at Bitcoin Park.
- Create a wallet
- Sync to Electrum
- Get balance
import { ElectrumBlockchain, Wallet, Network } from 'bdk';
const wallet = new Wallet(
'wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/0/*)',
'wpkh([c258d2e4/84h/1h/0h]tpubDDYkZojQFQjht8Tm4jsS3iuEmKjTiEGjG6KnuFNKKJb5A6ZUCUZKdvLdSDWofKi4ToRCwb9poe1XdqfUnP4jaJjCB2Zwv11ZLgSbnZSNecE/1/*)',
Network.Testnet,
);
const chain = new ElectrumBlockchain('ssl://electrum.blockstream.info:60002');
wallet.sync(chain);
const balance: bigint = wallet.getBalance();
console.log('balance', balance); // 5748838n