2

I am using bitcoinjs-lib to create private key (WIF), addresses and sign the transactions.

I would like to fetch all transactions (UTXOs) associated with a wallet. I found these libs: bitcoin-filter and bitcoin-net .

But I didn't understand the code below:

var filter = new Filter(peers)
filter.add(new Buffer('818895f3dc2c178629d3d2d8fa3ec4a3f8179821', 'hex'))
filter.add(walletObject)

What parameters does filter receive ? Are they the addresses ? If so, how can I find all the used addresses of a HD wallet ?

1

You are asking a few different questions here, I'll try to help with each:

Wallet filters: See BIP37 which describes SPV wallets in general. A Bloom Filter is generated by the SPV wallet and sent to full nodes on the network. The filter is a compact data structure that represents every public key the SPV wallet is interested in. The full node will check each transaction in blocks and the mempool against this filter and if there is a match, that transaction is sent back to the SPV wallet. BIP37 specifies all the data the filter is tested against but in summary, it includes transaction hashes, public keys, public key hashes, and script hashes.

You can see here in the bcoin wallet (also JavaScript) where the wallet's public key hashes and watched outpoints are added to the bloom filter.

The bcoin socket API also has a method for adding address hashes to a bloom filter before it is sent to a full node.

HD Wallet Addresses: To understand HD wallets it's important to read BIP44 which describes the recovery process. During BIP44 wallet recovery, the program starts with a seed of entropy (derived from your 12- or 24-word phrase). It then generates account 0, receive and change addresses 0 through 20. Then, starting from a specified block height (just before the wallet was first generated in time) it iterates through the blockchain looking for TXs that match those addresses. Every time it finds a match, it generates another address (the 21st address, and so on...). In SPV mode, each new address would have to be added to the Bloom Filter and sent back to the full node. This actually can cause issues with the wallet sync, and some blocks may need to be re-scanned.

Notes:

I am using bitcoinjs-lib to create private key (WIF), addresses and sign the transactions. I would like to fetch all transactions (UTXOs) associated with a wallet.

In general using a single private key and reusing a single address is considered bad practice. BIP44 is an excellent design for wallets that generate multiple keys and addresses.

If you really only have one address to scan for UTXO you can use an address indexer like in bcoin or soon-to-be-merged to Bitcoin Core. You may also have some success just using rpc scantxoutset fo your single address.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.