<p><code>Verify()</code> verifies if the transaction is properly signed.  </p>

<blockquote>
  <p>Since Verify() doesn't really tell us if a transaction will successfully propagate </p>
</blockquote>

<p>It is either untrue or you found a bug.  </p>

<p><code>node.SendMessage(new TxPayload(tx));</code> should be perfect. However Stratis is currently building a <a href="https://github.com/stratisproject/StratisBitcoinFullNode/" rel="nofollow noreferrer">Bitcoin .NET fullnode,</a> with the lead of Nicolas Dorier, NBitcoin's creator, so you should be sure the method they are using is up to date. <a href="https://github.com/stratisproject/StratisBitcoinFullNode/blob/34e00064487ad96d903e8b4ca6a67f6ce3a3d553/Stratis.Bitcoin.Tests/NodeBuilder.cs" rel="nofollow noreferrer">In their tests,</a> they are doing it a little differently:  </p>

<pre><code>node.VersionHandshake();
node.SendMessageAsync(new InvPayload(transaction));
node.SendMessageAsync(new TxPayload(transaction));
node.PingPong();
</code></pre>

<p>I cannot explain why two <code>SendMessageAsync</code> and <code>PingPong</code> is there. You might want to figure out.  </p>

<p>To make sure you might want to ask some other nodes if they have the transaction in their mempool you are connected to, to check the propagation.
Like this:  </p>

<pre><code>bool broadcasted = false;
foreach(var txid in node.GetMempool())
{
    if(txid.Equals(tx.GetHash()))
    {
        broadcasted = true;
    }
}  
</code></pre>

<p>Alternatively you can ask your node only. I strongly suspect the transaction would not get into your (Bitcoin Core) mempool if there is something wrong, but you should not rely on that. Theory not always mimics practice.  </p>

<p><strong>Privacy concerns:</strong> if you broadcast a transaction without Tor, interested parties can note it and come to conclusions.  </p>

CC BY-SA 3.0
2017-02-13T16:27:44.630Z
I was able to propagate a transaction to the testnet that didn't properly verify. If you would like to view it, here is the hash: 
e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f0158ae5
rosstripi
CC BY-SA 3.0
2017-02-13T21:57:32.023Z
I cannot find it:  
https://testnet.smartbit.com.au/tx/e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f015%E2%80%8C%E2%80%8B8ae5  
http://tbtc.blockr.io/tx/info/e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f015‌​8ae5
nopara73
CC BY-SA 3.0
2017-02-13T22:00:46.150Z
I can just speculate at this point, but maybe the node you "propagated to" does not check the validity of the transaction, but when it wanted to propagate it further, other nodes rejected it?
nopara73
CC BY-SA 3.0
2017-02-13T22:02:15.733Z
It should accept the transaction: I'm sending it to myself, so mine is the only key needed.

Also, I'm seeing that the above transaction did go through: [transaction here](https://www.blocktrail.com/tBTC/tx/e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f0158ae5)
rosstripi
CC BY-SA 3.0
2017-02-13T22:06:11.450Z
It did not get propagated to the network, block explorers doesn't find it. Sending to yourself happens to the same way as sending to everyone else. You have to propagate the transaction through the whole network and it has to be stored by every full-node. I'm not sure what's going on at you locally.
nopara73
CC BY-SA 3.0
2017-02-13T22:50:24.007Z
@rossbot Apparently when you copypaste the transactionid from your first comment some magic changes it. From the `f015` it inserts 2 `??` when I paste it. (Win7, not sure that matters). This is why I did not see the transactions on the above links.
nopara73
CC BY-SA 3.0
2017-02-13T22:51:25.430Z
To sum up, yes, you propagated a transaction that NBitcoin couldn't verify. That's strange.
nopara73
CC BY-SA 3.0
2017-02-11T04:40:49.067Z
2017-02-11T04:40:49.067Z
nopara73
<p>So I am creating a transaction using TransactionBuilder like this:</p>

<pre><code>var builder = new TransactionBuilder();
Transaction tx = builder
  .AddCoins(coins)
  .AddKeys(privateKeys)
  .Send(recipientAddress, Money.Coins(amount))
  .SetChange(changeAddress)
  .SendFees(Money.Coins(fee))
  .BuildTransaction(sign: true);

Boolean verified = builder.Verify(tx);
</code></pre>

<p>And then I propagate it to the network like so:</p>

<pre><code>using (var node = Node.ConnectToLocal(network)) 
{
    node.VersionHandshake(); 

    node.SendMessage(new InvPayload(InventoryType.MSG_TX, tx.GetHash()));

    node.SendMessage(new TxPayload(tx));
    Thread.Sleep(500); 
}
</code></pre>

<p>I have two questions:</p>

<ol>
<li><p>What does the <code>builder.Verify(tx)</code> even tell us? It returns a boolean, but sometimes I can propagate transactions that returned <code>false</code>. What does verify mean/do?</p></li>
<li><p>Since <code>Verify()</code> doesn't really tell us if a transaction will successfully propagate, how do I determine when a transaction made using TransactionBuilder will or won't propagate to the network?</p></li>
</ol>

<c#><nbitcoin><transaction-propagation>
How to determine if transaction is going to propagate?
rosstripi
# How to determine if transaction is going to propagate?

(Asked by: username_0 on 2017-02-11)

So I am creating a transaction using TransactionBuilder like this:

```
var builder = new TransactionBuilder();
Transaction tx = builder
  .AddCoins(coins)
  .AddKeys(privateKeys)
  .Send(recipientAddress, Money.Coins(amount))
  .SetChange(changeAddress)
  .SendFees(Money.Coins(fee))
  .BuildTransaction(sign: true);

Boolean verified = builder.Verify(tx);

```

And then I propagate it to the network like so:

```
using (var node = Node.ConnectToLocal(network)) 
{
    node.VersionHandshake(); 

    node.SendMessage(new InvPayload(InventoryType.MSG_TX, tx.GetHash()));

    node.SendMessage(new TxPayload(tx));
    Thread.Sleep(500); 
}

```

I have two questions:

1. What does the `builder.Verify(tx)` even tell us? It returns a boolean, but sometimes I can propagate transactions that returned `false`. What does verify mean/do?
2. Since `Verify()` doesn't really tell us if a transaction will successfully propagate, how do I determine when a transaction made using TransactionBuilder will or won't propagate to the network?

**Tags:** c#, nbitcoin, transaction-propagation


---

## 1 answers

### Answer by username_1 on 2017-02-11. Score: 2

`Verify()` verifies if the transaction is properly signed.

> Since Verify() doesn't really tell us if a transaction will successfully propagate

It is either untrue or you found a bug.

`node.SendMessage(new TxPayload(tx));` should be perfect. However Stratis is currently building a [Bitcoin .NET fullnode,](https://github.com/stratisproject/StratisBitcoinFullNode/) with the lead of Nicolas Dorier, NBitcoin's creator, so you should be sure the method they are using is up to date. [In their tests,](https://github.com/stratisproject/StratisBitcoinFullNode/blob/34e00064487ad96d903e8b4ca6a67f6ce3a3d553/Stratis.Bitcoin.Tests/NodeBuilder.cs) they are doing it a little differently:

```
node.VersionHandshake();
node.SendMessageAsync(new InvPayload(transaction));
node.SendMessageAsync(new TxPayload(transaction));
node.PingPong();

```

I cannot explain why two `SendMessageAsync` and `PingPong` is there. You might want to figure out.

To make sure you might want to ask some other nodes if they have the transaction in their mempool you are connected to, to check the propagation.
Like this:

```
bool broadcasted = false;
foreach(var txid in node.GetMempool())
{
    if(txid.Equals(tx.GetHash()))
    {
        broadcasted = true;
    }
}  

```

Alternatively you can ask your node only. I strongly suspect the transaction would not get into your (Bitcoin Core) mempool if there is something wrong, but you should not rely on that. Theory not always mimics practice.

**Privacy concerns:** if you broadcast a transaction without Tor, interested parties can note it and come to conclusions.

> **Comments:**
> **username_0**: I was able to propagate a transaction to the testnet that didn't properly verify. If you would like to view it, here is the hash:  e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f0158ae5  
> **username_1**: I cannot find it:   https://testnet.smartbit.com.au/tx/e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f015%E2%80%8C%E2%80%8B8ae5   http://tbtc.blockr.io/tx/info/e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f015‌​8ae5  
> **username_1**: I can just speculate at this point, but maybe the node you "propagated to" does not check the validity of the transaction, but when it wanted to propagate it further, other nodes rejected it?  
> **username_0**: It should accept the transaction: I'm sending it to myself, so mine is the only key needed.  Also, I'm seeing that the above transaction did go through: [transaction here](https://www.blocktrail.com/tBTC/tx/e98118de943d124e21d52dd6a05528eff18f199e3eea6ae149d97ce3f0158ae5)  
> **username_1**: It did not get propagated to the network, block explorers doesn't find it. Sending to yourself happens to the same way as sending to everyone else. You have to propagate the transaction through the whole network and it has to be stored by every full-node. I'm not sure what's going on at you locally.  
> **username_1**: @rossbot Apparently when you copypaste the transactionid from your first comment some magic changes it. From the `f015` it inserts 2 `??` when I paste it. (Win7, not sure that matters). This is why I did not see the transactions on the above links.  
> **username_1**: To sum up, yes, you propagated a transaction that NBitcoin couldn't verify. That's strange.  

---

