<blockquote>
  <p>But what I don't understand in particular is how they relate to transactions and wallets.</p>
</blockquote>

<p>This requires a long answer. <a href="https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3" rel="nofollow noreferrer">Here's</a> a nice intro which should answer this.</p>

<blockquote>
  <p>I am actually not sure what the point is for adding the key to the wallet. Does it somehow relate to transactions? Why do I need to add a private key to my wallet? </p>
</blockquote>

<p>If you read the above intro to cryptography in Bitcoin, this question is almost fully answered. You need a private key because that's the secret half you use to sign transactions. Otherwise  people could spend your Bitcoins.</p>

<blockquote>
  <p>Can/should I add more than one to a wallet? Or, oh! I think I remember, the wallet key is just for storing your private keys. But why don't I just store it myself in a different way? What advantage does having it stored in a wallet offer?</p>
</blockquote>

<p>Yes you should create many. In fact, one private key for each transaction is ideal. You can store these keys anywhere you want, but a wallet program will do many nice things for you. The wallet keeps track of how much Bitcoin you have, it gives you an easy way to sign TX's and send them to the network, it groups all your received transactions and allows you to combine their amounts to form new transactions and so on. A profesionally developed wallet will also normally employ good security practices. But nothing's stopping you from rolling your own key store.</p>

<blockquote>
  <p>Then the second part of the question is, what key I should be signing my transactions with, and how. Can I say "wallet, give me a key by name" or something?</p>
</blockquote>

<p>Bitcoin Core and other wallets offer a database management system to manage your keys for you. Yes you can usually give them mnemonic names or start typing a prefix and the wallet software suggests the rest. You should sign your TX's with a key you've never used before. That's the general rule.</p>

<blockquote>
  <p>Final part of the question is, how many keys I should have.</p>
</blockquote>

<p>One key per transaction. Never reuse keys.</p>

CC BY-SA 4.0
2019-10-29T03:48:03.207Z
2019-10-29T03:48:03.207Z
Jose Fonseca
<blockquote>
  <p>I get their purpose and that they need a strong password, etc. But what I don't understand in particular is how they relate to transactions and wallets.</p>
</blockquote>

<p>The purpose of the private key is to decrypt. An example in asymmetric cryptography a.k.a. public key cryptography, you have a shared(public) key, and the private key that can decrypt some scrambled data, let's say a message. A public key cannot reverse solve for a private key, but a private key can derive the public key. The only way to decrypt the message is by having the private key. Bitcoin is similar, one type of bitcoin transaction is Pay-to-<strong>Public-Key-Hash</strong> (P2PKH). Value/data locked inside these types of addresses require the spender to provide the <strong>public key</strong> and a cryptographic signature (<strong>hash</strong>) using the private key to that public key. The signature proves that the spender has the private key without the spender ever having to reveal the private key. </p>

CC BY-SA 4.0
2019-10-29T08:45:06.953Z
This is technically correct, but mostly unrelated to bitcoin - Bitcoin does not use any encryption/decryption at a protocol level
Raghav Sood
CC BY-SA 4.0
2019-10-29T03:48:30.027Z
2019-10-29T03:48:30.027Z
m1xolyd1an
<p>I am learning about BitCoin private keys and trying to figure out what the best way to use them are. I get their purpose and that they need a strong password, etc. But what I don't understand in particular is how they relate to transactions and wallets.</p>

<p>I just ran <code>bitcoin-cli importprivkey &lt;key&gt;</code> (which has been running for like 5 minutes, who knows how long this will take, and I am brand new). I am actually not sure what the point is for adding the key to the wallet. Does it somehow relate to transactions? Why do I need to add a private key to my wallet? Can/should I add more than one to a wallet? Or, oh! I think I remember, the wallet key is just for storing your private keys. But why don't I just store it myself in a different way? What advantage does having it stored in a wallet offer?</p>

<p>Then the second part of the question is, what key I should be signing my transactions with, and how. Can I say "wallet, give me a key by name" or something?</p>

<p>Final part of the question is, <strong>how many keys I should have</strong>. Should I just have 1 key for everything? 2 just to switch it up every now and then? 10 or 100 or 1000? A new key for every transaction? I don't know, what is the ideal here? Is it best to use some keys for one thing, and others for another?</p>

CC BY-SA 4.0
2019-10-28T14:34:02.090Z
Based on the questions you’ve asked recently, I suggest you don’t try to build systems that handle other peoples money.
Claris
<transactions><private-key>
How to use BitCoin private keys (a primer)
Lance Pollard
# How to use BitCoin private keys (a primer)

(Asked by: username_0 on 2019-10-28)

I am learning about BitCoin private keys and trying to figure out what the best way to use them are. I get their purpose and that they need a strong password, etc. But what I don't understand in particular is how they relate to transactions and wallets.

I just ran `bitcoin-cli importprivkey <key>` (which has been running for like 5 minutes, who knows how long this will take, and I am brand new). I am actually not sure what the point is for adding the key to the wallet. Does it somehow relate to transactions? Why do I need to add a private key to my wallet? Can/should I add more than one to a wallet? Or, oh! I think I remember, the wallet key is just for storing your private keys. But why don't I just store it myself in a different way? What advantage does having it stored in a wallet offer?

Then the second part of the question is, what key I should be signing my transactions with, and how. Can I say "wallet, give me a key by name" or something?

Final part of the question is, **how many keys I should have**. Should I just have 1 key for everything? 2 just to switch it up every now and then? 10 or 100 or 1000? A new key for every transaction? I don't know, what is the ideal here? Is it best to use some keys for one thing, and others for another?

**Tags:** transactions, private-key

> **Comments:**
> **username_1**: Based on the questions you’ve asked recently, I suggest you don’t try to build systems that handle other peoples money.  

---

## 2 answers

### Answer by username_2 on 2019-10-29. Score: 1 | Accepted answer

> But what I don't understand in particular is how they relate to transactions and wallets.

This requires a long answer. [Here's](https://hackernoon.com/what-is-the-math-behind-elliptic-curve-cryptography-f61b25253da3) a nice intro which should answer this.

> I am actually not sure what the point is for adding the key to the wallet. Does it somehow relate to transactions? Why do I need to add a private key to my wallet?

If you read the above intro to cryptography in Bitcoin, this question is almost fully answered. You need a private key because that's the secret half you use to sign transactions. Otherwise people could spend your Bitcoins.

> Can/should I add more than one to a wallet? Or, oh! I think I remember, the wallet key is just for storing your private keys. But why don't I just store it myself in a different way? What advantage does having it stored in a wallet offer?

Yes you should create many. In fact, one private key for each transaction is ideal. You can store these keys anywhere you want, but a wallet program will do many nice things for you. The wallet keeps track of how much Bitcoin you have, it gives you an easy way to sign TX's and send them to the network, it groups all your received transactions and allows you to combine their amounts to form new transactions and so on. A profesionally developed wallet will also normally employ good security practices. But nothing's stopping you from rolling your own key store.

> Then the second part of the question is, what key I should be signing my transactions with, and how. Can I say "wallet, give me a key by name" or something?

Bitcoin Core and other wallets offer a database management system to manage your keys for you. Yes you can usually give them mnemonic names or start typing a prefix and the wallet software suggests the rest. You should sign your TX's with a key you've never used before. That's the general rule.

> Final part of the question is, how many keys I should have.

One key per transaction. Never reuse keys.


---

### Answer by username_3 on 2019-10-29. Score: 1

> I get their purpose and that they need a strong password, etc. But what I don't understand in particular is how they relate to transactions and wallets.

The purpose of the private key is to decrypt. An example in asymmetric cryptography a.k.a. public key cryptography, you have a shared(public) key, and the private key that can decrypt some scrambled data, let's say a message. A public key cannot reverse solve for a private key, but a private key can derive the public key. The only way to decrypt the message is by having the private key. Bitcoin is similar, one type of bitcoin transaction is Pay-to-**Public-Key-Hash** (P2PKH). Value/data locked inside these types of addresses require the spender to provide the **public key** and a cryptographic signature (**hash**) using the private key to that public key. The signature proves that the spender has the private key without the spender ever having to reveal the private key.

> **Comments:**
> **username_4**: This is technically correct, but mostly unrelated to bitcoin - Bitcoin does not use any encryption/decryption at a protocol level  

---

