5
Suppose I'm making a service like SatoshiDice and when I receive a transaction I want to give some money back. Where can I find the sender address?
If I run this, e.g.:
bitcoin-cli gettransaction 8386a8d2870c0df79f652ef4d981b21649ebf40601948c1c0709de0f02de8c8c
I get:
{
"amount" : -0.00750000,
"fee" : -0.00050000,
"confirmations" : 10130,
"blockhash" : "00000000000000002b44cdc1b2fe4ec2aa6b31b25ae8eedc8d1ef16799bd3114",
"blockindex" : 13,
"blocktime" : 1398584440,
"txid" : "8386a8d2870c0df79f652ef4d981b21649ebf40601948c1c0709de0f02de8c8c",
"walletconflicts" : [
],
"time" : 1398584248,
"timereceived" : 1398584248,
"details" : [
{
"account" : "",
"address" : "1Gxua3AptLgz1DWbG38dakLP4DVY2Jia4d",
"category" : "send",
"amount" : -0.00750000,
"fee" : -0.00050000
}
],
"hex" : "01000000013c75459d163a5343725362a5b412dde392784814ec04c4e77df7ee5edbd10352010000006a47304402200ee65c9f757eb6c240efe5a7e4427e04174a32da14b1eef459d36d61d031f6e702202d6b5383f86f155d92a494e80a1242af7e160faf16d597ea457b6e3bf08bb1ca012102be7759e73363488269f0257158177f3295af42d1f3a6b2fdf8fb4380b1d16ae9ffffffff0250c30000000000001976a9144233e899673c755c11664d43d0a83a56d06ce23188acb0710b00000000001976a914af1ca5c63970b893a4ef79d030b28ca91ccd22ce88ac00000000"
}
I can find the address I am looking for in details -> address. But is this the right place to look? The details array can be empty or have more than one element?
I know there are two similar questions already: How to findout the sender of a transaction and What's the best way for a website to detect payments from green addresses? but the problem is that theses questions don't explain if I can use gettransaction securely to find it.
Following the answer tip, I was able to do this:
bitcoin-cli decoderawtransaction "01000000013c75459d163a5343725362a5b412dde392784814ec04c4e77df7ee5edbd10352010000006a47304402200ee65c9f757eb6c240efe5a7e4427e04174a32da14b1eef459d36d61d031f6e702202d6b5383f86f155d92a494e80a1242af7e160faf16d597ea457b6e3bf08bb1ca012102be7759e73363488269f0257158177f3295af42d1f3a6b2fdf8fb4380b1d16ae9ffffffff0250c30000000000001976a9144233e899673c755c11664d43d0a83a56d06ce23188acb0710b00000000001976a914af1ca5c63970b893a4ef79d030b28ca91ccd22ce88ac00000000"
which produces:
{
"txid" : "8386a8d2870c0df79f652ef4d981b21649ebf40601948c1c0709de0f02de8c8c",
"version" : 1,
"locktime" : 0,
"vin" : [
{
"txid" : "5203d1db5eeef77de7c404ec14487892e3dd12b4a562537243533a169d45753c",
"vout" : 1,
"scriptSig" : {
"asm" : "304402200ee65c9f757eb6c240efe5a7e4427e04174a32da14b1eef459d36d61d031f6e702202d6b5383f86f155d92a494e80a1242af7e160faf16d597ea457b6e3bf08bb1ca01 02be7759e73363488269f0257158177f3295af42d1f3a6b2fdf8fb4380b1d16ae9",
"hex" : "47304402200ee65c9f757eb6c240efe5a7e4427e04174a32da14b1eef459d36d61d031f6e702202d6b5383f86f155d92a494e80a1242af7e160faf16d597ea457b6e3bf08bb1ca012102be7759e73363488269f0257158177f3295af42d1f3a6b2fdf8fb4380b1d16ae9"
},
"sequence" : 4294967295
}
],
"vout" : [
{
"value" : 0.00050000,
"n" : 0,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 4233e899673c755c11664d43d0a83a56d06ce231 OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a9144233e899673c755c11664d43d0a83a56d06ce23188ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1733nLJx6QrYa7AemEHXgq89G2NaWjPpRW"
]
}
},
{
"value" : 0.00750000,
"n" : 1,
"scriptPubKey" : {
"asm" : "OP_DUP OP_HASH160 af1ca5c63970b893a4ef79d030b28ca91ccd22ce OP_EQUALVERIFY OP_CHECKSIG",
"hex" : "76a914af1ca5c63970b893a4ef79d030b28ca91ccd22ce88ac",
"reqSigs" : 1,
"type" : "pubkeyhash",
"addresses" : [
"1Gxua3AptLgz1DWbG38dakLP4DVY2Jia4d"
]
}
}
]
}
This let's me find the change address.
But can I skip these steps and take it from "details"?
I know that it should be avoided (guess the change address) but I am not asking here best practices, I am asking how to do it. It's a controlled and specific situation, I know the sender won't use a mix service and so on. – Felipe – 2014-07-01T00:24:43.077
I don't think that your question conveyed explicitly your special situation, so I don't think it is fair of you to rebut the answers you got for not catering to your special situation. Especially your question whether "it is the right place to look", easily allows for these answers. You should improve your question to precisely state the underlying conditions of your situation, instead of critizing the answers. – Murch – 2014-08-12T09:06:08.620
Related: http://bitcoin.stackexchange.com/questions/12111/how-does-blockchain-info-calculate-the-estimated-transaction-value
– Felipe – 2014-12-02T01:24:20.927I'm somewhat confused by all this talk about change addresses and so forth. Why does it matter? If the OP is receiving money in the current transaction at address "1733nLJx6QrYa7AemEHXgq89G2NaWjPpRW", then it's clear that the other output is the change output. And since there's only one input in this transaction, its clear that the sole sender is the signer of that input. That is, the sender's pubkey is "02be7759e73363488269f0257158177f3295af42d1f3a6b2fdf8fb4380b1d16ae9" while the sender's address is "1388D9sHH4HXdGLxkSipxe2noZuekHZmaF". – Ryan – 2014-12-02T02:26:21.977