Monitoring a BCH address with Tasker
"You can use this to check if somebody tipped into your account!"
Introduction
Sometimes we need to put our knowledge to work in order to consolidate it, at least it is my case, during my daytime, I don't like to be constantly checking the phone and bought a Smart Band from Xiaomi.
As the few features on the device are pretty limited I got a copy of the Tasker app a friend of mine recommended and then the fun began.
Prior work
Do you know how much energy consumes a phone with Bluetooth activated? I won't get too specific on details and I'll summarize it with: "enough to kill your battery before lunch".
Do you know how many days is the smart band's battery supposed to last and how much it lasts if the user has always Bluetooth ON? "Not enough to compensate it's price/quality ratio".
One of my first hacks with tasker was activating the Bluetooth only one minute each half an hour between 08:00 AM and 09:00 PM both user experience and battery usage improved (reduced spam notifications and made battery footprint for both the smartphone and the smart band unnoticeable).
The idea
After being invited to a congress where they'll be speaking about blockchain as a solution for my organization, I wanted to be able to speak and debate properly about it then I decided to update my knowledge about blockchain.
After spending some weeks studying about cryptocurrency and blockchain technologies, I found great ideas and websites like this and fell in love with them, they are a great idea that shows how blockchain is much more than virtual and highly volatile assets. Thanks to that my motivation boosted.
Then, the idea just came out yesterday speaking with a friend: "I could automate checking an address balance and notifying changes in order to, for example, get a notification if somebody tips my account" and this morning woke up and thought: "why not?".
The concept
Look, block explorers like Blockchair have a REST API so everything you can look into that web page is also able to be queried by a REST Client (any HTTP browser or network-enabled device can issue a request!) to get a JSON.
A Blockchair JSON looks like this (ugly huh?) but is extremely useful to computer programs as you can parse it and extract any information already available on the human-readable website.
In this case, I will use BCH addresses and with the JSON used to represent BCH addresses on Blockchair, we can get two useful values for our application: BCH amount in satoshis and USD conversion of that amount. Then I can implement the algorithm shown on the diagram leading this section with two kinds of notifications:
Your balance has changed
The value of your assets changed (significantly)
The implementation
Tasker makes implementing automation on your smartphone pretty straightforward with a GUI that does most of the typing job for you, but once in a while, you'll have to deal with declarative code like Javascript. Anyway, I'll share the ¿snippet? with you, each line is a step option you can choose on the Tasker menu:
HTTP Request (Method:
GET
, URL:https://api.blockchair.com/bitcoin-cash/dashboards/address/{your address here]
Variable Set (Name:
%JSON
To:%http_data
)JavaScriptlet (code:
var balance = JSON.parse(global('%JSON')).data.{your addres here}.address.balance;setGlobal( "%BALANCE",balance );
)JavaScriptlet (code:
var usd = JSON.parse(global('%JSON')).data.{your address here}.address.balance_usd;
setGlobal( "%BALANCE_USD", Math.round(usd*100)/100 );
)If (Condition:
%BALANCE neq %LAST_BALANCE
)Variable Set (Name:
%USD_DIF
To:%BALANCE_USD - %USD
Do Maths:Checked
)Variable Set (Name:
%LAST_BALANCE
To:%BALANCE
)Variable Set (Name:
%USD
To:%BALANCE_USD
)Notification: Check down
Else If (Condition:
%USD neq %BALANCE_USD
)Variable Set (Name:
%USD_DIF
To:%BALANCE_USD - %USD
Do Maths:Checked
)Variable Set (Name:
%USD
To:%BALANCE_USD
)Notification: Check down
Set a profile to run this task every 30 minutes (or any other time configuration you might consider).
About the notification, I left it open because I use Mi Band Tools and explaining how it works could lead to another full post, but you can use the native Notification tool from tasker, where you can even set a permanent push notification in your phone that lets you check the address balance just by looking at your notification bay.
How does it look in action?
Well, it's not the prettiest thing and needs more polishing, but not bad being aware that it just took me 20 minutes to set up.
Also, I'll try to make the message shorter and aware of the 8 characters per line limitation from the smart band so it looks prettier.
Translation:
Your BCH balance changed to 0.57 $
Final thoughts
I know this is something that might not be useful having many widgets that do the same and very much easier, anyway I believe this solution, at least, is cheaper on energy cost and safety.
Anyway, I had fun doing it and I am already thinking about much more features and improvements I'll sure post them here if I can get some time to.
Thank you for reading!
nice article ....loved it ...lets subscribe each other