Bitcoin Forum
May 05, 2024, 11:55:23 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1] 2 »  All
  Print  
Author Topic: Bitcoin API with callback function?  (Read 9015 times)
Mcoroklo (OP)
Jr. Member
*
Offline Offline

Activity: 77
Merit: 1


View Profile WWW
January 14, 2013, 06:46:00 PM
Merited by ABCbits (1)
 #1

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!
1714910123
Hero Member
*
Offline Offline

Posts: 1714910123

View Profile Personal Message (Offline)

Ignore
1714910123
Reply with quote  #2

1714910123
Report to moderator
1714910123
Hero Member
*
Offline Offline

Posts: 1714910123

View Profile Personal Message (Offline)

Ignore
1714910123
Reply with quote  #2

1714910123
Report to moderator
1714910123
Hero Member
*
Offline Offline

Posts: 1714910123

View Profile Personal Message (Offline)

Ignore
1714910123
Reply with quote  #2

1714910123
Report to moderator
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
grau
Hero Member
*****
Offline Offline

Activity: 836
Merit: 1021


bits of proof


View Profile WWW
January 14, 2013, 06:56:06 PM
 #2

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.
Realpra
Hero Member
*****
Offline Offline

Activity: 815
Merit: 1000


View Profile
January 14, 2013, 08:32:34 PM
 #3

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..

Cheap and sexy Bitcoin card/hardware wallet, buy here:
http://BlochsTech.com
Mcoroklo (OP)
Jr. Member
*
Offline Offline

Activity: 77
Merit: 1


View Profile WWW
January 15, 2013, 10:11:36 AM
 #4

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.

BitcoinHoarder
Full Member
***
Offline Offline

Activity: 144
Merit: 100


View Profile
January 15, 2013, 12:41:44 PM
 #5

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!
ingrownpocket
Legendary
*
Offline Offline

Activity: 952
Merit: 1000


View Profile
January 15, 2013, 02:24:16 PM
 #6

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)
Mcoroklo (OP)
Jr. Member
*
Offline Offline

Activity: 77
Merit: 1


View Profile WWW
January 15, 2013, 05:46:36 PM
 #7

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 Smiley
grau
Hero Member
*****
Offline Offline

Activity: 836
Merit: 1021


bits of proof


View Profile WWW
January 15, 2013, 06:34:02 PM
Last edit: January 15, 2013, 07:29:58 PM by grau
 #8

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 Smiley

See the wiki for more: https://github.com/bitsofproof/supernode/wiki
ingrownpocket
Legendary
*
Offline Offline

Activity: 952
Merit: 1000


View Profile
January 15, 2013, 08:25:37 PM
 #9

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.
Mcoroklo (OP)
Jr. Member
*
Offline Offline

Activity: 77
Merit: 1


View Profile WWW
January 15, 2013, 10:11:36 PM
 #10

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?
ingrownpocket
Legendary
*
Offline Offline

Activity: 952
Merit: 1000


View Profile
January 16, 2013, 09:36:51 AM
 #11

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
Mcoroklo (OP)
Jr. Member
*
Offline Offline

Activity: 77
Merit: 1


View Profile WWW
January 16, 2013, 10:35:20 AM
 #12

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.
Mike Hearn
Legendary
*
expert
Offline Offline

Activity: 1526
Merit: 1129


View Profile
January 16, 2013, 10:38:34 AM
 #13

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
ingrownpocket
Legendary
*
Offline Offline

Activity: 952
Merit: 1000


View Profile
January 16, 2013, 12:32:16 PM
 #14

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.
Mcoroklo (OP)
Jr. Member
*
Offline Offline

Activity: 77
Merit: 1


View Profile WWW
January 16, 2013, 01:13:12 PM
 #15

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.
danystatic
Full Member
***
Offline Offline

Activity: 235
Merit: 100


View Profile
September 30, 2013, 06:36:40 PM
 #16

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
BitcoinLeader
Member
**
Offline Offline

Activity: 84
Merit: 10


View Profile WWW
September 30, 2013, 07:22:08 PM
 #17

I just released the open-source 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.

Sukrim
Legendary
*
Offline Offline

Activity: 2618
Merit: 1006


View Profile
October 08, 2013, 08:21:50 AM
 #18

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.

https://www.coinlend.org <-- automated lending at various exchanges.
https://www.bitfinex.com <-- Trade BTC for other currencies and vice versa.
johba
Member
**
Offline Offline

Activity: 68
Merit: 10



View Profile WWW
October 08, 2013, 03:34:21 PM
 #19


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;
    }
  });
Sukrim
Legendary
*
Offline Offline

Activity: 2618
Merit: 1006


View Profile
October 09, 2013, 12:50:40 PM
 #20

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.

https://www.coinlend.org <-- automated lending at various exchanges.
https://www.bitfinex.com <-- Trade BTC for other currencies and vice versa.
Pages: [1] 2 »  All
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!