6

I need to make a backend server that reacts to events in my smart contract, such as token transfers, action calling, etc

I know that there are DBs plugins (such as SQLite and MongoDb) but I need to build one to just store actions and transfers related to a specific Smart Contract, instead of storing everything.

How can that be achieved? I didn't find any documentation related to that on Github nor EOSIO Official documentation

2

Demux may help you! it's a kind of javascript module.

you can watch specific contracts and actions, and handle this in light weight.

see repository https://github.com/eosio/demux-js

and see this example https://github.com/EOSIO/demux-js/tree/develop/examples/eos-transfers

have a good day :)

  • 1
    turns out I demux was the solution to my problem, I'm actually using it with rabbitmq, but forgot to update the question. Thanks anyway! Hope this helps out others! – lucca65 Nov 22 '18 at 15:32
2

In the main repository there is a plugin called history_plugin which can serve as a good example and it includes a simple configurable filter for what it retains. A similar mechanism could be created to filter based on almost anything and its skeleton is a good resource for traversing the data structures you have access to as a plugin.

see https://github.com/EOSIO/eos/blob/master/plugins/history_plugin/history_plugin.cpp

  • It there any way to register such a custom plugin on mainnet? Otherwise this seems quite useless for developing a real EOS dapp. This question is also related to: eosio.stackexchange.com/questions/418/… and eosio.stackexchange.com/questions/25/… – Aaron Voelker May 27 '18 at 20:52
  • 1
    You wouldn't need to add it to mainnet per say. If you ran a full node connected to the mainnet, you could install the plugin and it would have all the information it needs. – Bart Wyatt May 28 '18 at 16:45
  • Would everyone using your dapp need to go through your node? Or would the plugin independently process every transaction that it's interested in simply by being connected to the mainnet? If your own node experiences downtime, would it automatically go through everything it missed after being reconnected? – Aaron Voelker May 28 '18 at 20:21
  • 1
    If your dApp depended on information that only your node (and its plugin) collect and offer over RPC then yes but only if it creates some sort of dependency like that. You could, of course, deploy N nodes with your plugin that would essentially all be read replicas of that data. – Bart Wyatt May 28 '18 at 21:43
  • 1
    > If your own node experiences downtime, would it automatically go through everything it missed after being reconnected? Yes, it should as it syncs to the network. All of the plugin lifecycle hooks will be emitted so you can sync too – Bart Wyatt May 28 '18 at 21:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.