1

Coming from an ethereum web3 background, I'm accustomed to listening for a contract's events to figure out when things happen in my contract and react accordingly in the application.

I'm looking for ways to do something similar with a tezos node and smart contract. Since there currently isn't any equivalent of emitting events on tezos, I was hoping there would be some way to get a list of operations for my contract KT1 address -- but that doesn't seem possible looking at the tezos-node RPC and taquito docs.

I've seen some tools like tzindex which seem like overkill for the problem I'm trying to solve. Looks like it can handle a contract's operations but it stores them historically and for all contracts on the chain.

The only thing that seems reasonable to me is to roll my own 'operation listener' to hear each block, and process/handle any operation if it involves my contract's address.

Is it possible to do this or something similar with a library like taquito? Is there another tool, option, or strategy that I'm missing?

2
  • Not sure why you got downvoted since it's a perfectly valid question. Feb 4, 2021 at 17:03
  • I couldn't find any duplicates. Oh well, hope it helps others :) Things are looking good for taquito
    – jon
    Feb 4, 2021 at 17:18

2 Answers 2

4

After working with @taquito/rpc for a little while and having success there I also discovered in the main @taquito/taquito package there's some useful things you can subscribe to on the stream. A simple example to listen for new block hashes:

const tezos = new TezosToolkit("http://localhost:8732");
const blockSub = tezos.stream.subscribe("head");
blockSub.on("data", data => {
    console.log(data);
});

There's also something for listening to filtered operations, eg. at a contract's address:

tezos.stream.subscribeOperation({destination: 'KT1...'});
2

First, note that there is work in progress to implement on-chain events for Tezos: TZIP and MR.

At the moment however, I don't think you have a choice other than using an indexer. In addition to tzindex that you mentioned, there is also Nomadic Labs Tezos indexer.

2
  • Thank you, I look forward to on-chain events in the future. For the time being, I need something and I find the indexer solutions to be too heavy. I'm having excellent success so far with rolling my own node listener approach using @taquito/rpc npm package (thanks to the authors). Going with that for now
    – jon
    Feb 4, 2021 at 17:17
  • Sounds good! Don't hesitate to document your approach by answering this question yourself. Even just a phrase and a link to the relevant taquito documentation would be helpful :)
    – arvidj
    Feb 4, 2021 at 19:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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