I know that I can use eosjs to read/query multi_index table data from the chain. However, my goal is to listen to/on these changes. Specifically, I want to receive a notification whenever something happens on-chain.

Therefore, I need a persistent connection to the chain, whether using web sockets, mqtt (pub-sub) or any other real-time protocol. How to do this? does the eosjs library support this?

Of course, I can write a while(true) loop, where I send RPC requests all the time to check if something has changed, but this is not a good solution, so I'm interested if other people already solved this issue.

Also, some websites like https://eosauthority.com/ show real-time data of what is happening on the eosio network. So, how do they do this?


dfuse.eosnation.io provides websocket and graphql push services which should accomplish what you are trying to do. See docs.dfuse.eosnation.io for details.

  • But dfuse.eosnation.io is an external service provider and I need to get an api key to use their services. Why can't I do this alone? or rather how do they do this? that's what I'm interested in
    – basilisk
    Nov 9 at 15:15

you would use the state history plugin which is a web socket of on chain events.

This is commonly referred to as a SHiP node (state history nodeos instance).


block one developed demux-js as well, but should still work https://github.com/EOSIO/demux-js

You can see other history tools here https://developers.eos.io/welcome/latest/tools/history-tools/history-tools

If you want an example of storing certain information in a PostgreSQL database, you can see the atomic assets api: https://github.com/pinknetworkx/eosio-contract-api

Here is an example script to run a SHiP node exposing the web socket on 8887.


if [ ! -d $DATADIR ]; then
  mkdir -p $DATADIR;

nodeos \
--plugin eosio::producer_plugin \
--plugin eosio::chain_plugin \
--plugin eosio::chain_api_plugin \
--plugin eosio::http_plugin \
--plugin eosio::net_plugin \
--plugin eosio::state_history_plugin \
--data-dir $DATADIR"/data" \
--blocks-dir $DATADIR"/blocks" \
--config-dir $DATADIR"/config" \
--producer-name eosio \
--http-server-address \
--state-history-endpoint \
--access-control-allow-origin='*' \
--contracts-console \
--trace-history \
--chain-state-history \
--http-validate-host=false \
--p2p-peer-address $P2P_ADDRESS \
--verbose-http-errors \
--enable-stale-production \
--eos-vm-oc-enable \
--wasm-runtime eos-vm-jit \
--disable-replay-opts \
--genesis-json $DATADIR"/genesis.json" \
>> $DATADIR"/nodeos.log" 2>&1 & \
echo $! > $DATADIR"/eosd.pid"

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.