<blockquote>
  <p>However, what is stopping someone, for example the recipient of the original transaction, to simply send in the same exact transaction with the same data and signature?</p>
</blockquote>

<p>Bitcoin does not have the concept of account balance but works on the concept of unspent transaction outputs (UTXOs). Each output of a transaction (except <code>OP_RETURN</code> ones) lead to the creation of a separate UTXO. When you create transactions in Bitcoin, you consume these UTXOs in entirety and create separate UTXOs. This is done by referencing the outpoint (<code>txid</code> and <code>n</code>) from which you 'earnt' these UTXO. For example, if you control 2 UTXOs (1 BTC and 0.5 BTC), and you want to send your friend 1.25 BTC, you would have to consume both your UTXOs and send the remaining change of 0.25 BTC to yourself (neglecting tx fees). So if the recipient of a transaction output tries to broadcast the same transaction again, the Bitcoin nodes when verifying the transaction would find that these utxos do not exist and hence the transaction is invalid. </p>

<p>When full nodes start syncing from the Genesis block, they start to build the database of all these UTXOs. Every transaction involves removing spent UTXOs and adding new ones. These database is stores in <code>chainstate</code> directory and aggressively cached in memory. </p>

CC BY-SA 4.0
2019-06-19T22:42:36.143Z
Technically OP_RETURN outputs are still outputs, they can just be ignored because there is no condition which can make them spendable.
Claris
CC BY-SA 4.0
2019-06-20T06:43:17.867Z
@Anonymous yeah true. they are outputs but not unspent outputs. So no need to add them to the UTXO database
Ugam Kamat
CC BY-SA 4.0
2019-06-19T20:57:57.000Z
2019-06-19T20:57:57.000Z
Ugam Kamat
<p>I understand that when creating a transaction, you send in data, the hash of that data, and a signature that is created using the hash of the data and your private key. However, what is stopping someone, for example the recipient of the original transaction, to simply send in the same exact transaction with the same data and signature. Wouldn't this come up as being valid, and therefore make the system insecure? How does Bitcoin solve this problem? </p>

<p>If the answer is a timestamp, how does Bitcoin deal with different transactions coming in at various times, often out of order?</p>

<transactions><signature>
How does Bitcoin makes sure that nobody can duplicate a transaction?
L. Rothman
# How does Bitcoin makes sure that nobody can duplicate a transaction?

(Asked by: username_0 on 2019-06-19)

I understand that when creating a transaction, you send in data, the hash of that data, and a signature that is created using the hash of the data and your private key. However, what is stopping someone, for example the recipient of the original transaction, to simply send in the same exact transaction with the same data and signature. Wouldn't this come up as being valid, and therefore make the system insecure? How does Bitcoin solve this problem?

If the answer is a timestamp, how does Bitcoin deal with different transactions coming in at various times, often out of order?

**Tags:** transactions, signature


---

## 1 answers

### Answer by username_1 on 2019-06-19. Score: 1

> However, what is stopping someone, for example the recipient of the original transaction, to simply send in the same exact transaction with the same data and signature?

Bitcoin does not have the concept of account balance but works on the concept of unspent transaction outputs (UTXOs). Each output of a transaction (except `OP_RETURN` ones) lead to the creation of a separate UTXO. When you create transactions in Bitcoin, you consume these UTXOs in entirety and create separate UTXOs. This is done by referencing the outpoint (`txid` and `n`) from which you 'earnt' these UTXO. For example, if you control 2 UTXOs (1 BTC and 0.5 BTC), and you want to send your friend 1.25 BTC, you would have to consume both your UTXOs and send the remaining change of 0.25 BTC to yourself (neglecting tx fees). So if the recipient of a transaction output tries to broadcast the same transaction again, the Bitcoin nodes when verifying the transaction would find that these utxos do not exist and hence the transaction is invalid.

When full nodes start syncing from the Genesis block, they start to build the database of all these UTXOs. Every transaction involves removing spent UTXOs and adding new ones. These database is stores in `chainstate` directory and aggressively cached in memory.

> **Comments:**
> **username_2**: Technically OP_RETURN outputs are still outputs, they can just be ignored because there is no condition which can make them spendable.  
> **username_1**: @Anonymous yeah true. they are outputs but not unspent outputs. So no need to add them to the UTXO database  

---

