I would like to issue Bitcoin coupons with a given USD value. The redeeming web app should accept the coupon pin-code and a Bitcoin address and transfer bitcoins to that address according to the current exchange rate. I'm looking for a quick / simple solution, preferably with PHP. Looking for design guidelines and any advice to help me get started.

[edit] To be more specific:

  1. Is there a sample code for sending coins using bitcoind / PHP ?
  2. Is there a 3d party API providing such functionality (instead of using bitcoind)?
  3. Do MtGox and Tradehill have APIs for transfers?
  4. Is captcha a must?

[end edit]

  • I suggest you don't try to maintain a bitcoin daemon yourself, but rather work with something like the Overlay Network / Stratum - bitcointalk.org/index.php?topic=55842.0
    – ripper234
    Commented Jan 4, 2012 at 10:36
  • 4. never EVER captcha. They provide no benefit, in exchange for enraging users. Don't. Ever.
    – o0'.
    Commented Jan 4, 2012 at 12:59

2 Answers 2


I modified the open source Intersango exchange code so that it can issue and accept Bitcoin coupons. You can view the code to see how I did it. My code doesn't store the whole coupon code in the database, so even if a hacker gains read access to the database, they can't redeem the unclaimed coupons.

To answer your particular questions:

1) Is there a sample code for sending coins using bitcoind / PHP ?

Yes. Here's some code that does it in a very simple way.

2) Is there a 3d party API providing such functionality (instead of using bitcoind)?

I don't know. Maybe one of these has what you want.

3) Do MtGox and Tradehill have APIs for transfers?

Tradehill's no longer operating. MtGox does.

4) Is captcha a must?

No. They're annoying. Have the code which checks the coupons take a long time to return a result, and only allow the users to check one at a time. Then they can't brute force the coupons in reasonable time.

  • How do you stop a malicious user from trying more than one at a time? Commented Mar 5, 2012 at 8:11
  • I use a lock to stop each logged in account doing more than one thing at a time. I can't stop one malicious user making a million accounts and using them all at once, but that is a lot more obvious if it happens. Commented Mar 5, 2012 at 9:57
  • If a malicious user creates N accounts, he can check N coupons at a time. You can't hold him to one. And while it might be obvious if a user creates millions of accounts, how do you stop him? The delay also tends to turn it into a self-DOS because you tend to run yourself out of connections. Commented Mar 5, 2012 at 10:11
  1. Issue coupons with some serial number that is unique to each coupon, preferably concealed in a way that once the number is visible, the coupon can't be made to look unopened.
  2. Have a list of all coupon serial numbers and their values in your database.
  3. Upon redeeming the coupon with a proper Bitcoin address, convert the amount according to some value form an exchange (like Mt.Gox) and send the proper amount of coins to the specified address.

As for the actual program to perform those actions, can't help you much, but if you can communicate with Bitcoind through JSON-RPC, the rest should be pretty easy to program for.

  • tnx ThePiachu, i've edited the question, added some more specific points.
    – asi
    Commented Jan 4, 2012 at 7:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.