Account Balance by polling or subscription?

Hi guys, I want to know if there is any method of listening to an account’s balance changes without polling ? In Ethereum for example you can install a block filter and scan changes every X blocks.

What kind of monitoring possibilities are in the Aepp SDK and/or Node API?

My purpose is to mantain an Aepp screen -developed in Vue.js- updated with the proper balance to check.

Thanks.

2 Likes

Hi there,

The æternity middleware may be able to help you with some of this. Unfortunately the middleware does not have any insight into the effects of contract calls on balances, so these are invisible to us.

However, the middleware does have a websocket interface which can be used to subscribe to events which relate to any æternity object. It’s described in the the manual, which you can find here. An example here:


[email protected]:~/Documents.old$ wscat -c ws://mdw.aepps.com:3022
connected (press CTRL+C to quit)
< connected
> {"op":"subscribe", "payload":"object", "target":"ak_nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv"}
< ["ak_nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv"]
> {"op":"subscribe", "payload":"object", "target":"ak_dArxCkAsk1mZB1L9CX3cdz1GDN4hN84L3Q8dMLHN4v8cU85TF"}
< ["ak_nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv","ak_dArxCkAsk1mZB1L9CX3cdz1GDN4hN84L3Q8dMLHN4v8cU85TF"]
< {"payload":{"beneficiary":"ak_nv5B93FPzRHrGNmMdTDfGdd5xGZvep3MVSpJqzcQmMp59bBCv","hash":"kh_2J6EPJxbg5iucZFMhfxPC9XEqri5un4HjLDy3EVj1nYbYe8j1B","height":114278,"info":"cb_AAAAAfy4hFE=","miner":"ak_2fkhBuZtFYhoFNxUck5TLZTDasKfz6RZ35gAvH4Bjrj9ZV5G6N","nonce":497952684640195701,"pow":[4091881,27332183,34728572,69171196,106642898,112171053,119878084,126311193,132323353,136906045,137471331,146462687,164235915,165041328,167773940,170578955,183872553,184976208,203131751,220483204,235116751,253492053,255830105,257216090,276345665,293030928,318027436,327252122,356944764,369955472,399748061,404573144,443659112,450379714,467982209,476222342,487010622,501904398,510090059,512973749,518739484,528025200],"prev_hash":"mh_kiZ8YTpKJ69WUp2LRKLAhomPBY4UDo97ommyHAYTMrsk8L9wh","prev_key_hash":"kh_UmmdsnhcRnKB8hs8sMLCjVCCuJbMBL7sk37Uut26UvtMYJYSw","state_hash":"bs_K639BSbjxZomubDJ1pFr5dh5YwxyR9rCHLNqeaDXEiChgfDqf","target":504338701,"time":1563973602427,"version":3},"subscription":"object"}
< {"payload":{"block_hash":"mh_2FFY8UAV2RyiTM6QqQVUkGpt1xnNCmM2FgHYTDgV46EciYpt8m","block_height":114278,"hash":"th_2pBdvXR4jzTgEdKogS2jPMAtBE2355beyrP3EVVXDCy55A6YWS","signatures":["sg_RjPoF3UWNz8rts1wCgj8AnuYCDunpzLvxecNeiik4fAX1HstYgUQTSEJ6PYbeLKLwP9D5SNGN1Zi9papguVXf2wcoMpGb"],"tx":{"amount":10036022990000000000,"fee":130000000000000,"nonce":24394,"payload":"ba_Xfbg4g==","recipient_id":"ak_2ECRbYccpvYkPBNsXycpX56cq4kuACgoaA5HeihSdo1Kiv1AuQ","sender_id":"ak_dArxCkAsk1mZB1L9CX3cdz1GDN4hN84L3Q8dMLHN4v8cU85TF","ttl":114578,"type":"SpendTx","version":1}},"subscription":"object"}

Here we subscribe to two objects, one the beneficiary account for a miner, the other the sender of a batch of SpendTx which I randomly selected. In this example I connect to the alpha version of the middleware (mdw.aepps.com:8002, or https://alpha.mdw.aepps.com/) which currently has the better websocket implementation. A release in the next day or so will correct this.

Hope this helps,

John

2 Likes

Quick update: all middlewares now updated, the mainnet middleware is on mdw.aepps.com:3020 and the testnet one on mdw.aepps.com:3021.

We love feature requests, so if there’s anything else we can do, please let us know.