<p>I try to explain it, that no coding is required :-) Taking more of a process view...</p>
<p><strong>Assembly and sending of a tx:</strong></p>
<p>the wallet software of A looks up it's internal database, if there is a transaction with required amount of 1 BTC on it. If yes, it then looks up this transaction's details in the blockchain, and finds in this transaction the pk script (spending condition), and assembles a new transaction, which shall move the funds to B's address. The wallet software then signs a hash of this transaction. The signature of this hash and the public key are placed in the [scriptsig] field of the transaction. So the final transaction contains the previous tx hash, signature and pubkey, and also an output section, with a pub key script (for B's  target address) and the amount. That's what the picture shows.
The transaction is then sent to the network.</p>
<p><strong>Transaction Verification:</strong></p>
<p>In the network are verifying nodes, that check for validity of the tx. Amongst others, these nodes check that you have the right to spend the funds. They take the current tx' sigscript (<code>&lt;signature&gt;</code> and <code>&lt;public key&gt;</code>), and from the previous tx the output script (pubkey script). Then basically two comparisons take place:</p>
<blockquote>
<p>1.) can the public key of the previous tx' sigscript be hashed to the same value as the presented hash in the current tx' pubkey script?</p>
<p>2.) is the signature a valid signature for the public key</p>
</blockquote>
<p>With the first check, it is assured, that the current transaction moves the funds to the previously defined target address. And with the second check it is verified, if the signature aligns to the presented public key.</p>
<p>For the second test: the wallet software creates a signature, which requires the private key of the owner of the public address. The private key is used to sign the hash of the current transaction.</p>
<p>The picture you provided has a presentation of the parts to create the spending tx. Not the verifying part. That makes it a bit more complex to derive functionality... I had a very good reading with Ken Shirrif's article here:</p>
<p><a href="http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html" rel="nofollow noreferrer">http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html</a></p>
<p>and also (of course) Andreas' book &quot;Mastering Bitcoin&quot; (Second Edition), which is also online available.</p>

CC BY-SA 3.0
2018-01-14T12:22:55.527Z
2018-03-19T06:40:01.473Z
2020-06-16T11:10:03.350Z
pebwindkraft
<p>Some of your understanding is not entirely correct. I will explain it with a series of question</p>

<blockquote>
  <p>What exactly is a transaction? What are its components?</p>
</blockquote>

<p>A transaction is a statement of transfer of value from one account(e.g Alice) to another account(e.g Bob). In bitcoin to transfer an amount, x Alice needs to first prove to the community that she has at least x amount with her. This proves in bitcoin is achieved by showing the whole community a previous transaction where Alice has received x(or more) amounts. Observe that it is even possible that Alice has received x amount from multiple transactions combined in which case Alice needs to give a list of the previous transaction which is called as <strong>inputs</strong> transaction.</p>

<p>Assume that if Alice has B bitcoins where B is greater than x, then Alice needs to send the change amount back to itself and x to bob. Alice can form this list out all the receiver's address with the corresponding amount which is called as <strong>outputs</strong> of a transaction.</p>

<blockquote>
  <p>What are Pubkey Scripts in the diagram?</p>
</blockquote>

<p>Bitcoin and several other cryptocurrencies provide us with an option to mention some conditions under which a transaction can be spent. Pubkey Scripts are nothing but these conditions. Example of Pubkey Scripts is "Only Alice is allowed to spend this with her signature", under which case Alice needs to show a legitimate signature to spend the transaction.</p>

<p>In your case, PubkeyScript1 contains the condition under which Alice is eligible to spend the transaction and PubkeyScript2 contains the condition which bob must satisfy to spend the transaction. </p>

CC BY-SA 3.0
2018-01-14T12:58:37.033Z
What is “txn”? {}{}{}
Rubertos
CC BY-SA 3.0
2018-01-14T13:11:54.573Z
"txn" is the short form of transaction. It is very standard. apologies.
sourav
CC BY-SA 3.0
2018-01-14T12:40:16.297Z
2018-01-14T16:37:14.330Z
2018-01-14T16:37:14.330Z
sourav
<p>( I have almost no background of coding, so please explain this in relatively easy words :) )</p>

<p>I want to know what are pubkey script, signature, full public key and the roles of these.</p>

<p>Specifically, I want to understand this diagram:</p>

<p><a href="https://i.sstatic.net/yTNgM.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/yTNgM.jpg" alt="enter image description here"></a></p>

<p>Here is how I understand this diagram;</p>

<p>Say, A wants to send 1btc to B.</p>

<p>Then, A gets something called <em>Pubkey script</em> from the most recent block in a block chain (Let’s call it PubkeyScript 1). Again, A uses something which is also called <em>Pubkey script</em> using the public key of B. (Let’s call it PubkeyScript 2) After that, A types a message “A sends 1btc to B”. Now, using A’s private key, convert the PubkeyScript1 to something called <em>signature</em>. Now, a chunk of signature and A’s public key and PubkeyScipt2 and the message “A sends 1btc to B” is called a <em>transaction</em>.</p>

<p>Am I understanding it correctly?</p>

<transactions><block>
How is a transaction created?
Rubertos
# How is a transaction created?

(Asked by: username_0 on 2018-01-14)

( I have almost no background of coding, so please explain this in relatively easy words :) )

I want to know what are pubkey script, signature, full public key and the roles of these.

Specifically, I want to understand this diagram:

[![enter image description here](https://i.sstatic.net/yTNgM.jpg)](https://i.sstatic.net/yTNgM.jpg)

Here is how I understand this diagram;

Say, A wants to send 1btc to B.

Then, A gets something called *Pubkey script* from the most recent block in a block chain (Let’s call it PubkeyScript 1). Again, A uses something which is also called *Pubkey script* using the public key of B. (Let’s call it PubkeyScript 2) After that, A types a message “A sends 1btc to B”. Now, using A’s private key, convert the PubkeyScript1 to something called *signature*. Now, a chunk of signature and A’s public key and PubkeyScipt2 and the message “A sends 1btc to B” is called a *transaction*.

Am I understanding it correctly?

**Tags:** transactions, block


---

## 2 answers

### Answer by username_1 on 2018-01-14. Score: 3 | Accepted answer

I try to explain it, that no coding is required :-) Taking more of a process view...

**Assembly and sending of a tx:**

the wallet software of A looks up it's internal database, if there is a transaction with required amount of 1 BTC on it. If yes, it then looks up this transaction's details in the blockchain, and finds in this transaction the pk script (spending condition), and assembles a new transaction, which shall move the funds to B's address. The wallet software then signs a hash of this transaction. The signature of this hash and the public key are placed in the [scriptsig] field of the transaction. So the final transaction contains the previous tx hash, signature and pubkey, and also an output section, with a pub key script (for B's target address) and the amount. That's what the picture shows.
The transaction is then sent to the network.

**Transaction Verification:**

In the network are verifying nodes, that check for validity of the tx. Amongst others, these nodes check that you have the right to spend the funds. They take the current tx' sigscript (`<signature>` and `<public key>`), and from the previous tx the output script (pubkey script). Then basically two comparisons take place:

> 1.) can the public key of the previous tx' sigscript be hashed to the same value as the presented hash in the current tx' pubkey script?
>
> 2.) is the signature a valid signature for the public key

With the first check, it is assured, that the current transaction moves the funds to the previously defined target address. And with the second check it is verified, if the signature aligns to the presented public key.

For the second test: the wallet software creates a signature, which requires the private key of the owner of the public address. The private key is used to sign the hash of the current transaction.

The picture you provided has a presentation of the parts to create the spending tx. Not the verifying part. That makes it a bit more complex to derive functionality... I had a very good reading with Ken Shirrif's article here:

<http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html>

and also (of course) Andreas' book "Mastering Bitcoin" (Second Edition), which is also online available.


---

### Answer by username_2 on 2018-01-14. Score: 2

Some of your understanding is not entirely correct. I will explain it with a series of question

> What exactly is a transaction? What are its components?

A transaction is a statement of transfer of value from one account(e.g Alice) to another account(e.g Bob). In bitcoin to transfer an amount, x Alice needs to first prove to the community that she has at least x amount with her. This proves in bitcoin is achieved by showing the whole community a previous transaction where Alice has received x(or more) amounts. Observe that it is even possible that Alice has received x amount from multiple transactions combined in which case Alice needs to give a list of the previous transaction which is called as **inputs** transaction.

Assume that if Alice has B bitcoins where B is greater than x, then Alice needs to send the change amount back to itself and x to bob. Alice can form this list out all the receiver's address with the corresponding amount which is called as **outputs** of a transaction.

> What are Pubkey Scripts in the diagram?

Bitcoin and several other cryptocurrencies provide us with an option to mention some conditions under which a transaction can be spent. Pubkey Scripts are nothing but these conditions. Example of Pubkey Scripts is "Only Alice is allowed to spend this with her signature", under which case Alice needs to show a legitimate signature to spend the transaction.

In your case, PubkeyScript1 contains the condition under which Alice is eligible to spend the transaction and PubkeyScript2 contains the condition which bob must satisfy to spend the transaction.

> **Comments:**
> **username_0**: What is “txn”? {}{}{}  
> **username_2**: "txn" is the short form of transaction. It is very standard. apologies.  

---

