<p>I'm trying to send all coins from my accounts (generated by HD Wallet) to one account with this code:</p>
<pre><code>fun sendAllFundsOnAddress(address: String) {
        val receiver = Address.fromString(params, address)
        val tx = Transaction(params)

        val balance = Coin.valueOf(walletAppKit.wallet().unspents.map { it.value.value }.sum())
        tx.addOutput(balance, receiver)

        walletAppKit.wallet().unspents.forEach {
            val key = walletAppKit.wallet().findKeyFromAddress(Address.fromString(params, it.scriptPubKey.getToAddress(params).toString()))
            tx.addSignedInput(it.outPointFor, it.scriptPubKey, key, Transaction.SigHash.ALL, true)
        }

        walletAppKit.wallet().commitTx(tx)
        val sendRequest = SendRequest.forTx(tx)
        walletAppKit.wallet().completeTx(sendRequest)
    }
</code></pre>
<p>But I get NullPointerException, while it calculates witness (in input signing process).</p>
<p>Could you give any ideas, what's wrong?</p>

CC BY-SA 4.0
2021-04-03T02:54:28.183Z
Hi snitron, do you perhaps have the stacktrace of the error? It may help potential answerers to narrow down the issue.
Murch
<bitcoinj>
How to make transaction with many inputs and one output in BitcoinJ?
snitron
# How to make transaction with many inputs and one output in BitcoinJ?

(Asked by: username_0 on 2021-04-02)

I'm trying to send all coins from my accounts (generated by HD Wallet) to one account with this code:
fun sendAllFundsOnAddress(address: String) {
        val receiver = Address.fromString(params, address)
        val tx = Transaction(params)

        val balance = Coin.valueOf(walletAppKit.wallet().unspents.map { it.value.value }.sum())
        tx.addOutput(balance, receiver)

        walletAppKit.wallet().unspents.forEach {
            val key = walletAppKit.wallet().findKeyFromAddress(Address.fromString(params, it.scriptPubKey.getToAddress(params).toString()))
            tx.addSignedInput(it.outPointFor, it.scriptPubKey, key, Transaction.SigHash.ALL, true)
        }

        walletAppKit.wallet().commitTx(tx)
        val sendRequest = SendRequest.forTx(tx)
        walletAppKit.wallet().completeTx(sendRequest)
    }

But I get NullPointerException, while it calculates witness (in input signing process).
Could you give any ideas, what's wrong?

**Tags:** bitcoinj

> **Comments:**
> **username_1**: Hi username_0, do you perhaps have the stacktrace of the error? It may help potential answerers to narrow down the issue.  

---

## 0 answers

