Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: init1 on November 03, 2015, 09:50:15 AM



Title: raw tx and change address
Post by: init1 on November 03, 2015, 09:50:15 AM
Hello

Want to prepare raw TX with change address.
according to the manual https://bitcoin.org/en/developer-examples#simple-raw-transaction

input had 50.0000 bitcoins and our output ($NEW_ADDRESS) is being paid 49.9999 bitcoins, so the transaction will include a fee of 0.0001 bitcoins. If we had paid $NEW_ADDRESS only 10 bitcoins with no other changes to this transaction, the transaction fee would be a whopping 40 bitcoins

I should add change address if I want to save change.

prepared Raw tx like this
Code:
./bitcoin-cli createrawtransaction 
'[{"txid":"fba4b0a1e11b68c587aae3578844d68131c807913767a1efc9a699d38ecd9f06",
"vout":1,
"scriptPubKey":"a914e8fa0f97c663ba132bd81e6d657c46825d390e6c87",
"redeemscript":"524104d9546728bb1d1bf309ef3c2c7278d8d306052ecf7dc81443f16e75ae607099dfcfc573a3e71553bd8321d91c209bab03aa999befa6e77734c0f4dd34ef78ebfd41041050ff637a97fa462dffa19d0bc013869f6231895019bd9f263a0a55a067665cfca4473aab1dc38e8aecf359e23ce6bb35ff900bc84fdd890a3b982ea50dd92f4104e086dce7893384cbfa89fbbf7d33de3f1ee01279a1e9810d952f1c440e91fc7ee7cb9cf070dfbdee397e123c363d140221e81610b7bd695905fbf198edfd71a153ae"}]'
 '{"143UX8t7LNiAf1dNPqyWDYQ1Gedbk27R7b":0.0001}'

Could you please share example how to prepare raw tx with address for the change and fee  ?

Thanks.


Title: Re: raw tx and change address
Post by: achow101 on November 03, 2015, 12:52:17 PM
Just add a second output the same way you added the first output.


Title: Re: raw tx and change address
Post by: fbueller on November 05, 2015, 03:38:02 PM
If you were doing:

in: 50 coin input,
fee: 0.0001
out: 10
 39.9999 change

Quote
...snippet...
'{"143UX8t7LNiAf1dNPqyWDYQ1Gedbk27R7b":"10","your-change-address", "39.9999"}'

And, remember to never use floats (BTC amounts) in additions, subtractions - use satoshis instead.