<p>I answered my own question.</p>

<p>I used the following PHP code...</p>

<pre><code>$savings = 0.001;
$txfee = 0.0001;
$amount = floatval(($bitcoind->getbalance() - $savings) - $txfee); // getbalance() returns 0.005
$outputAddr = [
    '1GAnaq3atnKkxFsUC4Vky8Ysb751LbxHSC' => $amount, // wallet 1 address
    '122ExHr92bEgJbepSHmQCruCRR3YRR6dx5' => $savings // wallet 2 address
];

$rawtxUnspent = [];
$unspent = $bitcoind->listunspent();
foreach($unspent as $tx) {
    array_push($rawtxUnspent, [
        'txid' => $tx['txid'],
        'vout' => $tx['vout']
    ]);
}

$rawtx = $bitcoind->createrawtransaction($rawtxUnspent, $outputAddr);
$signedtx = $bitcoind->signrawtransaction($rawtx);
$senttx = $bitcoind->sendrawtransaction($signedtx['hex']);

$senttx === false ? print $bitcoind->error : var_dump($senttx);</code>
</pre>

<p>and got this output...</p>

<p><code>string(64) "bae6d6978da7a50422a943ac42017c64478169ce87a264d7cedbaa5a869558b4"</code></p>

<p>The transaction is confirmed and worked exactly as I hoped. :)</p>

<p><a href="https://blockchain.info/tx/bae6d6978da7a50422a943ac42017c64478169ce87a264d7cedbaa5a869558b4" rel="nofollow">https://blockchain.info/tx/bae6d6978da7a50422a943ac42017c64478169ce87a264d7cedbaa5a869558b4</a></p>

CC BY-SA 3.0
2015-06-14T06:33:12.360Z
2015-06-14T06:38:37.577Z
2015-06-14T06:38:37.577Z
maff1989
<p>Sorry if this has already been asked; Stack Exchange didn't have this exact question in the "related" field.</p>

<p>Let's say I have two bitcoin wallets. Somebody sends wallet 1 a transaction of 0.5 BTC.</p>

<p>What I am wondering is if I can take that transaction and create a new one, where I'm sending 0.4 BTC to that same address in wallet 1 with the original 0.5 BTC (the one listed in the "receive" data in the UTXO), and sending the 0.1 BTC change to an address in wallet 2.</p>

<p>I would think this is possible since the address in wallet 2 referenced as part of the second transaction would then have the funds available once the transaction confirms in the block chain.</p>

<p>I just don't know enough about Bitcoin's code to know for sure if this won't cause some sort of hiccup, as my general conception of "transaction change" is that an address local to the wallet, in this case wallet 1, is generated for capturing the change from the transaction to avoid overspending in transaction fees.</p>

<p>Using a separate wallet's address as the change may well break something in the code that accounts for the total balance of the first wallet.</p>

<p>This is why I need an expert to help me out here. Too many unknown outcomes for me!</p>

<bitcoind>
Automatic savings account using 2 wallets?
maff1989
# Automatic savings account using 2 wallets?

(Asked by: username_0 on 2015-06-14)

Sorry if this has already been asked; Stack Exchange didn't have this exact question in the "related" field.

Let's say I have two bitcoin wallets. Somebody sends wallet 1 a transaction of 0.5 BTC.

What I am wondering is if I can take that transaction and create a new one, where I'm sending 0.4 BTC to that same address in wallet 1 with the original 0.5 BTC (the one listed in the "receive" data in the UTXO), and sending the 0.1 BTC change to an address in wallet 2.

I would think this is possible since the address in wallet 2 referenced as part of the second transaction would then have the funds available once the transaction confirms in the block chain.

I just don't know enough about Bitcoin's code to know for sure if this won't cause some sort of hiccup, as my general conception of "transaction change" is that an address local to the wallet, in this case wallet 1, is generated for capturing the change from the transaction to avoid overspending in transaction fees.

Using a separate wallet's address as the change may well break something in the code that accounts for the total balance of the first wallet.

This is why I need an expert to help me out here. Too many unknown outcomes for me!

**Tags:** bitcoind


---

## 1 answers

### Answer by username_0 on 2015-06-14. Score: 1 | Accepted answer

I answered my own question.

I used the following PHP code...

```
$savings = 0.001;
$txfee = 0.0001;
$amount = floatval(($bitcoind->getbalance() - $savings) - $txfee); // getbalance() returns 0.005
$outputAddr = [
    '1GAnaq3atnKkxFsUC4Vky8Ysb751LbxHSC' => $amount, // wallet 1 address
    '122ExHr92bEgJbepSHmQCruCRR3YRR6dx5' => $savings // wallet 2 address
];

$rawtxUnspent = [];
$unspent = $bitcoind->listunspent();
foreach($unspent as $tx) {
    array_push($rawtxUnspent, [
        'txid' => $tx['txid'],
        'vout' => $tx['vout']
    ]);
}

$rawtx = $bitcoind->createrawtransaction($rawtxUnspent, $outputAddr);
$signedtx = $bitcoind->signrawtransaction($rawtx);
$senttx = $bitcoind->sendrawtransaction($signedtx['hex']);

$senttx === false ? print $bitcoind->error : var_dump($senttx);

```

and got this output...

`string(64) "bae6d6978da7a50422a943ac42017c64478169ce87a264d7cedbaa5a869558b4"`

The transaction is confirmed and worked exactly as I hoped. :)

<https://blockchain.info/tx/bae6d6978da7a50422a943ac42017c64478169ce87a264d7cedbaa5a869558b4>


---

