22

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.

Loourr
  • 3,050
  • 4
  • 17
  • 35
M.R
  • 501
  • 1
  • 4
  • 11

2 Answers2

33

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
  • 3,050
  • 4
  • 17
  • 35
  • 1
    What 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 Jun 05 '19 at 18:50
  • 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 Nov 06 '19 at 07:03
0

to complement Loourr's answer, %w can also be passed to your script, informing you of the wallet in the node that received the funds, since you may have > 1 wallet

ekkis
  • 177
  • 10