With bitcoin-core, you get a configuration option called walletnotify
which allow you to invoke a command whenever you receive a payment, first confirmation of a payment or send a payment.
You can specify %s
as an argument which will be used to parse the transaction id.
Bitcoind WalletNotify TransactionID Example
To see what walletnotify does, in my bitcoin.conf
I had a basic script to write a entry every time I receive a payment:
1 2 3 |
|
And in my /bin/notify.sh
script I have this:
1 2 3 4 5 |
|
I have executable permissions for the script:
1
|
|
When a payment was made, my logfile showed the following:
1
|
|
Capturing the wallet name in walletnotify
In bitcoin-core we wave wallets, and in a wallet we have one or more bitcoin addresses, as can be seen below for wallets:
1 2 |
|
and to get the addresses for that wallet:
1 2 |
|
I had to figure out how to capture the wallet name as well as the transaction id, as I thought its not possible until I stumbled upon a post which mentioned from bitcoind 0.20:
The -walletnotify configuration parameter will now replace any %w in its argument with the name of the wallet generating the notification.
Which was merged by this PR: - https://github.com/bitcoin/bitcoin/pull/13339
So first to verify that bitcoind is newer than mentioned:
1 2 |
|
Updated the walletnotify
config in bitcoin.conf
to include %w
:
1 2 |
|
Then in the notify.sh
script:
1 2 3 4 5 |
|
And then restart bitcoind:
1
|
|
When a transaction occurred, I could see the transaction id with the corresponding wallet name:
1 2 |
|
Thanks
Thanks for reading, if you like my content, check out my website or follow me at @ruanbekker on Twitter.