<blockquote>
  <p>With public key am I able to track all transactions associated with this key?</p>
</blockquote>

<p>A public key has two corresponding addresses: Uncompressed and compressed. I suggest only generating compressed public keys for simplicity. The relevant methods are <code>Compress</code> and <code>Decompress</code> <a href="https://github.com/MetacoSA/NBitcoin/blob/master/NBitcoin/PubKey.cs" rel="nofollow noreferrer">here</a>.</p>

<p>So, yes.</p>

<blockquote>
  <p>Even if I used multiple adresses?</p>
</blockquote>

<p>Multiple addresses: Yes, you should track all of them.</p>

<blockquote>
  <p>Do I have to iterate throughout whole blockchain and check the signatures?</p>
</blockquote>

<p>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.</p>

CC BY-SA 4.0
2019-02-03T21:46:31.543Z
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.
Martin Lipták
CC BY-SA 4.0
2019-02-03T14:24:45.633Z
2019-02-03T14:24:45.633Z
MCCCS
<p><strong>Restoring the wallet balance:</strong></p>

<p>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.</p>

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

<p><strong>Restoring the wallet history:</strong></p>

<p>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. </p>

<p><code>Libbitcoin-Server</code> 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.</p>

<p>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.</p>

CC BY-SA 4.0
2024-02-08T22:27:01.100Z
Furthermore, one will need the derivation path(s) to scan.
Zelgada
CC BY-SA 4.0
2019-02-03T17:59:56.980Z
2019-02-03T17:59:56.980Z
James C.
<p>at first sorry for my ignorance, I have little experience at bitcoin programming.</p>

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

<p>Lets say I have mnemonic private key, then I calculate its public key.</p>

<p>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?</p>

<p>Thank you.</p>

CC BY-SA 4.0
2019-02-03T13:50:06.863Z
Is it an HD wallet?
MCCCS
CC BY-SA 4.0
2019-02-03T14:15:05.287Z
No I want to keep it as simplest as posible for start.
Martin Lipták
<wallet><c#><nbitcoin>
NBitcoin, how to implement wallet restoration? How does it work?
Martin Lipták
# NBitcoin, how to implement wallet restoration? How does it work?

(Asked by: username_0 on 2019-02-02)

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.

**Tags:** wallet, c#, nbitcoin

> **Comments:**
> **username_1**: Is it an HD wallet?  
> **username_0**: No I want to keep it as simplest as posible for start.  

---

## 2 answers

### Answer by username_1 on 2019-02-03. Score: 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](https://github.com/MetacoSA/NBitcoin/blob/master/NBitcoin/PubKey.cs).

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.

> **Comments:**
> **username_0**: 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.  

---

### Answer by username_2 on 2019-02-03. Score: 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.

> **Comments:**
> **username_3**: Furthermore, one will need the derivation path(s) to scan.  

---

