0

at first sorry for my ignorance, I have little experience at bitcoin programming.

Im trying to implement a very simple wallet using NBitcoin library. I have done some work, but now Im stucked with wallet restoration function.

Lets say I have mnemonic private key, then I calculate its public key.

With public key am I able to track all transactions associated with this key? Even if I used multiple adresses? How its done(NBitcoin)? Any advice? Do I have to iterate throught whole blockchain and chceck signatures?

Thank you.

2
  • Is it an HD wallet?
    – MCCCS
    Commented Feb 3, 2019 at 13:50
  • No I want to keep it as simplest as posible for start. Commented Feb 3, 2019 at 14:15

2 Answers 2

0

With public key am I able to track all transactions associated with this key?

A public key has two corresponding addresses: Uncompressed and compressed. I suggest only generating compressed public keys for simplicity. The relevant methods are Compress and Decompress here.

So, yes.

Even if I used multiple adresses?

Multiple addresses: Yes, you should track all of them.

Do I have to iterate throughout whole blockchain and check the signatures?

You should use SPV: Download a block, verify it, keep the headers, skip to the next block. Also you should keep the transactions that are incoming/outgoing. Writing the current block height to the wallet file is a good idea, as after you launch the wallet for the second time, you'll only need to download blocks and scan for relevant transactions after that block height.

1
  • Thank you for the answer. What API would you recomend for a beginer(query a blockchain)? I read a NBitcoin c# book and couple of articles + Mastering bitcoin, but Im still confused about the restoration thing. Commented Feb 3, 2019 at 21:46
0

Restoring the wallet balance:

To restore the wallet balance from just the mnemonic passphrase, and determine your spendable UTXO's, you need to perform a UTXO-scan with a trusted local node which has validated the Blockchain.

With Bitcoind server, consider querying scantxoutset, which allows you to determine (per public key/address) which unspent outputs are controlled by your wallets.

Restoring the wallet history:

Restoring the receiving/spending history of the wallet will require you to build an "address-index" over all transaction, indexing the tx's associated with addresses you control.

Libbitcoin-Server already indexes all transactions by standard addresses per default, so you can query a standard Libbitcoin server to get the full-history for each address in your wallet.

Note: You do not need to validate signatures during wallet restoration, because your local bitcoin server has validated these. You don't need to build an SPV client if you are running your own validating full-node.

1
  • Furthermore, one will need the derivation path(s) to scan.
    – Zelgada
    Commented Feb 8 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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