user56245: I am trying to write a program to receive bitcoin, and then after some time, return the same amount of bitcoin to the same address.
How would you do this? Does bitcoin have the ability to send and receive coins through the same address, or would I have to ask for a return address and somehow link the sent amount address to the return address?

user46471: You should ask for a return address. Bitcoin transactions don't contain any "from address", it only references another (previous) transaction's output. An output can be a P2PKH (Pay to public key hash), but it can just as well be P2SH (Pay to script hash) and some other may be implemented in the future.
There's also a large possibility of getting a transaction referencing many previous outputs, as happens when someone paying you 1 BTC received many smaller transaction previously.
It would also be unintuitive to your users, as it's bitcoin best practice not to care about where the bitcoins come from and instead to generate a new address for every transaction received.
On top of that, you shouldn't implement any cryptography by yourself if you're not already a top-level expert, there are simply too many things that can go wrong. I would recommend using a proper API.

user85: For the love of all that is holy, do not do this. Consider:
Alice wants to send you 1 bitcoin. She asks her wallet provider to send you 1 bitcoin. Her wallet provider sends you the bitcoins it got from Bob when he deposited into his wallet.
You look at the transaction and see that the coins came from Bob's deposit address. So you send coins back to that address. Alice's wallet provider sees coins received to Bob's deposit address and credits Bob.
Bob wonders why he received some bitcoins from a random stranger, but since he has no idea who you are and no way to contact you, he just keeps them. Heck, maybe it's an address he made public as a tip jar and he has no reason not to think it's a tip.
Alice might eventually wonder why she didn't get her bitcoins. If she contacts you, you'll give her the transaction ID. She'll think, "Hmm, that's not my address. But it must belong to my wallet provider. So they must have the bitcoins. When I explain to them that they're mine, they should credit them to me."
And now we have a massive mess where everyone is blaming everyone else and Alice thinks her wallet provider stole from her and you think it wasn't your fault. But you're wrong.
Please do not do this. It does not make any sense. (The story above is real. Only the names have been changed to protect the innocent ... and the guilty.)

56245: <p>I am trying to write a program to receive bitcoin, and then after some time, return the same amount of bitcoin to the same address.</p>

<p>How would you do this? Does bitcoin have the ability to send and receive coins through the same address, or would I have to ask for a return address and somehow link the sent amount address to the return address?</p>
 46471: <p>You should ask for a return address. Bitcoin transactions don't contain any "from address", it only references another (previous) transaction's output. An output can be a P2PKH (Pay to public key hash), but it can just as well be P2SH (Pay to script hash) and some other may be implemented in the future.</p>

<p>There's also a large possibility of getting a transaction referencing many previous outputs, as happens when someone paying you 1 BTC received many smaller transaction previously.</p>

<p>It would also be unintuitive to your users, as it's bitcoin best practice not to care about where the bitcoins come from and instead to generate a new address for every transaction received.</p>

<p>On top of that, you shouldn't implement any cryptography by yourself if you're not already a top-level expert, there are simply too many things that can go wrong. I would recommend using a proper API.</p>
 85: <p>For the love of all that is holy, do not do this. Consider:</p>

<p>Alice wants to send you 1 bitcoin. She asks her wallet provider to send you 1 bitcoin. Her wallet provider sends you the bitcoins it got from Bob when he deposited into his wallet.</p>

<p>You look at the transaction and see that the coins came from Bob's deposit address. So you send coins back to that address. Alice's wallet provider sees coins received to Bob's deposit address and credits Bob.</p>

<p>Bob wonders why he received some bitcoins from a random stranger, but since he has no idea who you are and no way to contact you, he just keeps them. Heck, maybe it's an address he made public as a tip jar and he has no reason not to think it's a tip.</p>

<p>Alice might eventually wonder why she didn't get her bitcoins. If she contacts you, you'll give her the transaction ID. She'll think, "Hmm, that's not my address. But it must belong to my wallet provider. So they must have the bitcoins. When I explain to them that they're mine, they should credit them to me."</p>

<p>And now we have a massive mess where everyone is blaming everyone else and Alice thinks her wallet provider stole from her and you think it wasn't your fault. But you're wrong.</p>

<p>Please do not do this. It does not make any sense. (The story above is real. Only the names have been changed to protect the innocent ... and the guilty.)</p>
