<p>Right, figured it out. It's a matter of picking the correct output from the previous transaction and running signInputs. After that it works.</p>

CC BY-SA 3.0
2013-11-18T10:56:17.337Z
2013-11-18T10:56:17.337Z
Carlos
<p>I'm trying to learn a few things about the API. <strong>I've managed to send coins</strong> on testnet via wallet.sendCoins(Peergroup,Address,BigInteger) so I don't think I have a network problem.</p>

<p>Here's what I'm trying to do, assume my wallet has the transaction, a Peergroup already exists and is connected, and the blockstores and such exist:</p>

<pre><code>    Transaction tin = wallet.getTransaction(
            new Sha256Hash("015a7cff7048b622315fe610e9e72347420a5528b938bffc931ddacf24b9ce88"));

    System.out.println("Input transaction: " + tin.toString());

    Transaction t = new Transaction(nwp);

    t.addOutput(Utils.toNanoCoins(4, 10), new Address(nwp, "mmhmMNfBiZZ37g1tgg2t8DDbNoEdqKVxAL"));
    t.addOutput(Utils.toNanoCoins(4, 0), new Address(nwp, "mrtUDRNFuwVPrKgwaGLuc3VvRCVYbayLkC"));

    t.addInput(tin.getOutput(0));
    p.broadcastTransaction(t);
</code></pre>

<p>As you can see, the transaction is trying to spend a <strong>specific</strong> previous transaction of 8.10 incoming by sending 4.10 back to the faucet and 4 back as change.</p>

<p>Unfortunately it doesn't propagate on the network. What do I need to do? I've been trying to follow the code in Wallet.java, but it's pretty complicated. From what I can see it's some checks on the amounts, coin selection, and locks on the coins to be used. Attempts to sign the transaction cause a warning (already signed) and a crash.</p>

<p>Can someone let me know what the minimum necessary steps for creating and sending this transaction are?</p>

<transactions><api><bitcoinj>
BitCoinJ custom transaction
Carlos
# BitCoinJ custom transaction

(Asked by: username_0 on 2013-11-17)

I'm trying to learn a few things about the API. I've managed to send coins on testnet via wallet.sendCoins(Peergroup,Address,BigInteger) so I don't think I have a network problem.
Here's what I'm trying to do, assume my wallet has the transaction, a Peergroup already exists and is connected, and the blockstores and such exist:
    Transaction tin = wallet.getTransaction(
            new Sha256Hash("015a7cff7048b622315fe610e9e72347420a5528b938bffc931ddacf24b9ce88"));

    System.out.println("Input transaction: " + tin.toString());

    Transaction t = new Transaction(nwp);

    t.addOutput(Utils.toNanoCoins(4, 10), new Address(nwp, "mmhmMNfBiZZ37g1tgg2t8DDbNoEdqKVxAL"));
    t.addOutput(Utils.toNanoCoins(4, 0), new Address(nwp, "mrtUDRNFuwVPrKgwaGLuc3VvRCVYbayLkC"));

    t.addInput(tin.getOutput(0));
    p.broadcastTransaction(t);

As you can see, the transaction is trying to spend a specific previous transaction of 8.10 incoming by sending 4.10 back to the faucet and 4 back as change.
Unfortunately it doesn't propagate on the network. What do I need to do? I've been trying to follow the code in Wallet.java, but it's pretty complicated. From what I can see it's some checks on the amounts, coin selection, and locks on the coins to be used. Attempts to sign the transaction cause a warning (already signed) and a crash.
Can someone let me know what the minimum necessary steps for creating and sending this transaction are?

**Tags:** transactions, api, bitcoinj


---

## 1 answers

### Answer by username_0 on 2013-11-18. Score: 1

Right, figured it out. It's a matter of picking the correct output from the previous transaction and running signInputs. After that it works.


---

