Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: madmadmax on May 12, 2013, 11:49:35 PM



Title: How to use Walletnotify?
Post by: madmadmax on May 12, 2013, 11:49:35 PM
How do you post or get using walletnotify?


Title: Re: How to use Walletnotify?
Post by: kjj on May 13, 2013, 11:24:42 AM
If you are talking about the -walletnotify config option in 0.8.2rc1, it works exactly like -blocknotify.  You specify the path to a program to be run.

The program will be run with a single argument (the transaction hash) when a new transaction hits your wallet.  Actually, it will run once or twice per transaction.  First time will be if you receive that transaction as a transaction, and the second time when you receive it as part of a block.

That program can be a script that uses some other tool (curl, wget, whatever) to issue a call out to an external webservice, or it can do whatever you need directly (update a database, logfile, etc).

If you are a high volume site that gets lots of transactions, you may need to be careful with it.  It can spawn a lot of new processes, so you should make your script fast and simple.  Just dump the txhash to a journal file (or table) and exit, for example, with a cron job to come around later to collect and process them in batches.

People were looking for a simple way to track incoming transactions, and this was the easiest way to do it.  It has some quirks, but it is still vastly superior to the hacks people were having to use before.


Title: Re: How to use Walletnotify?
Post by: madmadmax on May 13, 2013, 01:56:16 PM
If you are talking about the -walletnotify config option in 0.8.2rc1, it works exactly like -blocknotify.  You specify the path to a program to be run.

The program will be run with a single argument (the transaction hash) when a new transaction hits your wallet.  Actually, it will run once or twice per transaction.  First time will be if you receive that transaction as a transaction, and the second time when you receive it as part of a block.

That program can be a script that uses some other tool (curl, wget, whatever) to issue a call out to an external webservice, or it can do whatever you need directly (update a database, logfile, etc).

If you are a high volume site that gets lots of transactions, you may need to be careful with it.  It can spawn a lot of new processes, so you should make your script fast and simple.  Just dump the txhash to a journal file (or table) and exit, for example, with a cron job to come around later to collect and process them in batches.

People were looking for a simple way to track incoming transactions, and this was the easiest way to do it.  It has some quirks, but it is still vastly superior to the hacks people were having to use before.

Cron job lol, it's subbitcoin level security that might fly with Paypal or banks that don't care that their accounts with tens of thousands of dollars are being sold for 100 bucks on the darknet...


Title: Re: How to use Walletnotify?
Post by: kjj on May 13, 2013, 02:27:25 PM
Cron job lol, it's subbitcoin level security that might fly with Paypal or banks that don't care that their accounts with tens of thousands of dollars are being sold for 100 bucks on the darknet...

I've read this four times now, and I still don't know what you are trying to say.


Title: Re: How to use Walletnotify?
Post by: madmadmax on May 13, 2013, 05:50:54 PM
Cron job lol, it's subbitcoin level security that might fly with Paypal or banks that don't care that their accounts with tens of thousands of dollars are being sold for 100 bucks on the darknet...

I've read this four times now, and I still don't know what you are trying to say.

Nevermind, can you please provide a sample of setting up walletnotify to execute an app?


Title: Re: How to use Walletnotify?
Post by: kjj on May 13, 2013, 07:20:24 PM
On the server I used for testing, in my bitcoin.conf:
Code:
walletnotify=/home/btcdev/walletnotify.sh %s
blocknotify=/home/btcdev/blocknotify.sh %s

The %s in the command line gets replaced with the (ASCII) hex string of the transaction hash, just like -blocknotify replaces it with the block hash.

And the program can be as simple or as complicated as you like.  Here is a simple shell script:

Code:
#!/bin/bash
F=/home/btcdev/wallet_transaction_log
D=`date +"%Y%m%d%H%M%S"`
echo ${D} - ${1} >> ${F}

which gives lines like:

Code:
20130513123015 - 6fa6c8ff08f122327b7a0a329d7632f243038f0fc96cce1248cb4948d0509ecf

You aren't limited to shell scripts, of course.

A pipe would have been better, but they aren't portable.  Even if we had been willing to limit it to just UNIX-ish systems, there would have been horrible locking problems, and these notices simply weren't worth the effort to work around them*.  If you want similar behavior, you can fake a pipe with netcat, so that you could have a long running service that accepts TCP connections from localhost, and just call netcat to dump the txid to that socket.

Did you know that named pipes can stall in both directions, potentially DOSing one of the client threads?  There are ways around it, of course, but you have to throw out a lot of the abstractions, so there would have been a very un-C++ chunk of code in the bitcoin client, just for dealing with the pipes.  At least that was how it looked to me when I was researching it.  I don't do much with C++, so I'm hoping that someone in the audience is more skilled than I am, and will read this and say "You dumbass, why didn't you just do X?", or even better, rewrite it for me.  :)


Title: Re: How to use Walletnotify?
Post by: madmadmax on May 16, 2013, 05:44:18 PM
On the server I used for testing, in my bitcoin.conf:
Code:
walletnotify=/home/btcdev/walletnotify.sh %s
blocknotify=/home/btcdev/blocknotify.sh %s

The %s in the command line gets replaced with the (ASCII) hex string of the transaction hash, just like -blocknotify replaces it with the block hash.

And the program can be as simple or as complicated as you like.  Here is a simple shell script:

Code:
#!/bin/bash
F=/home/btcdev/wallet_transaction_log
D=`date +"%Y%m%d%H%M%S"`
echo ${D} - ${1} >> ${F}

which gives lines like:

Code:
20130513123015 - 6fa6c8ff08f122327b7a0a329d7632f243038f0fc96cce1248cb4948d0509ecf

You aren't limited to shell scripts, of course.

A pipe would have been better, but they aren't portable.  Even if we had been willing to limit it to just UNIX-ish systems, there would have been horrible locking problems, and these notices simply weren't worth the effort to work around them*.  If you want similar behavior, you can fake a pipe with netcat, so that you could have a long running service that accepts TCP connections from localhost, and just call netcat to dump the txid to that socket.

Did you know that named pipes can stall in both directions, potentially DOSing one of the client threads?  There are ways around it, of course, but you have to throw out a lot of the abstractions, so there would have been a very un-C++ chunk of code in the bitcoin client, just for dealing with the pipes.  At least that was how it looked to me when I was researching it.  I don't do much with C++, so I'm hoping that someone in the audience is more skilled than I am, and will read this and say "You dumbass, why didn't you just do X?", or even better, rewrite it for me.  :)

So basically, I can write a quick C# app to send a udp packet to the local host and listen there with the server. I am wondering what is the DDoS potential of such an attack?


Title: Re: How to use Walletnotify?
Post by: kjj on May 17, 2013, 12:50:20 AM
DDOS?  zero.  There is no amplification, no redirection.

Someone can try to DOS you.  But it'll be expensive.  Your node will spawn a process for each transaction that hits your wallet, not for each output.  You should strive to make the spawned process as light and short lived as possible, but for the most part, there isn't much danger.


Title: Re: How to use Walletnotify?
Post by: inca on December 15, 2013, 01:15:39 AM
Hi,

I am trying to use the -walletnotify option to run a php script which updates a log file/sql db with transaction id of new transaction affecting wallet.

For some reason I cannot get it working. I am using bitcoin version 80100.

I have tried this in my bitcoin.conf:

walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

and..

walletnotify="php /home/blahblah/Downloads/btcdev/walletnotify.php %s"


and also run bitcoind with and without the walletnotify commandline options: bitcoind -datadir=/home/blahblah/Downloads/testnet -testnet -debug -printtoconsole -walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

I can see the new transactions coming in but neither bitcoin-qt or bitcoind seem to try to run my script or error.

Any suggestions? ;D

Inca


Title: Re: How to use Walletnotify?
Post by: kjj on December 15, 2013, 01:28:33 AM
Specify the path to php.


Title: Re: How to use Walletnotify?
Post by: BlockChainLottery on December 17, 2013, 01:41:51 PM
When using shell script, does the log file has write protection?
If for example, two notifications being issued, can the text become scrambled if the two scripts trying to write at the same time?


Title: Re: How to use Walletnotify?
Post by: kjj on December 17, 2013, 01:50:52 PM
If that is a concern for you, use something that you know can handle concurrent writes, like a database.


Title: Re: How to use Walletnotify?
Post by: jlp on January 30, 2014, 05:14:51 PM
Hi,

I am trying to use the -walletnotify option to run a php script which updates a log file/sql db with transaction id of new transaction affecting wallet.

For some reason I cannot get it working. I am using bitcoin version 80100.

I have tried this in my bitcoin.conf:

walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

and..

walletnotify="php /home/blahblah/Downloads/btcdev/walletnotify.php %s"


and also run bitcoind with and without the walletnotify commandline options: bitcoind -datadir=/home/blahblah/Downloads/testnet -testnet -debug -printtoconsole -walletnotify=php /home/blahblah/Downloads/btcdev/walletnotify.php %s

I can see the new transactions coming in but neither bitcoin-qt or bitcoind seem to try to run my script or error.

Any suggestions? ;D

Inca

I can get walletnotify to run a shell script.  Similar to user Inca, I cannot get walletnofiy to run a PHP program.

I am using Bitcoin-QT version 0.8.6 in testnet mode on a Mac OSX.  I have tried this in my bitcoin.conf:

walletnotify=php /Users/JLP/git_source/src/bin/walletnotify.php %s

and..

walletnotify="php /Users/JLP/git_source/src/bin/walletnotify.php %s"

I ran this in my terminal:

chmod a+x /Users/JLP/git_source/src/bin/walletnotify.php

but still to no avail.  Can someone help?

Update:  I found out how to invoke the php program.  I used curl:

walletnotify=curl http://localhost:8888/walletnotify.php/?transactionhash=%s

Is this transaction hash equal to the transaction id as required by the gettransaction command from https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list (https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list)?


Title: Re: How to use Walletnotify?
Post by: kjj on January 30, 2014, 06:59:42 PM
Specify the path to php.


Title: Re: How to use Walletnotify?
Post by: jlp on January 30, 2014, 07:08:09 PM
Specify the path to php.

I'm not sure if your posting is in reply to my question about invoking my PHP program.  If so, I'm not sure what you mean.  I had specified the path to the php file.  It is /Users/JLP/git_source/src/bin/walletnotify.php in the following string:

walletnotify=php /Users/JLP/git_source/src/bin/walletnotify.php %s

If I can get this to work, isn't this the preferred method than to use curl, which seems like a roundabout way?


Title: Re: How to use Walletnotify?
Post by: secbc on January 30, 2014, 08:41:01 PM
KJJ is saying the path to the PHP executable NOT the script, you have that.

Depending on your system it will most likely be something like

/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php %s

if your on a linux-ish system (Mac, linux) you can run `whereis php` and that should tell you


Title: Re: How to use Walletnotify?
Post by: jlp on January 31, 2014, 04:02:20 AM
KJJ is saying the path to the PHP executable NOT the script, you have that.

Depending on your system it will most likely be something like

/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php %s

if your on a linux-ish system (Mac, linux) you can run `whereis php` and that should tell you

Thanks for clarifying it.

I ran `whereis php` and terminal replied with:

/usr/bin/php

I changed bitcoin.conf so that it has the following:

walletnotify=/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php/?trxhash=%s

...but it still does not work.  I changed it to the following:

walletnotify="/usr/bin/php /Users/JLP/git_source/src/bin/walletnotify.php/?trxhash=%s"

...but it still does not work.  Does anyone have any suggestions on how to get this to work?


Title: Re: How to use Walletnotify?
Post by: kjj on January 31, 2014, 01:19:16 PM
Is ? a valid means of passing arguments to PHP on the command line?  I've never tried it.  I always use argc/argv, but my quick google search suggests that you can also use CGI style arguments:

/path/to/php /path/to/script.php trxhash=%s

and trxhash will be populated in $_GET, etc.


Title: Re: How to use Walletnotify?
Post by: jlp on January 31, 2014, 03:34:27 PM
Is ? a valid means of passing arguments to PHP on the command line?  I've never tried it.  I always use argc/argv, but my quick google search suggests that you can also use CGI style arguments:

/path/to/php /path/to/script.php trxhash=%s

and trxhash will be populated in $_GET, etc.

The following works with ? as a means of passing arguments to PHP:

walletnotify=curl http://localhost:8888/script.php/?trxhash=%s

How do I use argc/argv?

I tried the following by entering it in my Mac terminal and it works:

/usr/bin/php /path/to/script.php

I tried the following by entering them in my Mac terminal, but they do not work:

/usr/bin/php /path/to/script.php/?wallethash=testing

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php/?wallethash=testing

/usr/bin/php /path/to/script.php?wallethash=testing

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php?wallethash=testing

I put in the following into my PHP program:

print_r($_GET['blockhash']);
print_r($_SERVER['QUERY_STRING']);

I tried the following in my Mac terminal:

/usr/bin/php /path/to/script.php wallethash=testing

The above returns this error:

PHP Notice:  Undefined index:  wallethash in /path/to/script.php on line 17
PHP Notice:  Undefined index:  QUERY_STRING in /path/to/script.php on line 18

I welcome any other suggestions.


Title: Re: How to use Walletnotify?
Post by: kjj on January 31, 2014, 06:08:41 PM
I'm not on a mac, but try these anyway.

This is a minimal, but functional, PHP script that can be called from walletnotify:

Code: (walletnotify.php)
!/bin/php
<?php

if(2==$argc){
 
$fp=fopen("/tmp/notify_wallet","a");
 
$out=date("Ymd His")." - ".$argv[1]."\n";
 
fwrite($fp,$out);
}
?>


And two tested and working walletnotify lines:

Code:
walletnotify=/usr/local/bin/walletnotify.php %s
Code:
walletnotify=/bin/php /usr/local/bin/walletnotify.php %s

Note that there are no quotes in either line.

For the first option, the php file must be executable, and the path to your php binary must be set in the first line.  In the second option, you need to set your php path correctly in the walletnotify line.

Try these two first.  If you can get one of them working, you have a working baseline for making your own changes.  If you can't get it working, let me know and we'll figure it out.

Is ? a valid means of passing arguments to PHP on the command line?  I've never tried it.  I always use argc/argv, but my quick google search suggests that you can also use CGI style arguments:

/path/to/php /path/to/script.php trxhash=%s

and trxhash will be populated in $_GET, etc.

The following works with ? as a means of passing arguments to PHP:

walletnotify=curl http://localhost:8888/script.php/?trxhash=%s

curl is talking to your webserver, so HTTP syntax rules applies there (but not here, unless you want to run it that way).

How do I use argc/argv?

See above.  Basically, argc is the number of arguments on the command line, including the name of the script.  argv is an array of the command line elements, starting with argv[0] set to the name of the script.

I tried the following by entering it in my Mac terminal and it works:

/usr/bin/php /path/to/script.php

I tried the following by entering them in my Mac terminal, but they do not work:

/usr/bin/php /path/to/script.php/?wallethash=testing

You have no file named "/path/to/script.php/?wallethash=testing" on your system.  ?, = and even / are perfectly valid characters to have in a filename.  (really!)

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php/?wallethash=testing

/usr/bin/php /path/to/script.php?wallethash=testing

The above returns this error:

Could not open input file: /usr/bin/php /path/to/script.php?wallethash=testing

Ditto.

I put in the following into my PHP program:

print_r($_GET['blockhash']);
print_r($_SERVER['QUERY_STRING']);

I tried the following in my Mac terminal:

/usr/bin/php /path/to/script.php wallethash=testing

The above returns this error:

PHP Notice:  Undefined index:  wallethash in /path/to/script.php on line 17
PHP Notice:  Undefined index:  QUERY_STRING in /path/to/script.php on line 18

I welcome any other suggestions.

Double check your names.  You seem to be switching between wallethash and blockhash.  Also, try print_r($_GET);


Title: Re: How to use Walletnotify?
Post by: jlp on January 31, 2014, 08:55:42 PM

How do I use argc/argv?

See above.  Basically, argc is the number of arguments on the command line, including the name of the script.  argv is an array of the command line elements, starting with argv[0] set to the name of the script.


I got it to work with argc and argv.  I put the following into bitcoin.conf:

walletnotify=/usr/bin/php /path/to/walletnotify.php %s

I have the following in walletnotify.php:

Code:
<?php
if(2==$argc){
require_once 'jsonRPCClient.php';
$bitcoin = new jsonRPCClient('http://username:password@127.0.0.1:8332/');

$walletinfo $bitcoin->getinfo();
$trxinfo $bitcoin->gettransaction($argv[1]);

// Append data to the file
$new "\n\nTransaction hash: ".$argv[1]."\nGetinfo balance: ".$walletinfo["balance"]
."\n Gettransaction amount: ".$trxinfo["amount"]
."\n Gettransaction confirmations: ".$trxinfo["confirmations"]
."\n Gettransaction blockhash: ".$trxinfo["blockhash"]
."\n Gettransaction blockindex: ".$trxinfo["blockindex"]
."\n Gettransaction blocktime: ".$trxinfo["blocktime"]
."\n Gettransaction txid: ".$trxinfo["txid"]
."\n Gettransaction time: ".$trxinfo["time"]
."\n Gettransaction timereceived: ".$trxinfo["timereceived"]
."\n Gettransaction account: ".$trxinfo["details"][0]["account"]
."\n Gettransaction address: ".$trxinfo["details"][0]["address"]
."\n Gettransaction category: ".$trxinfo["details"][0]["category"]
."\n Gettransaction amount: ".$trxinfo["details"][0]["amount"]
//."\n Gettransaction fee: ".$trxinfo["details"][0]["fee"]  // According to https://en.bitcoin.it/wiki/Original_Bitcoin_client/API_calls_list, fee is returned, but it doesn't seem that way here
;

$fp=fopen("/tmp/notify_wallet.txt","a");
fwrite($fp,$new);
}
?>

When I send testnet coins from my eWallet to my Bitcoin-QT, the above walletnotify.php fetches the transaction's data from the wallet and writes it to the text file.  It works well.

I didn't need the following code:

Code:
!/bin/php

Thanks for your help!


Title: Re: How to use Walletnotify?
Post by: fduvincent on March 18, 2014, 11:44:06 AM
Sorry to bump this topic but i need to ask something.
I tried to test the walletnotify like you and it worked. but my problem is that it notify only after 0 and 1 confirmation then it stops.
I need to know if it is possible to set it for a specific number of confirmation because it will help for a callback. I thought that
it is possible to use minconf in config but when i add it, i do not even get data logged in the file.


Title: Re: How to use Walletnotify?
Post by: Automatic on March 18, 2014, 01:39:05 PM
DDOS?  zero.  There is no amplification, no redirection.

Someone can try to DOS you.  But it'll be expensive.  Your node will spawn a process for each transaction that hits your wallet, not for each output.  You should strive to make the spawned process as light and short lived as possible, but for the most part, there isn't much danger.

For reference, it actually runs the script twice, once when you first hear of it, once when it hits one confirmation (And thus hits the blockchain).


Title: Re: How to use Walletnotify?
Post by: fduvincent on March 18, 2014, 02:01:45 PM
DDOS?  zero.  There is no amplification, no redirection.

Someone can try to DOS you.  But it'll be expensive.  Your node will spawn a process for each transaction that hits your wallet, not for each output.  You should strive to make the spawned process as light and short lived as possible, but for the most part, there isn't much danger.

For reference, it actually runs the script twice, once when you first hear of it, once when it hits one confirmation (And thus hits the blockchain).
Is there a possibility to make it runs the script after one confirmation ? I'm trying to make a callback after at least three confirmations.


Title: Re: How to use Walletnotify?
Post by: Automatic on March 18, 2014, 02:05:53 PM
DDOS?  zero.  There is no amplification, no redirection.

Someone can try to DOS you.  But it'll be expensive.  Your node will spawn a process for each transaction that hits your wallet, not for each output.  You should strive to make the spawned process as light and short lived as possible, but for the most part, there isn't much danger.

For reference, it actually runs the script twice, once when you first hear of it, once when it hits one confirmation (And thus hits the blockchain).
Is there a possibility to make it runs the script after one confirmation ? I'm trying to make a callback after at least three confirmations.

Add TXID to DB after it calls it at one confirmation (To prevent against mutational, tell the user you received it at zero, however), then listen for blocknotify, on blocknotify, grab the TXID info from bitcoind again and update the confirmation. It should always be lastone+1, but, don't assume that, bugs can happen if you do, grab a new copy of the TX from bitcoind and update the confirmation from there.


Title: Re: How to use Walletnotify?
Post by: kerimk2 on August 11, 2014, 05:15:03 AM
Lets say I was using a blockchain.info daemon, how would I use walletnotify from them. Would that be possible? I'd prefer not to run a VPS but I might if I have to. My home network and computer wouldn't be trustworthy enough to be used for a public business with hundreds of customers.


Title: Re: How to use Walletnotify?
Post by: BlockChainLottery on August 11, 2014, 08:11:30 AM
Lets say I was using a blockchain.info daemon, how would I use walletnotify from them. Would that be possible? I'd prefer not to run a VPS but I might if I have to. My home network and computer wouldn't be trustworthy enough to be used for a public business with hundreds of customers.

If you want to be notified about a transaction in your blockchain.info wallet, just use the http callback (https://blockchain.info/nl/api/blockchain_wallet_api).
When a transaction comes in, you get a call back every new block until you acknowlegde it.


Title: Re: How to use Walletnotify?
Post by: kerimk2 on August 12, 2014, 05:33:14 PM
Lets say I was using a blockchain.info daemon, how would I use walletnotify from them. Would that be possible? I'd prefer not to run a VPS but I might if I have to. My home network and computer wouldn't be trustworthy enough to be used for a public business with hundreds of customers.

If you want to be notified about a transaction in your blockchain.info wallet, just use the http callback (https://blockchain.info/nl/api/blockchain_wallet_api).
When a transaction comes in, you get a call back every new block until you acknowlegde it.
I have tried blockchain's callbacks before, but they do not work. Sometimes they send duplicates, sometimes they don't even send at all, and they send the wrong information.


Title: Re: How to use Walletnotify?
Post by: BlockChainLottery on August 12, 2014, 08:03:19 PM
Lets say I was using a blockchain.info daemon, how would I use walletnotify from them. Would that be possible? I'd prefer not to run a VPS but I might if I have to. My home network and computer wouldn't be trustworthy enough to be used for a public business with hundreds of customers.

If you want to be notified about a transaction in your blockchain.info wallet, just use the http callback (https://blockchain.info/nl/api/blockchain_wallet_api).
When a transaction comes in, you get a call back every new block until you acknowlegde it.
I have tried blockchain's callbacks before, but they do not work. Sometimes they send duplicates, sometimes they don't even send at all, and they send the wrong information.

Yeah, the http callback is not a really reliable source. You can't count on it for managing a transaction database, and should always have a second system in place to check payments. It is more like a gadget.
Duplicates can be send if the acknowlegdment hasn't arrived correctly. Nothing receiving at all can be caused by, well, the same reason why you can't connect to a website some times. Receiving wrong information I haven't experienced using the callback function, so I can't say anything about that.

If you want something really reliable, you haven't a lot of options I can think of. It's an http callback from block chain, or a bitcoin deamon at home with wallet notify, or custom made software that acts like a bitcoin node. Maybe there is some other software around that is better suited for these kind of things? What exactly are your requirements?


Title: Re: How to use Walletnotify?
Post by: kerimk2 on August 12, 2014, 08:11:36 PM
Wat I did is make a script which automatically sorts get transactions every 15 seconds with a cron job, and it works well. It can handle 10 transactions every 15 seconds, and I can easily make it more.


Title: Re: How to use Walletnotify?
Post by: BlockChainLottery on August 13, 2014, 08:28:47 AM
Then you don't really need a notification, right? Or would you like your costumers to see an instant notification of a transaction?


Title: Re: How to use Walletnotify?
Post by: skyzer on September 02, 2014, 06:50:29 AM
Lets say I was using a blockchain.info daemon, how would I use walletnotify from them. Would that be possible? I'd prefer not to run a VPS but I might if I have to. My home network and computer wouldn't be trustworthy enough to be used for a public business with hundreds of customers.

If you want to be notified about a transaction in your blockchain.info wallet, just use the http callback (https://blockchain.info/nl/api/blockchain_wallet_api).
When a transaction comes in, you get a call back every new block until you acknowlegde it.
I have tried blockchain's callbacks before, but they do not work. Sometimes they send duplicates, sometimes they don't even send at all, and they send the wrong information.

Yeah, the http callback is not a really reliable source. You can't count on it for managing a transaction database, and should always have a second system in place to check payments. It is more like a gadget.
Duplicates can be send if the acknowlegdment hasn't arrived correctly. Nothing receiving at all can be caused by, well, the same reason why you can't connect to a website some times. Receiving wrong information I haven't experienced using the callback function, so I can't say anything about that.

If you want something really reliable, you haven't a lot of options I can think of. It's an http callback from block chain, or a bitcoin deamon at home with wallet notify, or custom made software that acts like a bitcoin node. Maybe there is some other software around that is better suited for these kind of things? What exactly are your requirements?
Would be also interested on other opinions besides bitcoind on using for example btcd, bitcoinj, libbitcoin full node implementations?


Title: Re: How to use Walletnotify?
Post by: skyzer on September 08, 2014, 08:34:53 PM
On the server I used for testing, in my bitcoin.conf:
Code:
walletnotify=/home/btcdev/walletnotify.sh %s
blocknotify=/home/btcdev/blocknotify.sh %s

The %s in the command line gets replaced with the (ASCII) hex string of the transaction hash, just like -blocknotify replaces it with the block hash.

And the program can be as simple or as complicated as you like.  Here is a simple shell script:

Code:
#!/bin/bash
F=/home/btcdev/wallet_transaction_log
D=`date +"%Y%m%d%H%M%S"`
echo ${D} - ${1} >> ${F}

which gives lines like:

Code:
20130513123015 - 6fa6c8ff08f122327b7a0a329d7632f243038f0fc96cce1248cb4948d0509ecf

You aren't limited to shell scripts, of course.

A pipe would have been better, but they aren't portable.  Even if we had been willing to limit it to just UNIX-ish systems, there would have been horrible locking problems, and these notices simply weren't worth the effort to work around them*.  If you want similar behavior, you can fake a pipe with netcat, so that you could have a long running service that accepts TCP connections from localhost, and just call netcat to dump the txid to that socket.

*  Did you know that named pipes can stall in both directions, potentially DOSing one of the client threads?  There are ways around it, of course, but you have to throw out a lot of the abstractions, so there would have been a very un-C++ chunk of code in the bitcoin client, just for dealing with the pipes.  At least that was how it looked to me when I was researching it.  I don't do much with C++, so I'm hoping that someone in the audience is more skilled than I am, and will read this and say "You dumbass, why didn't you just do X?", or even better, rewrite it for me.  :)

Hey, anybody else has issue in bitcoind with walletnotify that on first confirmation it shoots the curl twice immidiately and when checking the wallet_transaction_log file, there is also same txid written twice. so the issue is not in my built API server, but in bitcoind. any clues?


Title: Re: How to use Walletnotify?
Post by: kerimk2 on September 09, 2014, 01:30:24 AM
On the server I used for testing, in my bitcoin.conf:
Code:
walletnotify=/home/btcdev/walletnotify.sh %s
blocknotify=/home/btcdev/blocknotify.sh %s

The %s in the command line gets replaced with the (ASCII) hex string of the transaction hash, just like -blocknotify replaces it with the block hash.

And the program can be as simple or as complicated as you like.  Here is a simple shell script:

Code:
#!/bin/bash
F=/home/btcdev/wallet_transaction_log
D=`date +"%Y%m%d%H%M%S"`
echo ${D} - ${1} >> ${F}

which gives lines like:

Code:
20130513123015 - 6fa6c8ff08f122327b7a0a329d7632f243038f0fc96cce1248cb4948d0509ecf

You aren't limited to shell scripts, of course.

A pipe would have been better, but they aren't portable.  Even if we had been willing to limit it to just UNIX-ish systems, there would have been horrible locking problems, and these notices simply weren't worth the effort to work around them*.  If you want similar behavior, you can fake a pipe with netcat, so that you could have a long running service that accepts TCP connections from localhost, and just call netcat to dump the txid to that socket.

*  Did you know that named pipes can stall in both directions, potentially DOSing one of the client threads?  There are ways around it, of course, but you have to throw out a lot of the abstractions, so there would have been a very un-C++ chunk of code in the bitcoin client, just for dealing with the pipes.  At least that was how it looked to me when I was researching it.  I don't do much with C++, so I'm hoping that someone in the audience is more skilled than I am, and will read this and say "You dumbass, why didn't you just do X?", or even better, rewrite it for me.  :)

Hey, anybody else has issue in bitcoind with walletnotify that on first confirmation it shoots the curl twice immidiately and when checking the wallet_transaction_log file, there is also same txid written twice. so the issue is not in my built API server, but in bitcoind. any clues?
To prevent the bad things coming from this error just check for previous transaction duplicate in your script


Title: Re: How to use Walletnotify?
Post by: louislee on January 23, 2015, 08:57:48 AM
In bitcoind.conf:
walletnotify=C:\Users\User\AppData\Roaming\Bitcoin\walletnotify.sh %s
In walletnotify.sh:
#!/bin/bash
F=walletnotify_log.txt
D=`date +"%Y%m%d%H%M%S"`
echo ${D} - ${1}>> ${F}
I Click the walletnotify.sh,and i can see 20150123105344 - in the walletnotify_log.txt.
When i deposit bitcoin,just see the flashing window(cmd window).i can't see the new Date and transactions.
what wrong?
may i use walletnotify on Window 7 ?
Best Regards.


Title: Re: How to use Walletnotify?
Post by: CohibAA on September 25, 2015, 03:58:52 AM
Is walletnotify limited to one occurrence in bitcoin.conf, or can it be used multiple times?  Which one below would be better to use, or something different?

Code:
walletnotify=cmd-A
walletnotify=cmd-B

or

Code:
walletnotify=cmd-A && cmd-B

I'm guessing the second is better, if the first is even possible.  While I am asking, how about alertnotify and blocknotify?

 ???


Title: Re: How to use Walletnotify?
Post by: elbandi on September 25, 2015, 11:25:22 AM
Code:
walletnotify=cmd-A && cmd-B

I'm guessing the second is better, if the first is even possible.  While I am asking, how about alertnotify and blocknotify?

 ???

walletnotify=/usr/local/bin/notifyscript.sh

and you can call any commands in the script.


Title: Re: How to use Walletnotify?
Post by: Martin SK on December 03, 2017, 11:47:08 AM
Hey,

When I try to run wallet notify on a script I get this error:

Code:
2017-12-03 11:26:40 AddToWallet 8525ace8b3bac67a39b28d18f96186e3a76598fd36fe6f4b242c8f4ff2defa2a  new
2017-12-03 11:26:40 runCommand error: system(/home/pi/.bitcoin/pay.py 8525ace8b3bac67a39b28d18f96186e3a76598fd36fe6f4b242c8f4ff2defa2a) returned 512


The script is in the .bitcoin folder and has the these permissions:
-rwxr-xr-x  1 pi pi      150 Nov 28 12:09 pay.py

Anybody know how to make it work?

Thanks.


Title: Re: How to use Walletnotify?
Post by: rexter on December 03, 2017, 08:22:57 PM
Walletnotify notifies you twice in a deposit. 1- Once someone deposited into an address (0 conf). 2- When that transaction gets 1 confirmation. And it also notifies you if you "withdraw" one address.


Title: Re: How to use Walletnotify?
Post by: Martin SK on January 15, 2018, 12:20:33 PM
Walletnotify notifies you twice in a deposit. 1- Once someone deposited into an address (0 conf). 2- When that transaction gets 1 confirmation. And it also notifies you if you "withdraw" one address.

Sorry for the (very) late reply, but I still don't see how that brings me closer to why I get an error code?
Thanks.


Title: Re: How to use Walletnotify?
Post by: yiuinubol on January 15, 2018, 02:09:46 PM
Walletnotify has limitations for use in bitcoin.conf once it happens or can be used many times, whichever one is better and easier to use so we need to be able to set a specific number. as it can help for a callback.