Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Mcoroklo on January 14, 2013, 06:46:00 PM



Title: Bitcoin API with callback function?
Post by: Mcoroklo on January 14, 2013, 06:46:00 PM
I am currently developing several applications for bitcoins, but I have problems with the most vital part: Receiving payments!

I need the following two API calls:
- Generating a bitcoin address, providing a callback, which is called with my custom parameters, when the payment is made
- Sending money to a bitcoin address

I've investigated the following:

Blockchain:
They seem to have the perfect API, but after more than a week of silence in a support case, the API simply doesn't seem to work (the callback part).
Therefore, I am not comfortable with these guys.

Coinbase:
Has a minimum transaction of 0.01BTC and no callback function when sending money.

MtGox:
As I see it, it doesn't look to provide what I need, but different things.

Bitcoin RPC:
If I can avoid having a local server it would be great, plus I've no idea how to program against this API ;-)

I would love ANY ideas!


Title: Re: Bitcoin API with callback function?
Post by: grau on January 14, 2013, 06:56:06 PM
I am currently developing several applications for bitcoins, but I have problems with the most vital part: Receiving payments!

I need the following two API calls:
- Generating a bitcoin address, providing a callback, which is called with my custom parameters, when the payment is made
- Sending money to a bitcoin address

The first is a nice idea, I think about adding this to the bitsofproof API, the second should be trivial with bitcoind RPC or bitcoinj functions.


Title: Re: Bitcoin API with callback function?
Post by: Realpra on January 14, 2013, 08:32:34 PM
As far as I know the Electrum client is open source, since this is a lightweight client you can run it without killing your server easily.

Either it will have an API OR you can modify the code to write out the events you need etc..


Title: Re: Bitcoin API with callback function?
Post by: Mcoroklo on January 15, 2013, 10:11:36 AM
Grau:
If you implement it fast, you have a customer, and maybe, with quite a lot of volume ;-)

Realpra:
Only issue, seems like I need to learn Python first.. ;-)

Thanks for the answers! I would love to hear other thoughts too.



Title: Re: Bitcoin API with callback function?
Post by: BitcoinHoarder on January 15, 2013, 12:41:44 PM
If you are developing several applications for bitcoin I highly recommend you learn the bitcoind API.  It does a lot and works really well.  Why would you want to avoid having a local server?  If you post here you will get help very fast.

I will even get you started with this script that sends money in Python:

Code:
from jsonrpc import ServiceProxy

amount = 0.5050
sendToAddress = "1putanaddressheretosendto"

access = ServiceProxy("http://username:password@127.0.0.1:8332")
balance = access.getinfo()["balance"]
print "BALANCE: " + str(balance)
transaction_id = access.sendtoaddress(sendToAddress, amount)
print "TRANSACTION ID: " + transaction_id

How easy is that?  Super easy!


Title: Re: Bitcoin API with callback function?
Post by: ingrownpocket on January 15, 2013, 02:24:16 PM
I am currently developing several applications for bitcoins, but I have problems with the most vital part: Receiving payments!

I need the following two API calls:
- Generating a bitcoin address, providing a callback, which is called with my custom parameters, when the payment is made
- Sending money to a bitcoin address

I've investigated the following:

Blockchain:
They seem to have the perfect API, but after more than a week of silence in a support case, the API simply doesn't seem to work (the callback part).
Therefore, I am not comfortable with these guys.

http://blockchain.info/api/api_receive

https://github.com/blockchain/receive_payment_php_demo/blob/master/callback.php

Add to line 26 -> || $_SERVER['REMOTE_ADDR'] == '91.203.74.202'
(https://bitcointalk.org/index.php?topic=119600.0 (https://bitcointalk.org/index.php?topic=119600.0))


Title: Re: Bitcoin API with callback function?
Post by: Mcoroklo on January 15, 2013, 05:46:36 PM
BitcoinHoarder:
Ok, that code is really simple. Even without understanding python, that's so readable. I will look into it.

Carlos L:
Blockchain never make a callback, even though my code should work, and their support doesn't answer.

Thanks a lot for answers so far :)


Title: Re: Bitcoin API with callback function?
Post by: grau on January 15, 2013, 06:34:02 PM
Grau:
If you implement it fast, you have a customer, and maybe, with quite a lot of volume ;-)
It is done. The bitsofproof node offers a message bus where it sends validated transactions and block chain events to authenticated extensions. It accepts transactions for routing towards the net through the same bus.

The API for extensions includes a call to register a callback as simple as:
Code:
public void registerAccountListener (List<String> addresses, TransactionListener listener);
You will receive validated transactions as properly parsed java objects with all information available on the wire. You will receive transactions receiving OR spending involving that set of addresses.

The caveat with bitsofproof is, that although it works stable it needs to pass yet more tests to call it production quality.

If your decision criteria is fastest production deployment, go for something else for now.
In case you build an enterprise, I guess you will come back :)

See the wiki for more: https://github.com/bitsofproof/supernode/wiki


Title: Re: Bitcoin API with callback function?
Post by: ingrownpocket on January 15, 2013, 08:25:37 PM
Carlos L:
Blockchain never make a callback, even though my code should work, and their support doesn't answer.

You're doing something wrong then. I have 3 services using that payment method and all 3 callbacks work fine.


Title: Re: Bitcoin API with callback function?
Post by: Mcoroklo on January 15, 2013, 10:11:36 PM
Carlos:
That sounds VERY interesting! Could you provide an example of a URL you send?

I send:
https://blockchain.info/api/receive?method=create&address=1Ccypfi3rnXosUgY6p1sQVXFyddFvwLFEJ&anonymous=false&callback=url.com/callbackhandler.ashx&myid=a0613be5-1c05-47ff-a455-a9f597d61ea5&participant=A

(I've tried several others like this)

Did you need to activate anything?


Title: Re: Bitcoin API with callback function?
Post by: ingrownpocket on January 16, 2013, 09:36:51 AM
Carlos:
That sounds VERY interesting! Could you provide an example of a URL you send?

I send:
https://blockchain.info/api/receive?method=create&address=1Ccypfi3rnXosUgY6p1sQVXFyddFvwLFEJ&anonymous=false&callback=url.com/callbackhandler.ashx&myid=a0613be5-1c05-47ff-a455-a9f597d61ea5&participant=A

(I've tried several others like this)

Did you need to activate anything?

Error no protocol: url.com/callbackhandler.ashx -> This pretty much says everything.

blockchain.info/api/receive?method=create&address=1Ccypfi3rnXosUgY6p1sQVXFyddFvwLFEJ&anonymous=false&callback=http://url.com/callbackhandler.ashx&myid=a0613be5-1c05-47ff-a455-a9f597d61ea5&participant=A


Title: Re: Bitcoin API with callback function?
Post by: Mcoroklo on January 16, 2013, 10:35:20 AM
The url.com was just a replacement URL. I have full http://www. on my domain, and the callback tool on their API page works perfectly. It is when the money is payed to that address, the callback is never called. I log any visit (before checking IP), and the url is never called.


Title: Re: Bitcoin API with callback function?
Post by: Mike Hearn on January 16, 2013, 10:38:34 AM
bitcoinj apps receive callbacks when money is received. Take a look at the PingService example in the examples directory to see how it's done, or for a "real" app look at the code to MultiBit or the Android Bitcoin Wallet. There are docs on the website explaining how to do it :

http://code.google.com/p/bitcoinj


Title: Re: Bitcoin API with callback function?
Post by: ingrownpocket on January 16, 2013, 12:32:16 PM
The url.com was just a replacement URL. I have full http://www. on my domain, and the callback tool on their API page works perfectly. It is when the money is payed to that address, the callback is never called. I log any visit (before checking IP), and the url is never called.

Well, I don't know what's happening then.
I can take a look at your script for a fee.


Title: Re: Bitcoin API with callback function?
Post by: Mcoroklo on January 16, 2013, 01:13:12 PM
Carlos:
I just tried running the code on my website, and now it worked. It seems they made a fix, as I didn't change my code at all. Interesting! :-)

Thanks a lot for your help though.


Title: Re: Bitcoin API with callback function?
Post by: danystatic on September 30, 2013, 06:36:40 PM
I am having the same issue, I had fixed it before, but something is wrong, the callback works great from the Callback Test from blockchain.info
but not when I am actually sending Bitcoins


   $callback_url = Config::get('btcconfig.mysite_root') . "callback?invoice_id=" . $invoice_id;
   

file_get_contents("https://blockchain.info/api/receive?method=create&address=16qiTWRUr6dbTdAbH3nzP5nqGcmEdaPwGq&shared=false&callback=" . urlencode($callback_url));

Results :

string(195) "{"input_address":"1MrYVkkkXMEQjcwHtp8V2miXsR6aC1o9xf","callback_url":"http:\/\/guiseppelidonnici.com\/callback?invoice_id=9001","fee_percent":0,"destination":"16qiTWRUr6dbTdAbH3nzP5nqGcmEdaPwGq"}"
    

I have to fix this today, please give advice


Title: Re: Bitcoin API with callback function?
Post by: BitcoinLeader on September 30, 2013, 07:22:08 PM
I just released the open-source MtGox PHP API V2 (https://github.com/pathaksa/MtGox-PHP-API-V2) which does exactly what you need.


You would be needing the following method:

Quote
/**
* Generates a new bitcoin address for depositing.
*
* @require API Rights: Deposit
* @param string $description Optional description to display in the account history
* @param string $ipn Optional IPN URL which will be called with details when bitcoins are received
* @return mixed
*/
    function getDepositAddress($description = null, $ipn = null) {
        $result = $this->query( $this->pair . '/money/bitcoin/address', array(
            'description' => $description,
            'ipn' => $ipn
        ));

        return $result;
    }

1. The method returns an deposit addres
2. The IPN parameter is the callback URL you are looking for to get notified when bitcoins are deposited on the address

If you pass an transaction ID to the IPN URL and associate the transaction ID with the deposit address, you can trace it back when the IPN callback is triggered.


Title: Re: Bitcoin API with callback function?
Post by: Sukrim on October 08, 2013, 08:21:50 AM
Ideally I'd like a piece of code that just interfaces with bitcoind's RPC interface and generates the callbacks on its own, if necessary even just by simply polling every 2 seconds or so.

Has anyone written something like this already? It doesn't seem too difficult to do on my own, but it would be nice if it already exists.
I do explicitly not want to extend bitcoinj or Electrum etc., as I would like to use this approach on altcoin clients too, which are (too) often based on bitcoind and expose the same or a very similar RPC interface, so I'd love to keep it generic.


Title: Re: Bitcoin API with callback function?
Post by: johba on October 08, 2013, 03:34:21 PM

check out this in java for bitcoind: https://github.com/johannbarbie/BitcoindClient4J

you can register block or wallet listeners:

new BlockListener(client).addObserver(new Observer() {
    @Override
    public void update(Observable o, Object arg) {
      Block block = (Block)arg;
    }
  });


Title: Re: Bitcoin API with callback function?
Post by: Sukrim on October 09, 2013, 12:50:40 PM
One of the problems is the generation of new addresses that can lead to very large wallet files over time. With blockchain.info you offload this stuff to them, if you do it yourself, you might want to look into rate limiting or something like that to avoid someone spamming your server with 1 million requests that would fill your wallet files and also maybe even DoS you with key generation.


Title: Re: Bitcoin API with callback function?
Post by: johba on October 09, 2013, 02:40:53 PM
One of the problems is the generation of new addresses that can lead to very large wallet files over time. With blockchain.info you offload this stuff to them, if you do it yourself, you might want to look into rate limiting or something like that to avoid someone spamming your server with 1 million requests that would fill your wallet files and also maybe even DoS you with key generation.

I think that's easy to avoid using the getaccountaddress call with the bitcoind json rpc. It will only give you a new address once the previous one has been used in a transaction.


Title: Re: Bitcoin API with callback function?
Post by: Sukrim on October 09, 2013, 07:46:21 PM
Then you'd end up with potentially presenting the same address to several users, as there will always be some lag time between presenting the user an address and the user sending something there.

The only thing to prevent this is to create some accounts on your service (which is something I want to avoid) or doing ugly things such as using IP addresses to distinguish between current users...

It might be possible to re-use addresses (if you re-implement the blockchain API, one could save all addresses that were not used for 1 week and then use these again) to migitate this somehow, still wallet bloat is an issue, as long as keys are 100% independent of each other and not BIP31. Even if Bitcoind (finally!) implements BIP31 deterministic keys, there is still the issue with Altcoins that are poorly maintained and that would take even longer to pull the necessary code.

Maybe creating a relatively large pool of addresses (e.g. 100k or so) that are rotated would work too, but that's actually backend stuff. Still, the "generating new address" part is what worries me most, the rest could be also simply polled with getreceivedbyaddress as already said.


Title: Re: Bitcoin API with callback function?
Post by: danystatic on October 10, 2013, 12:19:58 AM
a REAL callback function, it could be possible with a cron job / script + walletnotify or other way I wish someone says the proper way :s

----------------------------
I did modifiy blockchain's php payment demo  and also  :   payment_button_v2.js
also
used bitcoin rpc  
----
why are you so opposed to learning the rpc, is easy, i could be a guide
It is 1 day thing.


Title: Re: Bitcoin API with callback function?
Post by: Benson Samuel on October 10, 2013, 03:31:42 AM
Check my github in my signature. It has fully working code for Blockchain and Coinbase.

Both have been successfully implemented with callbacks, etc for 2 games as well.

https://github.com/bensonsamuel


Title: Re: Bitcoin API with callback function?
Post by: johba on October 10, 2013, 03:45:36 AM
Then you'd end up with potentially presenting the same address to several users, as there will always be some lag time between presenting the user an address and the user sending something there.

The only thing to prevent this is to create some accounts on your service (which is something I want to avoid) or doing ugly things such as using IP addresses to distinguish between current users...

I'd say you have sessions for your users at least, to do basic things like shopping carts or even sticky load balancing. so map those to accounts and you will only ever need as much accounts/unused addresses as concurrent sessions. IMHO, bitcoind gives you some great tools at hand if you want to get things up and and running quickly.

If you want to build things neatly, build on bitcoinj/BOP with deterministic wallets, optimise wallet performance once needed, and then contribute your changes back instead of sitting on them.

blockchain.info is also not perfect, as you will have archive addresses to keep wallet performance up: http://blockchain.info/api/blockchain_wallet_api


Title: Re: Bitcoin API with callback function?
Post by: danystatic on October 10, 2013, 03:52:53 AM
yes, sessions work for this, just hope the 'user' does not pays and close the web-explorer(chrome,firefox,etc..) before the session expires =)
I know it's a small time-frame, but possible
also
what about two clients asking for   getnewaddress(),  (php)

is it possible two clients get same address because they clicked almost at the same time?
I think is not possible but someone said it was, but I test it and still it is not working like that, but I don't know on a heavier load...


Title: Re: Bitcoin API with callback function?
Post by: ron_ on July 11, 2014, 02:57:49 PM
btcipn.com does the job pretty much well and it is easy to integrate if you are familiar with paypal ipn

- no 3rd party wallet (use your own wallet)
- no registration required
- your website will be listed on their home page

i have tested it and it works just great


Title: Re: Bitcoin API with callback function?
Post by: crypto777 on November 11, 2014, 01:39:28 PM

You can use GoUrl PHP Payment Bitcoin API (https://gourl.io/) -

https://gourl.io/


It is support callbacks.


Title: Re: Bitcoin API with callback function?
Post by: HackerBOSS on April 13, 2016, 03:25:42 PM
Why callback blockchain.info don't work now?


Title: Re: Bitcoin API with callback function?
Post by: HackerBOSS on April 15, 2016, 06:23:59 AM

You can use GoUrl PHP Payment Bitcoin API (https://gourl.io/) -

https://gourl.io/


It is support callbacks.

nice service..
but how use it?
need vps and node?
please tell me details


Title: Re: Bitcoin API with callback function?
Post by: HackerBOSS on April 15, 2016, 06:26:17 AM
blockchain-info callback works now,
they have problem this it and fix now


Title: Re: Bitcoin API with callback function?
Post by: a7594li on April 16, 2016, 12:57:18 AM
I think blockchain-info callback works well.
there have no other problem.