Bitcoin Forum
April 22, 2018, 07:44:54 AM *
News: Latest stable version of Bitcoin Core: 0.16.0  [Torrent]. (New!)
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Using the raw transactions API to build a simple transaction  (Read 9134 times)
jon_smark
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
August 18, 2012, 11:47:46 AM
 #1

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!)
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1524383094
Hero Member
*
Offline Offline

Posts: 1524383094

View Profile Personal Message (Offline)

Ignore
1524383094
Reply with quote  #2

1524383094
Report to moderator
gmaxwell
Staff
Legendary
*
Offline Offline

Activity: 2436
Merit: 1183



View Profile
August 18, 2012, 09:40:19 PM
 #2

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

Bitcoin will not be compromised
jon_smark
Member
**
Offline Offline

Activity: 90
Merit: 10


View Profile
August 19, 2012, 02:40:51 PM
 #3

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!
Jouke
Sr. Member
****
Offline Offline

Activity: 427
Merit: 250



View Profile WWW
January 28, 2013, 10:21:42 PM
 #4

my gratitude to both Smiley Very helpful topic posts Smiley

Koop en verkoop snel en veilig bitcoins via iDeal op Bitonic.nl
rlh
Hero Member
*****
Offline Offline

Activity: 788
Merit: 1000


View Profile
October 23, 2013, 06:42:25 PM
 #5

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?

A Personal Quote on BTT from 2011:
"I'd be willing to make a moderate "investment" if the value of the BTC went below $2.00.  Otherwise I'll just have to live with my 5 BTC and be happy. :/"  ...sigh.  If only I knew.
dserrano5
Legendary
*
Offline Offline

Activity: 1848
Merit: 1000



View Profile
October 23, 2013, 07:27:30 PM
 #6

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.

Abdussamad
Legendary
*
Offline Offline

Activity: 1708
Merit: 1018



View Profile WWW
October 23, 2013, 07:30:10 PM
 #7

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

rlh
Hero Member
*****
Offline Offline

Activity: 788
Merit: 1000


View Profile
October 23, 2013, 07:36:59 PM
 #8

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.

A Personal Quote on BTT from 2011:
"I'd be willing to make a moderate "investment" if the value of the BTC went below $2.00.  Otherwise I'll just have to live with my 5 BTC and be happy. :/"  ...sigh.  If only I knew.
Abdussamad
Legendary
*
Offline Offline

Activity: 1708
Merit: 1018



View Profile WWW
October 23, 2013, 07:46:43 PM
 #9

edit: nvm. Just see this thread for examples from an expert DannyHamilton:

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

rlh
Hero Member
*****
Offline Offline

Activity: 788
Merit: 1000


View Profile
October 23, 2013, 08:47:39 PM
 #10

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.

A Personal Quote on BTT from 2011:
"I'd be willing to make a moderate "investment" if the value of the BTC went below $2.00.  Otherwise I'll just have to live with my 5 BTC and be happy. :/"  ...sigh.  If only I knew.
DannyHamilton
Legendary
*
Offline Offline

Activity: 2128
Merit: 1321



View Profile
October 24, 2013, 12:02:07 AM
 #11

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.

Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!