How do I use walletnotify?

19

8

I have bitcoin daemon and I want to use the walletnotify option with a json-rpc call. Some of the examples use a "transaction.sh" file for walletnotify. What is it for?

What do I have to write in that sh file, to make walletnotify work for more than 6 confirmations.

M.R

Posted 2014-04-10T06:14:00.660

Reputation: 471

Just put a ruby CLI command in the .sh file to run your ruby script. A .sh file is basically a command line.John T 2014-04-10T06:23:35.303

Found this thread helpful: https://bitcointalk.org/index.php?topic=203438.0

Mikko Ohtamaa 2014-04-10T06:27:53.247

Answers

28

First you must configure your bitcoin.conf file for JSON-RPC

rpcallowip=127.0.0.1
rpcuser=yourusername
rpcpassword=reallystrongpasswordthatsnothis
rpcport=7788
walletnotify=/home/scripts/transaction.sh %s

Where transaction.sh is some bash program. One approach is to have it make an http request to some process to notify you of the deposit. An example:

#!/bin/sh
curl -d "txid=$1" http://127.0.0.1/some/route

walletnotify will execute transaction.sh every time you either

  • receive bitcoin
  • send bitcoin
  • when a bitcoin gets its first confirmation

%s is the transaction ID or txid which gets passed to transaction.sh.

Loourr

Posted 2014-04-10T06:14:00.660

Reputation: 3 022

1What if I receive more than 1 transaction in a block? Does it spawn a new process/thread using the bash program for each transaction?pferg 2019-06-05T18:50:25.790

1@pferg it spaws for each transaction and for each block. the only question is: what if you receive multiple inputs from multiple outputs within 1 transaction. ist that even a thng? (i send you 10x 5 BTC within 1 transaction. i think you receive 1 OP with 50BTC)Tim Kretschmer 2019-11-06T07:03:38.313