<blockquote>
<p><strong>what is the process that is actually happening under the hood when I click the 'transfer Bitcoin' button of my wallet in terms of the keys?</strong></p>
</blockquote>
<p>Your wallet selects from available coins (UTXOs for which your wallet knows the private key) a sufficient number to cover the amount being &quot;sent&quot; plus the selected transaction-fee.</p>
<p>These selected UTXOs form the input side of the transaction the wallet constructs. The output side has at least one output that contains a locking script derived from the &quot;address&quot; provided by the payee. The locking script is sometimes called a scriptpubkey for historical reasons.</p>
<p>For each coin being spent, your wallet then creates a cryptographic signature of most of the transaction data using the corresponding private key and the ECDSA algorithm.</p>
<p>This signature data is put into the unlocking script for each UTXO. This unlocking script is sometimes called the scriptsig. It proves to the rest of the nodes in the network that you have the right to spend those UTXOs. The exact contents needed in the unlocking script obviously depend on the specific type of locking script in the prior transactions in which those coins were sent to you (i.e. came under your control)</p>
<p>The unlocking scripts are part of the created transaction but obviously cannot be part of the transaction data that is signed because their contents are not known until after the signature has been created.</p>
<hr />
<p>The above applies to the simplest types of transactions. There are complicated types of transactions, such as n-of-m multisig, which I have not attempted to describe here.</p>
<hr />
<blockquote>
<p><strong>How does the bitcoin network use public [...] keys [...]</strong></p>
</blockquote>
<p>In at least the simplest forms of transactions, nodes in the Bitcoin network use the public key provided to verify that the cryptographic signature in a transaction is a correct cryptographic signature of the transaction data.</p>
<p>Putting it very loosely:</p>
<pre><code>bigint signature = ECDSA.sign(data, private-key)

boolean validity = ECDSA.verify(data, signature, public-key)
</code></pre>
<p>Things must get more complicated at a detailed level when you compare P2PK vs P2PKH let alone P2SH, segwit outputs and multisig transactions.</p>

CC BY-SA 4.0
2022-06-20T15:45:22.907Z
2022-06-20T16:11:11.483Z
2022-06-20T16:11:11.483Z
RedGrittyBrick
<p>I am familiar with Public keys, private keys and addresses. But, I don't understand how they are used when I want to transfer funds to a different wallet.</p>
<p>For example, what is the process that is actually happening under the hood when I click the 'transfer Bitcoin' button of my wallet in terms of the keys?</p>

CC BY-SA 4.0
2022-06-20T12:41:51.043Z
Does this answer your question? [How are public and private keys related to the wallet?](https://bitcoin.stackexchange.com/questions/19950/how-are-public-and-private-keys-related-to-the-wallet)
Vojtěch Strnad
<transactions><wallet><address><private-key><public-key>
How does the bitcoin network use public and private keys when one wants to transfer funds?
Jamo
# How does the bitcoin network use public and private keys when one wants to transfer funds?

(Asked by: username_0 on 2022-06-20)

I am familiar with Public keys, private keys and addresses. But, I don't understand how they are used when I want to transfer funds to a different wallet.

For example, what is the process that is actually happening under the hood when I click the 'transfer Bitcoin' button of my wallet in terms of the keys?

**Tags:** transactions, wallet, address, private-key, public-key

> **Comments:**
> **username_1**: Does this answer your question? [How are public and private keys related to the wallet?](https://bitcoin.stackexchange.com/questions/19950/how-are-public-and-private-keys-related-to-the-wallet)  

---

## 1 answers

### Answer by username_2 on 2022-06-20. Score: 2

> **what is the process that is actually happening under the hood when I click the 'transfer Bitcoin' button of my wallet in terms of the keys?**

Your wallet selects from available coins (UTXOs for which your wallet knows the private key) a sufficient number to cover the amount being "sent" plus the selected transaction-fee.

These selected UTXOs form the input side of the transaction the wallet constructs. The output side has at least one output that contains a locking script derived from the "address" provided by the payee. The locking script is sometimes called a scriptpubkey for historical reasons.

For each coin being spent, your wallet then creates a cryptographic signature of most of the transaction data using the corresponding private key and the ECDSA algorithm.

This signature data is put into the unlocking script for each UTXO. This unlocking script is sometimes called the scriptsig. It proves to the rest of the nodes in the network that you have the right to spend those UTXOs. The exact contents needed in the unlocking script obviously depend on the specific type of locking script in the prior transactions in which those coins were sent to you (i.e. came under your control)

The unlocking scripts are part of the created transaction but obviously cannot be part of the transaction data that is signed because their contents are not known until after the signature has been created.

---

The above applies to the simplest types of transactions. There are complicated types of transactions, such as n-of-m multisig, which I have not attempted to describe here.

---

> **How does the bitcoin network use public [...] keys [...]**

In at least the simplest forms of transactions, nodes in the Bitcoin network use the public key provided to verify that the cryptographic signature in a transaction is a correct cryptographic signature of the transaction data.

Putting it very loosely:

```
bigint signature = ECDSA.sign(data, private-key)

boolean validity = ECDSA.verify(data, signature, public-key)

```

Things must get more complicated at a detailed level when you compare P2PK vs P2PKH let alone P2SH, segwit outputs and multisig transactions.


---

