konradp (OP)
|
|
August 06, 2014, 12:04:05 PM Last edit: August 06, 2014, 02:50:15 PM by konradp |
|
Hi, I'm trying to understand transactions, so I'm playing with raw transactions in bitcoin-qt on testnet. I'm not sure about a few things, even after reading https://en.bitcoin.it/wiki/Transactions (I supposed I missed something) After listunspent I have this transaction among others: { "txid" : "d8e5db107f5dbd3b74b454a4ba2566277894199a836d9982a255a61f2b10d0a8", "vout" : 1, "address" : "msmhYhrXtYAxerUCNfDAXu97xwaZ3JqxH6", "scriptPubKey" : "76a914866b70364391e0ba5514cc30cb45f12291bc6cf788ac", "amount" : 0.33900000, "confirmations" : 65 }, I want to send 0.02 BTC, So I do: createrawtransaction [{\"txid\":\"d8e5db107f5dbd3b74b454a4ba2566277894199a836d9982a255a61f2b10d0a8\",\"vout\":1}] {\"mxHgEstqwqYtVrDP3LsjS9WWAeWHQyatck\":0.02} (mxHgEstqwqYtVrDP3LsjS9WWAeWHQyatck is another address of mine) Is that OK? Result is: 0100000001a8d0102b1fa655a282996d839a199478276625baa454b4743bbd5d7f10dbe5d801000 00000ffffffff0180841e00000000001976a914b7f7543883c4fd010aeb1ef63b5e888487dd08ae 88ac00000000 After decoding it at https://blockchain.info/decode-tx I have (questions inside): { "lock_time":0, "inputs":[ { "prev_out":{ "index":1, "hash":"d8e5db107f5dbd3b74b454a4ba2566277894199a836d9982a255a61f2b10d0a8" }, "script":"" //question 0: This is scriptSig right? It's empty because I haven't signed the transfer yes? } ], "vout_sz":1, //question 1: What is it? "hash":"d231eab0bcee0ab3e2e2c08aa9f2eefa4f2e0d42ce225540fd2287ade62e0cdb", "vin_sz":1, //question 2: What is it? "out":[ { "address":"1Hmiwpos8p7dijjmKmuMcEJBJeuaQzY3Mv", //question 3: is this a receiving address created by the wallet? Or something else? "script_string":"OP_DUP OP_HASH160 b7f7543883c4fd010aeb1ef63b5e888487dd08ae OP_EQUALVERIFY OP_CHECKSIG", //question 4: where did this b7f7543883... come from? "value":2000000, "script":"76a914b7f7543883c4fd010aeb1ef63b5e888487dd08ae88ac" } ], "size":85, "version":1 } I will soon sign the transfer, but can you answer the questions above first please? btw. should I ask these kind of questions here or in Development & Technical Discussion maybe?
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 12:20:39 PM |
|
(mxHgEstqwqYtVrDP3LsjS9WWAeWHQyatck is another address of mine) Is that OK?
Yes "script":"" //question 0: This is scriptSig right? It's empty because I haven't signed the transfer yes?
Yes "vout_sz":1,//question 1: What is it?
This is the number of outputs ( vector- output- si ze?). You can send to several "addresses" your funds. This transaction sends to one address. "vin_sz":1,//question 2: What is it?
This is the number of inputs. You can spend several inputs in one transaction. Your particular transaction spends only one "address":"1Hmiwpos8p7dijjmKmuMcEJBJeuaQzY3Mv",//question 3: is this a receiving address created by the wallet? Or something else?
Yes. But why does it starts with "1" Seems to me thay you have decoded your transaction for mainnet, not for testnet! Be careful! "script_string":"OP_DUP OP_HASH160 b7f7543883c4fd010aeb1ef63b5e888487dd08ae OP_EQUALVERIFY OP_CHECKSIG",//question 4: where did this b7f7543883... came from? "value":2000000, "script":"76a914b7f7543883c4fd010aeb1ef63b5e888487dd08ae88ac"
This is another representation of your destination address http://test.webbtc.com/address/mxHgEstqwqYtVrDP3LsjS9WWAeWHQyatck
|
|
|
|
konradp (OP)
|
|
August 06, 2014, 12:36:15 PM Last edit: August 06, 2014, 12:57:33 PM by konradp |
|
Thank you! "address":"1Hmiwpos8p7dijjmKmuMcEJBJeuaQzY3Mv",//question 3: is this a receiving address created by the wallet? Or something else? Yes. But why does it starts with "1" Huh Seems to me thay you have decoded your transaction for mainnet, not for testnet! Be careful!Well, I have no idea. I'm working entirely in testnet mode. I did run mainnet before but it's closed now. Do you have an idea? "script_string":"OP_DUP OP_HASH160 b7f7543883c4fd010aeb1ef63b5e888487dd08ae OP_EQUALVERIFY OP_CHECKSIG",//question 4: where did this b7f7543883... came from? "value":2000000, "script":"76a914b7f7543883c4fd010aeb1ef63b5e888487dd08ae88ac"
This is another representation of your destination addressI found out that this "hash160" is a ripemd160(sha256(address)) is this correct? Because when I do this I get a completely different result... even considering this endianness craziness it doesn't match.
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 01:07:15 PM |
|
Well, I have no idea. I'm working entirely in testnet mode. I did run mainnet before but it's closed now. Do you have an idea?
Of course. You have said above: Blockchain.info site decodes this transaction as for mainnet. I found out that this "hash160" is a ripemd160(sha256(address)) is this correct?
No. Your public key is long array of bytes (64 bytes to be correct) It is too long to be used as an address and it does not have checksums for error handling So, there is a hash function which converts public key to 20 bytes (there are 2 ways to do it) b7f7543883c4fd010aeb1ef63b5e888487dd08ae - is the result of this written in hex digits This line is also bad for using as your address - it is still too long and also does not have error-cheching So, there is base58check function which converts 20 bytes to bitcoin address read this https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresseshttps://en.bitcoin.it/wiki/Base58Check_encoding
|
|
|
|
Bitcoin Town
Newbie
Offline
Activity: 13
Merit: 0
|
|
August 06, 2014, 01:12:19 PM |
|
i dont know about thats maybe some error system on it .
|
|
|
|
konradp (OP)
|
|
August 06, 2014, 01:21:56 PM |
|
Well, I have no idea. I'm working entirely in testnet mode. I did run mainnet before but it's closed now. Do you have an idea?
Of course. You have said above: Blockchain.info site decodes this transaction as for mainnet. I found out that this "hash160" is a ripemd160(sha256(address)) is this correct?
No. Your public key is long array of bytes (64 bytes to be correct) It is too long to be used as an address and it does not have checksums for error handling So, there is a hash function which converts public key to 20 bytes (there are 2 ways to do it) b7f7543883c4fd010aeb1ef63b5e888487dd08ae - is the result of this written in hex digits This line is also bad for using as your address - it is still too long and also does not have error-cheching So, there is base58check function which converts 20 bytes to bitcoin address read this https://en.bitcoin.it/wiki/Technical_background_of_Bitcoin_addresseshttps://en.bitcoin.it/wiki/Base58Check_encodingThanks. I was going to ask you if I also have to fully understand addresses to understand transactions, then I saw last two lines of your answer:) So thanks. I'll read it. Blockchain.info site decodes this transaction as for mainnet. Ouch But can I assume that everything except for this receiving address is OK?
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 01:26:09 PM |
|
Blockchain.info site decodes this transaction as for mainnet. Ouch But can I assume that everything except for this receiving address is OK? Yes
|
|
|
|
konradp (OP)
|
|
August 06, 2014, 01:56:50 PM |
|
Thanks!
So I'm signing the transaction:
signrawtransaction 0100000001a8d0102b1fa655a282996d839a199478276625baa454b4743bbd5d7f10dbe5d801000 00000ffffffff0180841e00000000001976a914b7f7543883c4fd010aeb1ef63b5e888487dd08ae 88ac00000000
result is OK, and after decoding I have:
{ "lock_time":0, "inputs":[ { "prev_out":{ "index":1, "hash":"d8e5db107f5dbd3b74b454a4ba2566277894199a836d9982a255a61f2b10d0a8" }, "script":"473044022031e60b2d340e350d871809492f3d0b4d7dda2eae11c4e729be648a9c87b2fc1802207 bd0fbd9614dc08f14b9092559de106417373a8a1d9353767874a95aa302973b012102d9c1d8bc28 62f6946ea055743551abb385492069da38bdc0ec8e3e875ec87875" //question 0: this is again scriptSig, this time signed, right? But why can't be it "decoded" just like scriptPubKey below? } ], "vout_sz":1, "hash":"7f850e2a177fb494492d3ad7707cceaa410106b3c6ce0385f876d24acad653ab",//question 1: I thought this is transaction ID, then why did it change after signing it? "vin_sz":1, "out":[ { "address":"1Hmiwpos8p7dijjmKmuMcEJBJeuaQzY3Mv", "script_string":"OP_DUP OP_HASH160 b7f7543883c4fd010aeb1ef63b5e888487dd08ae OP_EQUALVERIFY OP_CHECKSIG",//question 3: this is the same as in above, but I forgot to ask, this is the scriptPubKey, right? "value":2000000, "script":"76a914b7f7543883c4fd010aeb1ef63b5e888487dd08ae88ac" } ], "size":191, "version":1 }
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 02:29:28 PM |
|
"script":"473...c87875" //question 0: this is again scriptSig, this time signed, right? But why can't be it "decoded" just like scriptPubKey below?
There is nothing interesting in scriptSig - there are two <push> operations. Signature and publicKey "hash":"7f850e2a177fb494492d3ad7707cceaa410106b3c6ce0385f876d24acad653ab",//question 1: I thought this is transaction ID, then why did it change after signing it?
There is no "ID" field in transaction itself. Transaction ID is a hash of its contents. Contents was changed. So the hash will be different "script_string":"OP_DUP OP_HASH160 b7f7543883c4fd010aeb1ef63b5e888487dd08ae OP_EQUALVERIFY OP_CHECKSIG",//question 3: this is the same as in above, but I forgot to ask, this is the scriptPubKey, right?
Yes
|
|
|
|
konradp (OP)
|
|
August 06, 2014, 02:37:28 PM Last edit: August 06, 2014, 02:55:16 PM by konradp |
|
Thank you, you're a nice guy!
So now I'm trying to send it:
sendrawtransaction 0100000001a8d0102b1fa655a282996d839a199478276625baa454b4743bbd5d7f10dbe5d801000 0006a473044022031e60b2d340e350d871809492f3d0b4d7dda2eae11c4e729be648a9c87b2fc18 02207bd0fbd9614dc08f14b9092559de106417373a8a1d9353767874a95aa302973b012102d9c1d 8bc2862f6946ea055743551abb385492069da38bdc0ec8e3e875ec87875ffffffff0180841e0000 0000001976a914b7f7543883c4fd010aeb1ef63b5e888487dd08ae88ac00000000
result (error): (code -25)
Debug log doesn't say anything. Actually, it looks like it stopped logging things an hour ago... And google doesn't help either.
Update, was that an error? Because I've just received those 0.02 btc, transaction hash is OK: 7f850e2a177fb494492d3ad7707cceaa410106b3c6ce0385f876d24acad653ab
So, why was it in red, and this minus sign before...
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 02:55:22 PM |
|
|
|
|
|
konradp (OP)
|
|
August 06, 2014, 02:56:57 PM |
|
Ha, yes, I've just received it, thanks.
But then why bitcoin-qt said code: -25 (in red) ?
Edit:
OK, I need to go home now. *Big* thank you for your help amaclin! Tomorrow I'll have to wrap my head around it all over again:)
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 03:03:47 PM |
|
But then why bitcoin-qt said code: -25 (in red) ? Something was wrong while sending. I have sources for bitcoin 0.8.x version. There is no -25 error code there. Are you using v0.9? Have a look into bitcoinrpc.h file
|
|
|
|
p2pbucks
|
|
August 06, 2014, 03:37:54 PM |
|
./bitcoind getrawtransaction d8e5db107f5dbd3b74b454a4ba2566277894199a836d9982a255a61f2b10d0a8 and then decoderawtransaction first, make sure you have set the right vout
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 03:57:11 PM |
|
OK, I need to go home now. *Big* thank you for your help amaclin! Tomorrow I'll have to wrap my head around it all over again:)
By the way: do not forget about "change" output and fees working with mainnet.
|
|
|
|
Bungeebones
|
|
August 06, 2014, 04:14:51 PM |
|
I want to say "thanks" to both the OP and Amaclin for this post. It is great when someone posts really concise, step by step and intelligent questions and then another replies with equally concise, step by step and intelligent answers. I, myself, am just starting to delve into understanding transactions so I have bookmarked this baby.
Thank you both!
|
|
|
|
21M Bitcoin
Newbie
Offline
Activity: 15
Merit: 0
|
|
August 06, 2014, 05:58:45 PM |
|
I want to say "thanks" to both the OP and Amaclin for this post. It is great when someone posts really concise, step by step and intelligent questions and then another replies with equally concise, step by step and intelligent answers. I, myself, am just starting to delve into understanding transactions so I have bookmarked this baby.
Thank you both!
he is real hero . thats full and easy step from him what a amazing man wiiith brightshine .
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 06:55:52 PM |
|
wow should i put my address into the signature for donations?
|
|
|
|
coynbyer123
Newbie
Offline
Activity: 43
Merit: 0
|
|
August 06, 2014, 07:49:36 PM |
|
After listunspent I have this transaction among others:
{ "txid" : "d8e5db107f5dbd3b74b454a4ba2566277894199a836d9982a255a61f2b10d0a8", "vout" : 1, "address" : "msmhYhrXtYAxerUCNfDAXu97xwaZ3JqxH6", "scriptPubKey" : "76a914866b70364391e0ba5514cc30cb45f12291bc6cf788ac", "amount" : 0.33900000, "confirmations" : 65 },
I want to send 0.02 BTC, So I do: createrawtransaction [{\"txid\":\"d8e5db107f5dbd3b74b454a4ba2566277894199a836d9982a255a61f2b10d0a8\",\"vout\":1}] {\"mxHgEstqwqYtVrDP3LsjS9WWAeWHQyatck\":0.02}
(mxHgEstqwqYtVrDP3LsjS9WWAeWHQyatck is another address of mine)
Is that OK?
0.339 - 0.2 = 0.319 u paying 0.319 BTC transaction fee is what u want to do? if no then createrawtransaction need 2nd output to address from u wallet.
|
|
|
|
amaclin
Legendary
Offline
Activity: 1260
Merit: 1019
|
|
August 06, 2014, 07:54:38 PM |
|
is what u want to do? This is not a problem on testnet. Let him to make this mistake before teaching him. By the way. I have a lot of testnet coins. Who wants them? PM me your testnet address
|
|
|
|
|