<p>This looks like an implementation choice of the <code>PeerGroup.broadcastTransaction</code> method of bitcoinj. </p>

<p>If you send a transaction out to one or more peers, there is no guarantee that any of those peers will forward them on to others, and no way to verify it without having another node somewhere else on the bitcoin network listening for it (or listening to it from the same node but from different peers). You can only attempt to have some level of confidence that the transaction has been broadcast by sending it to multiple peers.</p>

<p>The <code>broadcastTransaction</code> method appears to have some confidence calculation in it, and probably does not complete the promise unless the confidence is met. I've not explored the details of it, but I'd suspect you're perhaps not connected to enough peers for it to have the confidence. Are you only connected to one peer perhaps? Maybe you need a longer timeout? Check the details of how the broadcast is implemented and you might figure it out.</p>

CC BY-SA 4.0
2020-08-19T00:37:59.450Z
If you're only connected to one peer, there's not much it can do. That peer won't send the transaction back to you. So until it's mined (which obviously will typically take much more than 20 seconds) it can't get any confidence at all.
David Schwartz
CC BY-SA 4.0
2020-03-21T22:15:56.247Z
2020-03-21T22:15:56.247Z
Mark H
<p>I use bitcoinj to create the following method to broadcast a raw transacion in testnet, and I did see on bitcoin explorer that it has been broadcast. But even the transaction has been already broadcast, it always return false message, please help me to solve this issue, I don't know if there is a problem when sync with the peer or if my broadcast method is wrong.</p>

<pre><code>//sync with the peer
static WalletAppKit kit = new WalletAppKit(params, new File("."), "sendrequest-example");
kit.startAsync();
kit.awaitRunning();

//transaction broadcast method
public static boolean broadcastTransaction (Transaction tx) {
        System.out.println("Broadcast transaction: ");
        System.out.println(tx);
        try {
            TransactionBroadcast broadcast = kit.peerGroup().broadcastTransaction(tx);
            broadcast.future().get(20,TimeUnit.SECONDS);
            System.out.println(tx.getHash() + "broadcasted successfully!");
            return true;
        } catch (Exception e) {
            System.out.println("e.getMessage() = " + e.getMessage());
        }
        return false;
    }
</code></pre>

<p>The false message is always as following, although the transaction has been indeed broadcast.</p>

<pre><code>e.getMessage() = Waited 20 seconds (plus 1985971 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@20d525[status=PENDING]
</code></pre>

<pre><code>e.getMessage() = Waited 20 seconds (plus 4214583 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@38afe297[status=PENDING]
</code></pre>

<bitcoinj><java><implementation>
Error message still returned after transaction was indeed broadcast
Oiiiwk
# Error message still returned after transaction was indeed broadcast

(Asked by: username_0 on 2020-03-20)

I use bitcoinj to create the following method to broadcast a raw transacion in testnet, and I did see on bitcoin explorer that it has been broadcast. But even the transaction has been already broadcast, it always return false message, please help me to solve this issue, I don't know if there is a problem when sync with the peer or if my broadcast method is wrong.

```
//sync with the peer
static WalletAppKit kit = new WalletAppKit(params, new File("."), "sendrequest-example");
kit.startAsync();
kit.awaitRunning();

//transaction broadcast method
public static boolean broadcastTransaction (Transaction tx) {
        System.out.println("Broadcast transaction: ");
        System.out.println(tx);
        try {
            TransactionBroadcast broadcast = kit.peerGroup().broadcastTransaction(tx);
            broadcast.future().get(20,TimeUnit.SECONDS);
            System.out.println(tx.getHash() + "broadcasted successfully!");
            return true;
        } catch (Exception e) {
            System.out.println("e.getMessage() = " + e.getMessage());
        }
        return false;
    }

```

The false message is always as following, although the transaction has been indeed broadcast.

```
e.getMessage() = Waited 20 seconds (plus 1985971 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@20d525[status=PENDING]

```

```
e.getMessage() = Waited 20 seconds (plus 4214583 nanoseconds delay) for com.google.common.util.concurrent.SettableFuture@38afe297[status=PENDING]

```

**Tags:** bitcoinj, java, implementation


---

## 1 answers

### Answer by username_1 on 2020-03-21. Score: 2

This looks like an implementation choice of the `PeerGroup.broadcastTransaction` method of bitcoinj.

If you send a transaction out to one or more peers, there is no guarantee that any of those peers will forward them on to others, and no way to verify it without having another node somewhere else on the bitcoin network listening for it (or listening to it from the same node but from different peers). You can only attempt to have some level of confidence that the transaction has been broadcast by sending it to multiple peers.

The `broadcastTransaction` method appears to have some confidence calculation in it, and probably does not complete the promise unless the confidence is met. I've not explored the details of it, but I'd suspect you're perhaps not connected to enough peers for it to have the confidence. Are you only connected to one peer perhaps? Maybe you need a longer timeout? Check the details of how the broadcast is implemented and you might figure it out.

> **Comments:**
> **username_2**: If you're only connected to one peer, there's not much it can do. That peer won't send the transaction back to you. So until it's mined (which obviously will typically take much more than 20 seconds) it can't get any confidence at all.  

---

