Shannon Code here: During my AmA I was asked about monitoring an address so they could log incoming deposits into a database. I researched a bit, asked the core developers here on the development team and came up with a pretty elegant solution.
Continuing with the integration demonstration here: http://mastercoin.io/mastercore-integration-nodejs/ I’ll demonstrate how this can be done.
This example is of course a simplistic version, there is very little error handling and only the simplest “mvp” Minimum Viable Product has been demonstrated. I handled it this way to make things easier to follow along with.
Lets get started:
First off lets clone the example files so you can follow along:
> git clone https://github.com/genecyber/Mastercore-Node-App.git
This should get you a copy of the files needed. I (being a .Net developer) am writing this app in node, but I’m using the visual studio node tools for VS2013, I have included the project files in the event that you would like to also use Visual Studio.
You will need to install the dependencies. npm is used to install the dependencies.
Start the application
> node server.js
You can also check out my live version here: http://184.108.40.206:3000/
First things first, bitcoind has the walletnotify flag built right in, I’m illustrating how to harness this capability. I found a great resource via this post
Wallet notify works by telling bitcoind you want to execute some command locally whenever a wallet event happens. Incoming tx, confirmations, outgoing tx, etc.
This excerpt is from my bitcoin conf file and simply says run notify.sh and append any parameters. In this case it will be a transaction id.
So looking back at the node app we can visit the /notify url to monitor transactions: http://220.127.116.11:3000/notify/ You will notice an address we want to monitor. Sending any transactions to this address should now create records in our database.
Testing it out
How’d That happen?
I’ll dive into the node just a bit now to show how that works behind the scenes.
I hope this helps answer how to monitor an address using Mastercore.
Mastercoin Developer Evangelist & Head of Security