Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: DannyHamilton on March 27, 2013, 11:41:40 AM



Title: Assistance please regarding createrawtransaction
Post by: DannyHamilton on March 27, 2013, 11:41:40 AM
Given the following usage from https://en.bitcoin.it/wiki/Raw_Transactions

Quote
createrawtransaction [{"txid":txid,"vout":n},...] {address:amount,...}

I'm assuming I can type the following in the Bitcoin-Qt console window:

Quote
createrawtransaction [{\"txid\":\"7e252ce7176a7a585ed99d4a6ecfb005f34b34574fc933748113a7aa755f824d\",\"vout\":1}] {\"13YteEVecArYiRETzyccPvG7nrTrjg1mhD\":5.40537687}

The balance of the output being used is (at the time of writing this post) 5.40537687 according to this:
https://blockchain.info/tx/7e252ce7176a7a585ed99d4a6ecfb005f34b34574fc933748113a7aa755f824d

This should create a transaction that has no transaction fee, correct?

My first concern before trying this is that I thought that Bitcoin-Qt represented balances internally as integers, so I'm not certain if I should use 5.40537687 for the "amount" or if I should use 540537687



Title: Re: Assistance please regarding createrawtransaction
Post by: Stephen Gornick on March 27, 2013, 01:09:12 PM
The balance of the output being used is (at the time of writing this post) 5.40537687 according to this:
https://blockchain.info/tx/7e252ce7176a7a585ed99d4a6ecfb005f34b34574fc933748113a7aa755f824d

This wasn't your question but there is no "balance" for a transaction.  A transaction output is for a specific amount, period.  That amount is immutable -- it won't change.  Once the transaction is spent it will still be that same amount, it just will have been spent so some views of it might show a balance of 0, but the amount never changed.

My first concern before trying this is that I thought that Bitcoin-Qt represented balances internally as integers, so I'm not certain if I should use 5.40537687 for the "amount" or if I should use 540537687

The amount is decimal.

Here's an example.
 - http://bitcointalk.org/index.php?topic=104512.msg1146645#msg1146645

But this is what Testnet is for!   (Or use a transaction with an amount small enough so an error isn't costly)



Title: Re: Assistance please regarding createrawtransaction
Post by: DannyHamilton on March 27, 2013, 02:50:57 PM
- snip -
This wasn't your question but there is no "balance" for a transaction.  A transaction output is for a specific amount, period.  That amount is immutable -- it won't change.  Once the transaction is spent it will still be that same amount, it just will have been spent so some views of it might show a balance of 0, but the amount never changed.

Yes, I realize this.  I wrote my post in the wee hours of the morning after a long night of drinking and gambling, so I may not have phrased it properly.  I suppose it would have been clearer if I'd have said "the value of the output", rather than "the balance of the output"


Title: Re: Assistance please regarding createrawtransaction
Post by: CIYAM on March 27, 2013, 02:53:40 PM
I can confirm that the value is decimal (have done many raw tx's) and as long as you are spending all of the UTXO then all is good.

BTW I have a simple web page for doing such simple raw tx's (its included in the CIYAM Safe distro) also if you have bitcoin-qt or bitcoind running then  "decoderawtransaction" is a good way to "double check" the tx before you send it.

(although I would not recommend sending raw tx's after a few too many drinks)

:)


Title: Re: Assistance please regarding createrawtransaction
Post by: DannyHamilton on March 27, 2013, 03:10:43 PM
(although I would not recommend sending raw tx's after a few too many drinks)
Agreed. I figured I'd ask the question before going to bed so that the answer would be there when I woke up.

 ;)

I realize that if I screw up a transaction, I can end up with a significantly larger than expected "transaction fee".  I'm taking this slow and careful, and I really hope I don't screw up with real bitcoins. Maybe I'll look into Testnet, I'd really like to get comfortable with the process. I've been thinking about a handful of bitcoin tools (such as an automatic dust sweeper, and a few new coin selection routines).


Title: Re: Assistance please regarding createrawtransaction
Post by: CIYAM on March 27, 2013, 03:12:03 PM
Am sure you'll do fine - but please don't try and break my 111 BTC fee record!

:D


Title: Re: Assistance please regarding createrawtransaction
Post by: pc on March 27, 2013, 03:15:10 PM
If you want an example of using the raw API, check out the "spendfrom" python script in bitcoin's contrib directory: https://github.com/bitcoin/bitcoin/tree/master/contrib/spendfrom


Title: Re: Assistance please regarding createrawtransaction
Post by: DannyHamilton on March 27, 2013, 03:15:28 PM
Am sure you'll do fine - but please don't try and break my 111 BTC fee record!

Yes, I'm aware of it.  It's one of the main reasons that I'm hesitant and double checking everything I do.  Additionally, I'll create a fresh wallet and only send a handful of bitcoins to an address at that wallet to work with (significantly reducing my risk exposure).


Title: Re: Assistance please regarding createrawtransaction
Post by: kjj on March 27, 2013, 04:48:44 PM
Don't look at a website to find the value of an unspent output.  Use listunspent, or getrawtransaction/decoderawtransaction.


Title: Re: Assistance please regarding createrawtransaction
Post by: DannyHamilton on March 27, 2013, 06:59:05 PM
Don't look at a website to find the value of an unspent output.  Use listunspent, or getrawtransaction/decoderawtransaction.

Yes. I was using listunspent, but thanks.


Title: Re: Assistance please regarding createrawtransaction
Post by: themerkle on July 28, 2015, 09:20:12 PM
I am sorry for necroing this thread but I thought this might be of use to some. I was having a hard time calling the createrawtransaction function through an RPC client. I didn't see this anywhere else until it worked.

bitcoin-cli -regtest createrawtransaction '''
    [
      {
        "txid": "'334a94b6a337e86cc88afb1db5a22fa9b1b44546e0b1823c9f1d853be1c6177d'",
        "vout": '0'
      }
    ]
    ''' '''
    {
      "'1KupPMonFcC1Qn6a75kexDZPvwHRuD679s'": 49.9999
    }'''

This string will work. and bitcoin-cli should output (I used a random address on blockchain.info for this tx so its probably not valid):

01000000017d17c6e13b851d9f3c82b1e04645b4b1a92fa2b51dfb8ac86ce837a3b6944a3300000 00000ffffffff01f0ca052a010000001976a914cf6f731517e7e0c66d97c946d4fda0f98f7a23cd 88ac00000000

One important detail I found when messing around with the rpc client is that the vout has to be an integer. All the variables have to have matching types meaning the amount along with the vout has to be an integer and not a string. If you get a code 500 check your parameter types.