<p>Without verifying the transactions themselves, there's no guarantee that the transactions you get from either method are valid. Nodes can lie about what transactions they have in their mempool, for example, and send you gibberish. On the flip side, nodes also don't have any obligation to send you transactions that they have. There are non-standard transactions, for example, that many nodes simply don't relay, so you have no way to find out about them, but they may still get mined in the next block.</p>

<p>In order to actually verify unconfirmed transactions, you're going to need to be a full node with the entire blockchain stored so you can validate them yourself. There are no guarantees about the behavior of any other node on unconfirmed transactions and assuming that they're valid is simply not a good thing to do from a security perspective.</p>

<p>That said, if you want the largest set of unconfirmed transactions possible, the easiest way is to connect to as many nodes as possible and get whatever transactions they have in their mempools. The <a href="https://en.bitcoin.it/wiki/Protocol_documentation" rel="nofollow">bitcoin network protocol</a> has a lot of very useful commands for this purpose that you can create. Of particular interest are the <code>inv</code> and <code>getdata</code> commands.</p>

<p>Of course, that's exactly what bitcoind already does and it verifies all the transactions to boot, so you'd really honestly be duplicating that exact same function. The big optimization opportunity here would be mostly on choosing the best peers that somehow are "most informed" about unconfirmed transactions. </p>

CC BY-SA 3.0
2015-02-23T03:17:05.910Z
What if i don't accept a transaction if it doesn't exist in at least two different nodes' mempool? I think it lowers the chance of my node to be tricked so i don't have to store entire blockchain.
paddlesteamer
CC BY-SA 3.0
2015-02-23T03:18:15.037Z
It also excludes transactions that are non-standard but might still make it into the blockchain. Eligius pool, for example, does non-standard transactions and it's in their mempool, but hardly anyone relays them.
Jimmy Song
CC BY-SA 3.0
2015-02-22T20:10:46.483Z
2015-02-22T20:10:46.483Z
Jimmy Song
<p>I'm trying to write a node that listens all the bitcoin transactions in real time. I'm considering two ways of doing this: The first one is to check mempools of other nodes periodically and the second one is to act like a relay so that other nodes can broadcast transactions to my node. I'm not keeping any blockchain data so it is out of question for me to verify the transactions. So my question is which one would be more reliable, secure and real time? I think the first one is more reliable because in the second case it's not certain that all transactions will be broadcasted to me but again it seems like there won't be any latency in the second case. What do you think? And also are there some better ways to achieve this?</p>

<p>ps: i don't want to use a third party api, it all should be handled from my node.</p>

<transactions><client><relay><broadcast><mempool>
Best Way to Get Latest Transactions
paddlesteamer
# Best Way to Get Latest Transactions

(Asked by: username_0 on 2015-02-21)

I'm trying to write a node that listens all the bitcoin transactions in real time. I'm considering two ways of doing this: The first one is to check mempools of other nodes periodically and the second one is to act like a relay so that other nodes can broadcast transactions to my node. I'm not keeping any blockchain data so it is out of question for me to verify the transactions. So my question is which one would be more reliable, secure and real time? I think the first one is more reliable because in the second case it's not certain that all transactions will be broadcasted to me but again it seems like there won't be any latency in the second case. What do you think? And also are there some better ways to achieve this?

ps: i don't want to use a third party api, it all should be handled from my node.

**Tags:** transactions, client, relay, broadcast, mempool


---

## 1 answers

### Answer by username_1 on 2015-02-22. Score: 3 | Accepted answer

Without verifying the transactions themselves, there's no guarantee that the transactions you get from either method are valid. Nodes can lie about what transactions they have in their mempool, for example, and send you gibberish. On the flip side, nodes also don't have any obligation to send you transactions that they have. There are non-standard transactions, for example, that many nodes simply don't relay, so you have no way to find out about them, but they may still get mined in the next block.

In order to actually verify unconfirmed transactions, you're going to need to be a full node with the entire blockchain stored so you can validate them yourself. There are no guarantees about the behavior of any other node on unconfirmed transactions and assuming that they're valid is simply not a good thing to do from a security perspective.

That said, if you want the largest set of unconfirmed transactions possible, the easiest way is to connect to as many nodes as possible and get whatever transactions they have in their mempools. The [bitcoin network protocol](https://en.bitcoin.it/wiki/Protocol_documentation) has a lot of very useful commands for this purpose that you can create. Of particular interest are the `inv` and `getdata` commands.

Of course, that's exactly what bitcoind already does and it verifies all the transactions to boot, so you'd really honestly be duplicating that exact same function. The big optimization opportunity here would be mostly on choosing the best peers that somehow are "most informed" about unconfirmed transactions.

> **Comments:**
> **username_0**: What if i don't accept a transaction if it doesn't exist in at least two different nodes' mempool? I think it lowers the chance of my node to be tricked so i don't have to store entire blockchain.  
> **username_1**: It also excludes transactions that are non-standard but might still make it into the blockchain. Eligius pool, for example, does non-standard transactions and it's in their mempool, but hardly anyone relays them.  

---

