Bitcoin Forum

Bitcoin => Bitcoin Technical Support => Topic started by: madmadmax on November 03, 2012, 02:56:41 PM



Title: Get the address sent from
Post by: madmadmax on November 03, 2012, 02:56:41 PM
I have an address in bitcoind and I would like to receive the first address that bitcoins were sent from in Bitcoin.net.

For example if I have an address 37muSN5ZrukVTvyVh3mT5Zc5ew9L9CBare with a balance of 9.5 coins, I would like to receive the address those coins were sent from. This is a problem since I will have multiple addresses each with a couple of coins and I want to get the addresses the coins were sent from for each address.


Title: Re: Get the address sent from
Post by: Stephen Gornick on November 03, 2012, 08:00:26 PM
I have an address in bitcoind and I would like to receive the first address that bitcoins were sent from in Bitcoin.net.

For example if I have an address 37muSN5ZrukVTvyVh3mT5Zc5ew9L9CBare with a balance of 9.5 coins, I would like to receive the address those coins were sent from. This is a problem since I will have multiple addresses each with a couple of coins and I want to get the addresses the coins were sent from for each address.

The Raw Transactions API will give you this info.


Filter the results of listunspent for the output address to learn the transaction ids.  Then get each transaction and pull the first input for each.

use:
getrawtransaction
then for the output of that,
decoderawtransaction

 - http://en.bitcoin.it/wiki/Raw_Transactions

[Edit: See the next few posts to tell you why there is no "from" addresses with Bitcoin.   The right way to know what invoice a payment is for (or what customer sent the payment) is to give out a new address for each transaction.]


Title: Re: Get the address sent from
Post by: Pieter Wuille on November 03, 2012, 09:01:54 PM
If you want to distinguish separate incoming payments, the advised way is creating a separate receive address for each.

Bitcoin transactions do not really have 'from' addresses. All transactions do is consume coins, merge and split them, and produce new coins, potentially assigned to new address(es). It is indeed possible to retrieve where the input coins for your transaction were previously sent to, but in the general case this is not very useful information, as it only tells you which address previously controlled the coin, which is not necessarily the one who sent it. In the case of e-wallets with shared wallets, for example, it only tells you an address that belongs to the provider's wallet, and sending something to it will not necessary mean it ends up on the account of the one who sent it. If you want to do return payments, ask for a return address.


Title: Re: Get the address sent from
Post by: madmadmax on November 03, 2012, 09:41:29 PM
If you want to distinguish separate incoming payments, the advised way is creating a separate receive address for each.

Bitcoin transactions do not really have 'from' addresses. All transactions do is consume coins, merge and split them, and produce new coins, potentially assigned to new address(es). It is indeed possible to retrieve where the input coins for your transaction were previously sent to, but in the general case this is not very useful information, as it only tells you which address previously controlled the coin, which is not necessarily the one who sent it. In the case of e-wallets with shared wallets, for example, it only tells you an address that belongs to the provider's wallet, and sending something to it will not necessary mean it ends up on the account of the one who sent it. If you want to do return payments, ask for a return address.

This is what I do at the moment, how can I check from which address was the payment sent to mine?


Title: Re: Get the address sent from
Post by: Pieter Wuille on November 03, 2012, 09:48:15 PM
If you want to distinguish separate incoming payments, the advised way is creating a separate receive address for each.

Bitcoin transactions do not really have 'from' addresses. All transactions do is consume coins, merge and split them, and produce new coins, potentially assigned to new address(es). It is indeed possible to retrieve where the input coins for your transaction were previously sent to, but in the general case this is not very useful information, as it only tells you which address previously controlled the coin, which is not necessarily the one who sent it. In the case of e-wallets with shared wallets, for example, it only tells you an address that belongs to the provider's wallet, and sending something to it will not necessary mean it ends up on the account of the one who sent it. If you want to do return payments, ask for a return address.

This is what I do at the moment, how can I check from which address was the payment sent to mine?


Title: Re: Get the address sent from
Post by: madmadmax on November 03, 2012, 10:01:57 PM
If you want to distinguish separate incoming payments, the advised way is creating a separate receive address for each.

Bitcoin transactions do not really have 'from' addresses. All transactions do is consume coins, merge and split them, and produce new coins, potentially assigned to new address(es). It is indeed possible to retrieve where the input coins for your transaction were previously sent to, but in the general case this is not very useful information, as it only tells you which address previously controlled the coin, which is not necessarily the one who sent it. In the case of e-wallets with shared wallets, for example, it only tells you an address that belongs to the provider's wallet, and sending something to it will not necessary mean it ends up on the account of the one who sent it. If you want to do return payments, ask for a return address.

This is what I do at the moment, how can I check from which address was the payment sent to mine?

How is this possible then:http://blockchain.info/address/37muSN5ZrukVTvyVh3mT5Zc5ew9L9CBare    ?

I understand that the last address received from may not be the correct one and if you send there they might be lost but I still need it.


Title: Re: Get the address sent from
Post by: kjj on November 03, 2012, 10:43:50 PM
Look at the transaction that you got.  The input part of that transaction will have a list of transaction outputs redeemed.  For each of them, look up the transaction and check the scriptpubkey part of that output.

But you really should figure out a way to do whatever you are doing that doesn't require that, because no matter how much you think you need it, the system totally doesn't work that way.  Transactions do not have From: addresses.


Title: Re: Get the address sent from
Post by: madmadmax on November 05, 2012, 09:24:01 PM
Look at the transaction that you got.  The input part of that transaction will have a list of transaction outputs redeemed.  For each of them, look up the transaction and check the scriptpubkey part of that output.

But you really should figure out a way to do whatever you are doing that doesn't require that, because no matter how much you think you need it, the system totally doesn't work that way.  Transactions do not have From: addresses.

Is there any way to do it with Bitcoin .NET C#? I have been trying but can't seem to figure it out


Title: Re: Get the address sent from
Post by: madmadmax on November 06, 2012, 09:52:29 AM
Anyone? I am still looking for how to do it


Title: Re: Get the address sent from
Post by: madmadmax on November 07, 2012, 11:04:54 AM
*bump*


Title: Re: Get the address sent from
Post by: kjj on November 07, 2012, 12:18:34 PM
The answers are in this thread already.  What are you having problems with?

Are you wondering how to use the RPC service from .net (https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#.NET_.28C.23.29)?


Title: Re: Get the address sent from
Post by: CIYAM on November 07, 2012, 01:16:17 PM
I understand that the last address received from may not be the correct one and if you send there they might be lost but I still need it.

Perhaps it would help if you could tell us what exactly you need this for?

Also I hope you realise that it is even possible that funds could be sent to you from "coinbase" (e.g. if a miner were offering this as some kind of anonymising service) in which case there are no real inputs to tie your output to (apart from those of every tx that paid any fees in the entire block if that's of any use at all).


Title: Re: Get the address sent from
Post by: madmadmax on November 07, 2012, 01:55:29 PM
I understand that the last address received from may not be the correct one and if you send there they might be lost but I still need it.

Perhaps it would help if you could tell us what exactly you need this for?

Also I hope you realise that it is even possible that funds could be sent to you from "coinbase" (e.g. if a miner were offering this as some kind of anonymising service) in which case there are no real inputs to tie your output to (apart from those of every tx that paid any fees in the entire block if that's of any use at all).


I understand all this, it's still irrelevant for what I want to use it, I just need it.

The answers are in this thread already.  What are you having problems with?

Are you wondering how to use the RPC service from .net (https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#.NET_.28C.23.29)?

Yes, I am wondering what calls to make.


Title: Re: Get the address sent from
Post by: kjj on November 07, 2012, 02:03:18 PM
The answers are in this thread already.  What are you having problems with?

Are you wondering how to use the RPC service from .net (https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#.NET_.28C.23.29)?

Yes, I am wondering what calls to make.

The Raw Transactions API will give you this info.

Filter the results of listunspent for the output address to learn the transaction ids.  Then get each transaction and pull the first input for each.

use:
getrawtransaction
then for the output of that,
decoderawtransaction

 - http://en.bitcoin.it/wiki/Raw_Transactions


Title: Re: Get the address sent from
Post by: CIYAM on November 07, 2012, 02:11:07 PM
I understand all this, it's still irrelevant for what I want to use it, I just need it.

I think we have already explained that what you think you need simply does not exist - so can you now try once again to explain what you actually need (without re-stating what is in the thread title)?


Title: Re: Get the address sent from
Post by: madmadmax on November 07, 2012, 02:35:45 PM
I understand all this, it's still irrelevant for what I want to use it, I just need it.

I think we have already explained that what you think you need simply does not exist - so can you now try once again to explain what you actually need (without re-stating what is in the thread title)?


The address the coins were last owned by, return address, you get the point.


Title: Re: Get the address sent from
Post by: CIYAM on November 07, 2012, 02:45:13 PM
As I stated if the coins came from "coinbase" then there simply *is no return address* - do you get it now?

(also as was pointed out previously if the user was using a web-wallet service or some sort of "mixer" service the input address can in no way be reliably used to send coins back to the original sender - hence the warnings given to people wanting to play with satosh dice)


Title: Re: Get the address sent from
Post by: madmadmax on November 07, 2012, 03:17:41 PM
As I stated if the coins came from "coinbase" then there simply *is no return address* - do you get it now?

(also as was pointed out previously if the user was using a web-wallet service or some sort of "mixer" service the input address can in no way be reliably used to send coins back to the original sender - hence the warnings given to people wanting to play with satosh dice)


I already got it 100 times by now, I undestand that it isn't the most reliable method, what code would I use to get this address?


Title: Re: Get the address sent from
Post by: DannyHamilton on November 07, 2012, 03:25:49 PM
As I stated if the coins came from "coinbase" then there simply *is no return address* - do you get it now?

(also as was pointed out previously if the user was using a web-wallet service or some sort of "mixer" service the input address can in no way be reliably used to send coins back to the original sender - hence the warnings given to people wanting to play with satosh dice)


I already got it 100 times by now, I undestand that it isn't the most reliable method, what code would I use to get this address?

By now I'd think you would have noticed that you are getting a lot of responses saying that you can't get what you are asking for, and very few (any?) responses offering exactly what you are asking for.

I'd think this would seem to indicate one of the following:

  • The entire bitcoin community is having fun at your expense by withholding from you the information you are asking for
  • The entire bitcoin community is misunderstanding what you are asking for, perhaps you should try explaining it better.
  • You aren't understanding what you are asking for, perhaps you should think about it a bit and try explaining it better
  • You are asking for something that isn't available, perhaps you should consider a better way to accomplish your goal

Are there other possibilities here I haven't thought of?  Which of the above do you think is most likely?


Title: Re: Get the address sent from
Post by: CIYAM on November 07, 2012, 03:43:33 PM
I already got it 100 times by now, I undestand that it isn't the most reliable method, what code would I use to get this address?

The correct answer to your question is mu (please read G.E.B. to find out exactly what that means - and I hope you enjoy the experience as much as I did as it is IMHO one of the best books ever written).

:)

For the lazy:

Quote
2. /moo/ The correct answer to the classic trick question "Have you stopped beating your wife yet?". Assuming that you have no wife or you have never beaten your wife, the answer "yes" is wrong because it implies that you used to beat your wife and then stopped, but "no" is worse because it suggests that you have one and are still beating her. According to various Discordians and Douglas Hofstadter the correct answer is usually "mu", a Japanese word alleged to mean "Your question cannot be answered because it depends on incorrect assumptions".


Title: Re: Get the address sent from
Post by: madmadmax on November 07, 2012, 05:07:44 PM
I already got it 100 times by now, I undestand that it isn't the most reliable method, what code would I use to get this address?

The correct answer to your question is mu (please read G.E.B. to find out exactly what that means - and I hope you enjoy the experience as much as I did as it is IMHO one of the best books ever written).

:)

For the lazy:

Quote
2. /moo/ The correct answer to the classic trick question "Have you stopped beating your wife yet?". Assuming that you have no wife or you have never beaten your wife, the answer "yes" is wrong because it implies that you used to beat your wife and then stopped, but "no" is worse because it suggests that you have one and are still beating her. According to various Discordians and Douglas Hofstadter the correct answer is usually "mu", a Japanese word alleged to mean "Your question cannot be answered because it depends on incorrect assumptions".


How do I send back coins like satosh dice?


Title: Re: Get the address sent from
Post by: DeathAndTaxes on November 07, 2012, 05:45:57 PM
How do I send back coins like satosh dice?

You were already given the answer both in general terms and with the exact RPC call?  I mean kjj gave you exactly the answer you were asking for (even though it is advised not to use it)

https://bitcointalk.org/index.php?topic=122220.msg1322012#msg1322012


Title: Re: Get the address sent from
Post by: madmadmax on November 07, 2012, 06:21:13 PM
How do I send back coins like satosh dice?

You were already given the answer both in general terms and with the exact RPC call?  I mean kjj gave you exactly the answer you were asking for (even though it is advised not to use it)

https://bitcointalk.org/index.php?topic=122220.msg1322012#msg1322012


Bitcoin .NET C# doesn't contain these functions.


Title: Re: Get the address sent from
Post by: kjj on November 07, 2012, 08:36:47 PM
How do I send back coins like satosh dice?

You were already given the answer both in general terms and with the exact RPC call?  I mean kjj gave you exactly the answer you were asking for (even though it is advised not to use it)

https://bitcointalk.org/index.php?topic=122220.msg1322012#msg1322012


Bitcoin .NET C# doesn't contain these functions.

Ahh, I think you might need to do some reading on what the RPC API is, and how to use it.  I suggest starting with the link I posted earlier.

Are you wondering how to use the RPC service from .net (https://en.bitcoin.it/wiki/API_reference_%28JSON-RPC%29#.NET_.28C.23.29)?


Title: Re: Get the address sent from
Post by: madmadmax on November 10, 2012, 01:34:50 PM
I have an address in bitcoind and I would like to receive the first address that bitcoins were sent from in Bitcoin.net.

For example if I have an address 37muSN5ZrukVTvyVh3mT5Zc5ew9L9CBare with a balance of 9.5 coins, I would like to receive the address those coins were sent from. This is a problem since I will have multiple addresses each with a couple of coins and I want to get the addresses the coins were sent from for each address.

The Raw Transactions API will give you this info.


Filter the results of listunspent for the output address to learn the transaction ids.  Then get each transaction and pull the first input for each.

use:
getrawtransaction
then for the output of that,
decoderawtransaction

 - http://en.bitcoin.it/wiki/Raw_Transactions

[Edit: See the next few posts to tell you why there is no "from" addresses with Bitcoin.   The right way to know what invoice a payment is for (or what customer sent the payment) is to give out a new address for each transaction.]

I list the transactions:
[
  {
    "account": "testacc",
    "address": "18LaYLjk4ktP5PvHZ9X2afBW1uoJxhBZWN",
    "category": "receive",
    "amount": 5E-05,
    "confirmations": 213,
    "blockhash": "00000000000002ab8a627d4d88385a1c8b11b5bcc1de1ebee90a747e15ed87
d4",
    "blockindex": 171,
    "blocktime": 1352434315,
    "txid": "0601b1b121e2b8c7db0ab57620c97f3a8cefefa626a1838718baa8154f9fea84",
    "time": 1352434315,
    "timereceived": 1352550740
  },
  {
    "account": "testacc",
    "address": "18LaYLjk4ktP5PvHZ9X2afBW1uoJxhBZWN",
    "category": "receive",
    "amount": 5E-05,
    "confirmations": 180,
    "blockhash": "000000000000002afc8044a5b98e2634b8058e90e4ee9e22ebd722566c24bf
28",
    "blockindex": 268,
    "blocktime": 1352457915,
    "txid": "b57619177c9cb1031e9e867246751e810593ef1b9520e70de50f09ebb6503b7c",
    "time": 1352457915,
    "timereceived": 1352551000
  }
]
Then I pull a transaction:
{
  "amount": 5E-05,
  "confirmations": 213,
  "blockhash": "00000000000002ab8a627d4d88385a1c8b11b5bcc1de1ebee90a747e15ed87d4
",
  "blockindex": 171,
  "blocktime": 1352434315,
  "txid": "0601b1b121e2b8c7db0ab57620c97f3a8cefefa626a1838718baa8154f9fea84",
  "time": 1352434315,
  "timereceived": 1352550740,
  "details": [
    {
      "account": "testacc",
      "address": "18LaYLjk4ktP5PvHZ9X2afBW1uoJxhBZWN",
      "category": "receive",
      "amount": 5E-05
    }
  ]
}
Still no relevant information about where did it came from?


Title: Re: Get the address sent from
Post by: fergalish on November 10, 2012, 02:06:16 PM
You can get the previous addresses.  The transaction structure contains a list of prior transaction outputs which it is redeeming and which, necessarily, have never been spent before.  We get the list of those (txids,vout) pairs and find which address is associated with each output.  What about something like this pseudocode, where tx0 is the transaction which gave coins to your address:

%START PSEUDOCODE
rawtx = getrawtransaction(tx0)
rawtxdec = decoderawtransaction(rawtx)
for (input in rawtxdec['inputs'])    %LOOP OVER ALL INPUTS
   {
   tx_in=input.txid
   vout_number=input.vout
   rawtx_in = getrawtransaction(tx_in)
   rawtxdec_in = decoderawtransaction(rawtx_in)
   printf "Input address: ",rawtxdec_in['outputs'][vout_number]['destination_address']
   }
%ENDPSEUDOCODE

rawtxdec['inputs'] is an array of transaction inputs, each element of which contains the TXID and VOUT of prior outputs it is redeeming.
rawtxdec['outputs'] is an array of transaction outputs.
rawtxdec['outputs'][vout_number] is a single transaction output we are interested in.
rawtxdec['outputs'][vout_number]['destination_address'] is the address of that output.

I understand that the sender of the transaction might not know anything about the sending address (it could be change from a previous tx), and they might be using a web wallet and so not even have that address in their own personal wallet.


Title: Re: Get the address sent from
Post by: fergalish on November 10, 2012, 06:15:13 PM
Ah, you can also get the BTC amount associated with each "sending" address. Substitute the printf command with:

printf "Input address: ",rawtxdec_in['outputs'][vout_number]['destination_address'], "Amount: ", rawtxdec_in['outputs'][vout_number]['amount']

Or something similar. You'll have to read the documentation to find out the precise syntax, structure, and array keys.