Here is a nice blog from Shannon about his work on Mastercoin integration:
http://blog.mastercoin.org/2014/08/26/integration-with-mastercore-volume-2/"INTEGRATION WITH MASTERCORE VOLUME 2
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.gitThis 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.
If using Visual Studio
1
If using bash
2
Modify your copy of config.js to reflect the information needed to connect to your Mastercore instance.
3
Start the application
> node server.js
or if in Visual Studio click the play button
4
You should now be able to access the application via your web-browser.
5
You can also check out my live version here:
http://162.242.208.46:3000/ Diving In
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.
~/.bitcoin/bitcoin.conf
walletnotify=~/.bitcoin/notify.sh %s
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.
My Notify.sh simply runs curl on my notify endpoint to persist the transaction
6
So looking back at the node app we can visit the /notify url to monitor transactions:
http://162.242.208.46: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
Nothing in the database:
7
Make a deposit
8
Now we have a transaction id stored in our database!
9
How’d That happen?
I’ll dive into the node just a bit now to show how that works behind the scenes.
Here we now include the sqlite3 library
10
Here are our routes for handling the /notify view and the /notify/:txid/ endpoint
11
I hope this helps answer how to monitor an address using Mastercore.
Shannon Code
Mastercoin Developer Evangelist & Head of Security"