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.

2

2 Answers 2

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.

2
  • 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
    Commented Jun 5, 2019 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) Commented Nov 6, 2019 at 7: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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.