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"?