Bitcoin Forum
November 13, 2024, 10:25:51 AM *
News: Check out the artwork 1Dq created to commemorate this forum's 15th anniversary
 
   Home   Help Search Login Register More  
Pages: « 1 [2] 3 »  All
  Print  
Author Topic: How to use Walletnotify?  (Read 19054 times)
jlp
Sr. Member
****
Offline Offline

Activity: 266
Merit: 264


View Profile
January 31, 2014, 08:55:42 PM
Merited by ABCbits (3)
 #21


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!
fduvincent
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 18, 2014, 11:44:06 AM
 #22

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

Activity: 238
Merit: 109


View Profile
March 18, 2014, 01:39:05 PM
 #23

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

Please ask for a signed message from my on-site Bitcoin address (Check my profile) before doing any offsite trades with me.
fduvincent
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 18, 2014, 02:01:45 PM
 #24

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

Activity: 238
Merit: 109


View Profile
March 18, 2014, 02:05:53 PM
 #25

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.

Please ask for a signed message from my on-site Bitcoin address (Check my profile) before doing any offsite trades with me.
kerimk2
Full Member
***
Offline Offline

Activity: 140
Merit: 100

ACCOUNT BANNED. Email in sig!!


View Profile
August 11, 2014, 05:15:03 AM
 #26

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 need support for AutoPonzi contact: autoponzi@gmail.com
We aren't sure how long the ban is for. We aren't even sure why we are banned. But we'll try figure it out
BlockChainLottery
Sr. Member
****
Offline Offline

Activity: 332
Merit: 250


AwesomeDice.net


View Profile WWW
August 11, 2014, 08:11:30 AM
 #27

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.
When a transaction comes in, you get a call back every new block until you acknowlegde it.

kerimk2
Full Member
***
Offline Offline

Activity: 140
Merit: 100

ACCOUNT BANNED. Email in sig!!


View Profile
August 12, 2014, 05:33:14 PM
 #28

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

If you need support for AutoPonzi contact: autoponzi@gmail.com
We aren't sure how long the ban is for. We aren't even sure why we are banned. But we'll try figure it out
BlockChainLottery
Sr. Member
****
Offline Offline

Activity: 332
Merit: 250


AwesomeDice.net


View Profile WWW
August 12, 2014, 08:03:19 PM
 #29

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

kerimk2
Full Member
***
Offline Offline

Activity: 140
Merit: 100

ACCOUNT BANNED. Email in sig!!


View Profile
August 12, 2014, 08:11:36 PM
 #30

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.

If you need support for AutoPonzi contact: autoponzi@gmail.com
We aren't sure how long the ban is for. We aren't even sure why we are banned. But we'll try figure it out
BlockChainLottery
Sr. Member
****
Offline Offline

Activity: 332
Merit: 250


AwesomeDice.net


View Profile WWW
August 13, 2014, 08:28:47 AM
 #31

Then you don't really need a notification, right? Or would you like your costumers to see an instant notification of a transaction?

skyzer
Newbie
*
Offline Offline

Activity: 27
Merit: 0


View Profile
September 02, 2014, 06:50:29 AM
 #32

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.
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?
skyzer
Newbie
*
Offline Offline

Activity: 27
Merit: 0


View Profile
September 08, 2014, 08:34:53 PM
 #33

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

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?
kerimk2
Full Member
***
Offline Offline

Activity: 140
Merit: 100

ACCOUNT BANNED. Email in sig!!


View Profile
September 09, 2014, 01:30:24 AM
 #34

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

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

If you need support for AutoPonzi contact: autoponzi@gmail.com
We aren't sure how long the ban is for. We aren't even sure why we are banned. But we'll try figure it out
louislee
Newbie
*
Offline Offline

Activity: 1
Merit: 0


View Profile
January 23, 2015, 08:57:48 AM
 #35

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

Activity: 223
Merit: 132



View Profile WWW
September 25, 2015, 03:58:52 AM
 #36

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?

 Huh

elbandi
Hero Member
*****
Offline Offline

Activity: 525
Merit: 531


View Profile
September 25, 2015, 11:25:22 AM
 #37

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?

 Huh

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

and you can call any commands in the script.
Martin SK
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile WWW
December 03, 2017, 11:47:08 AM
 #38

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

Activity: 182
Merit: 100



View Profile
December 03, 2017, 08:22:57 PM
 #39

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.
Martin SK
Newbie
*
Offline Offline

Activity: 15
Merit: 0


View Profile WWW
January 15, 2018, 12:20:33 PM
 #40

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.
Pages: « 1 [2] 3 »  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!