<p>On the <a href="http://bitcoin.it" rel="nofollow">bitcoin wiki</a>, there is rather complete list of validation checks that are done by the Satoshi client: <a href="https://en.bitcoin.it/wiki/Protocol_rules" rel="nofollow">Protocol_rules</a>.</p>

<p>There is a <a href="https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages" rel="nofollow">section</a> specifically about transaction checking as well.</p>

CC BY-SA 3.0
2012-02-05T05:03:02.867Z
2013-06-05T21:06:06.437Z
2013-06-05T21:06:06.437Z
Pieter Wuille
<p>I recommend using the <a href="https://bitcore.io" rel="nofollow noreferrer">bitcore library</a> built by BitPay which has a <a href="https://bitcore.io/api/lib/transaction#Transaction+verify" rel="nofollow noreferrer">transaction.verify()</a> function that works well. </p>

<p>You can also attempt to decode a transaction hex using this <a href="https://live.blockcypher.com/btc/decodetx/" rel="nofollow noreferrer">blockcypher tool</a> and if it decodes properly and all of the components of a valid transaction are there, then your transaction should be good to go </p>

CC BY-SA 3.0
2018-03-26T16:04:55.023Z
2018-03-26T16:04:55.023Z
Loourr
<blockquote>
  <p>I understand there are a couple things that need to be checked for a transaction to be valid - the previous transaction had to be correct, no OP can invalidate the transaction, etc, but is there a complete list on what one needs to check in order to know if a transaction is valid?</p>
</blockquote>

<p>You check the chain, if it goes all the way back to a generation, it is valid. You must wait for a confirmation to get it set in stone.</p>

<blockquote>
  <p>What steps does the protocol require a client to go through to check if the transaction is valid?</p>
</blockquote>

<p><a href="https://github.com/bitcoin/bitcoin/tree/master/src" rel="nofollow">https://github.com/bitcoin/bitcoin/tree/master/src</a></p>

CC BY-SA 3.0
2012-04-05T11:08:46.023Z
Well, quite more than "a [single] confirmation" to "set [it] in stone".
o0'.
CC BY-SA 3.0
2012-05-05T12:06:20.973Z
Though you're technically correct in saying that you need to check the chain all the way back to generation, this is not useful. Clients only store the part of the chain they've verified to be valid, and the only thing they need to check is whether it correctly connects to the transactions therein. Also, transactions are never entirely set in stone, but each confirmation significantly reduces the chance for reverting further.
Pieter Wuille
CC BY-SA 3.0
2012-05-05T16:59:58.050Z
There has not been and there will likely not be a single Chain Fork attack. It is not worth it, it is unlikely, it has not happened. fThe only ever attack to the Bitcoin Client or Chain was an Integer Overflow back at the beginnings of time.
Fabián Heredia Montiel
CC BY-SA 3.0
2012-01-05T03:57:58.387Z
2012-01-05T03:57:58.387Z
Fabián Heredia Montiel
<p>I understand there are a couple things that need to be checked for a transaction to be valid - the previous transaction had to be correct, no OP can invalidate the transaction, etc, but is there a complete list on what one needs to check in order to know if a transaction is valid?</p>

<p>For example, does the transaction need to have a specific structure in order to be spent, like the script from TxIn needs to compile to the encoded message, and the TxOut script needs to properly run OP_Checksig on that particular message? If not, one could simply drop the message from TxIn, push their own malicious message and run OP_Checksig on that.</p>

<p>What steps does the protocol require a client to go through to check if the transaction is valid?</p>

CC BY-SA 3.0
2012-01-05T02:21:33.267Z
It's not clear what you're asking. By "valid" do you just mean that the client won't consider a block invalid if it contains that transaction? Or by "valid" do you mean the default client will include that transaction in blocks it generates? Or by "valid" you mean the default client will relay it to other nodes? Or something else? There are different checks on transactions to decide if they are "valid" for a number of different purposes. For example, consider a transaction that spends coins not yet available but that could become available. In some senses, that's valid. In some, not yet.
David Schwartz
CC BY-SA 3.0
2012-01-05T10:51:51.480Z
@DavidSchwartz I suppose all of the above would be useful, but mainly I was thinking about including the transactions in the block.
ThePiachu
<transactions><client><development><protocol><script>
How to know if a transaction is valid?
ThePiachu
# How to know if a transaction is valid?

(Asked by: username_0 on 2012-01-05)

I understand there are a couple things that need to be checked for a transaction to be valid - the previous transaction had to be correct, no OP can invalidate the transaction, etc, but is there a complete list on what one needs to check in order to know if a transaction is valid?

For example, does the transaction need to have a specific structure in order to be spent, like the script from TxIn needs to compile to the encoded message, and the TxOut script needs to properly run OP\_Checksig on that particular message? If not, one could simply drop the message from TxIn, push their own malicious message and run OP\_Checksig on that.

What steps does the protocol require a client to go through to check if the transaction is valid?

**Tags:** transactions, client, development, protocol, script

> **Comments:**
> **username_1**: It's not clear what you're asking. By "valid" do you just mean that the client won't consider a block invalid if it contains that transaction? Or by "valid" do you mean the default client will include that transaction in blocks it generates? Or by "valid" you mean the default client will relay it to other nodes? Or something else? There are different checks on transactions to decide if they are "valid" for a number of different purposes. For example, consider a transaction that spends coins not yet available but that could become available. In some senses, that's valid. In some, not yet.  
> **username_0**: @username_1 I suppose all of the above would be useful, but mainly I was thinking about including the transactions in the block.  

---

## 3 answers

### Answer by username_2 on 2012-02-05. Score: 3

On the [bitcoin wiki](http://bitcoin.it), there is rather complete list of validation checks that are done by the Satoshi client: [Protocol\_rules](https://en.bitcoin.it/wiki/Protocol_rules).

There is a [section](https://en.bitcoin.it/wiki/Protocol_rules#.22tx.22_messages) specifically about transaction checking as well.


---

### Answer by username_3 on 2018-03-26. Score: 0

I recommend using the [bitcore library](https://bitcore.io) built by BitPay which has a [transaction.verify()](https://bitcore.io/api/lib/transaction#Transaction+verify) function that works well.

You can also attempt to decode a transaction hex using this [blockcypher tool](https://live.blockcypher.com/btc/decodetx/) and if it decodes properly and all of the components of a valid transaction are there, then your transaction should be good to go


---

### Answer by username_4 on 2012-01-05. Score: -1

> I understand there are a couple things that need to be checked for a transaction to be valid - the previous transaction had to be correct, no OP can invalidate the transaction, etc, but is there a complete list on what one needs to check in order to know if a transaction is valid?

You check the chain, if it goes all the way back to a generation, it is valid. You must wait for a confirmation to get it set in stone.

> What steps does the protocol require a client to go through to check if the transaction is valid?

<https://github.com/bitcoin/bitcoin/tree/master/src>

> **Comments:**
> **username_5**: Well, quite more than "a [single] confirmation" to "set [it] in stone".  
> **username_2**: Though you're technically correct in saying that you need to check the chain all the way back to generation, this is not useful. Clients only store the part of the chain they've verified to be valid, and the only thing they need to check is whether it correctly connects to the transactions therein. Also, transactions are never entirely set in stone, but each confirmation significantly reduces the chance for reverting further.  
> **username_4**: There has not been and there will likely not be a single Chain Fork attack. It is not worth it, it is unlikely, it has not happened. fThe only ever attack to the Bitcoin Client or Chain was an Integer Overflow back at the beginnings of time.  

---

