Author

Topic: Using the raw transactions API to build a simple transaction (Read 9176 times)

legendary
Activity: 3416
Merit: 4658
edit: nvm. Just see this thread for examples from an expert DannyHamilton:

https://bitcointalk.org/index.php?topic=218447.0;all

I'm an expert?

That's news to me.   Grin

Let me know if I can help at all.
rlh
hero member
Activity: 804
Merit: 1004
edit: nvm. Just see this thread for examples from an expert DannyHamilton:

https://bitcointalk.org/index.php?topic=218447.0;all

Yes, thank you.  I had just found that post (and hadn't read it) when I responded.
legendary
Activity: 3612
Merit: 1564
edit: nvm. Just see this thread for examples from an expert DannyHamilton:

https://bitcointalk.org/index.php?topic=218447.0;all
rlh
hero member
Activity: 804
Merit: 1004
Thanks guys.  This helps.  However, I keep getting nasty "Error Parsing JSON" errors that don't tell me anything.  Is there s specific format for the raw transaction details that I need to follow.

In my case, I'm using the bitcoind.exe file-- not a linux or Mac build.
legendary
Activity: 3612
Merit: 1564
vout depends on the input transaction. The first vout of a transaction is 0, the second 1 and so. You'll have to refer to the input transaction on blockexplorer.com to see which vout went to which address.

You can refer to multiple inputs. Just separate them with commas:

createrawtransaction [{txid:aaaaaaaa,vout=1},{txid:aaaaaaaa,vout=2}] {m2222=90,m3333=9}

https://en.bitcoin.it/wiki/Raw_Transactions#createrawtransaction_.5B.7B.22txid.22:txid.2C.22vout.22:n.7D.2C....5D_.7Baddress:amount.2C....7D
legendary
Activity: 1974
Merit: 1029
Hey guys, I have a quick question.  When executing "hex = createrawtransaction [{txid:aaaaaaaa,vout=1}] {m2222=90,m3333=9}", what is the correct value of vout?  Is it always 1? 

How do you build a rawtransaction from multiple inputs?

Transactions can (and usually do) have more than one output, and you need to specify the specific output you want to redeem in a given transaction. vout serves that purpose. It's 0-based.
rlh
hero member
Activity: 804
Merit: 1004
Hey guys, I have a quick question.  When executing "hex = createrawtransaction [{txid:aaaaaaaa,vout=1}] {m2222=90,m3333=9}", what is the correct value of vout?  Is it always 1? 

How do you build a rawtransaction from multiple inputs?
sr. member
Activity: 426
Merit: 250
my gratitude to both Smiley Very helpful topic posts Smiley
member
Activity: 90
Merit: 10
You've basically got it. You don't need to dump or provide the private key: Those parameters are optional— they're used for cases where the relevant keys aren't in your local wallet.

Thanks for the reply!  Indeed, it seems it's even simpler than I thought at first!
staff
Activity: 4172
Merit: 8419
I'm trying to get a good understanding of how Bitcoin works, and the combination of testnet + raw transactions is a wonderful platform for this!  I do have some questions concerning the basics, so I'll describe how I reckon a simple transaction can be built, and I hope you'll correct me and/or answer some of my doubts.
Suppose that a past transaction with txid=aaaaaaaa gave 100 BTC to address m1111 on output vout=1.  I now want to take these 100 BTC and give 90 BTC to address m2222, 9 BTC to address m3333, and pay the remaining 1 BTC as a transaction fee.  These are the steps I think I need to do (in pseudo-code):
[...]
Now I need to sign the transaction.  This is where I have a couple of doubts. First, in this simple example, the second parameter of signrawtransaction can be just an empty list, right? Second, what should the sighash parameter normally be?

You've basically got it. You don't need to dump or provide the private key: Those parameters are optional— they're used for cases where the relevant keys aren't in your local wallet.

Here are some quick walk-throughs I'm working on that use this api:

https://people.xiph.org/~greg/escrowexample.txt
https://people.xiph.org/~greg/signdemo.txt
member
Activity: 90
Merit: 10
I'm trying to get a good understanding of how Bitcoin works, and the combination of testnet + raw transactions is a wonderful platform for this!  I do have some questions concerning the basics, so I'll describe how I reckon a simple transaction can be built, and I hope you'll correct me and/or answer some of my doubts.

Suppose that a past transaction with txid=aaaaaaaa gave 100 BTC to address m1111 on output vout=1.  I now want to take these 100 BTC and give 90 BTC to address m2222, 9 BTC to address m3333, and pay the remaining 1 BTC as a transaction fee.  These are the steps I think I need to do (in pseudo-code):

First I would need to create a raw transaction:

   
    hex = createrawtransaction [{txid:aaaaaaaa,vout=1}] {m2222=90,m3333=9}
   


Now I need to sign the transaction.  This is where I have a couple of doubts. First, in this simple example, the second parameter of signrawtransaction can be just an empty list, right? Second, what should the sighash parameter normally be?

   
    priv = dumpprivkey m1111
    hex2 = signrawtransaction hex [] priv ALL
   


Finally I can send the transaction:

   
    txid = sendrawtransaction hex2
   


Is this all or am I missing something?
(Thank you for your input!)
Jump to: