Do smart contracts on NEAR have events or do I need to poll the chain to get data?

Viewed 199

Do smart contracts have events now that I can set up listeners for or do I need to poll the chain manually to get data about them?

1 Answers

There are no events right now on NEAR but you could do the following https://github.com/near-examples/erc-20-token/blob/master/contract/events.ts and in Rust https://github.com/near/docs/issues/362

Instead of native events we have a way to poll for changes in the contract's state. For example the events above for fungible tokens are implemented by using that.

Polling for events can be done via RPC https://docs.near.org/docs/api/rpc-experimental#example-of-data-changes and also we are finishing the indexing infrastructure so can later just run indexing node that will provide all this events (https://github.com/nearprotocol/nearcore/pull/2651)

Related