In this example, we start a subscription and get a result whenever a new block is generated.
subscription { blocks { id }}
The filter and result parameters are the same as in the query method. The filter parameter narrows the action down to a subset of monitored items. In this case, the filter is empty: all items are included into monitoring.
const {TonClient} =require('@eversdk/core');const {libNode} =require('@eversdk/lib-node');TonClient.useBinaryLibrary(libNode)constclient=newTonClient({ network: { endpoints: [process.env.endpoint ], queries_protocol:'WS' },});functionresponseHandler(data, responseType) {// Tip: Always wrap the logic inside responseHandler in a try-catch block// or you will be surprised by non-informative errors due to the context// in which the handler is executedtry {if (responseType ===100/* GraphQL data received */) {if (data?.result?.blocks) {console.log(data.result.blocks); } } else {// See full list of error codes here:// https://docs.everos.dev/ever-sdk/reference/types-and-methods/mod_net#neterrorcodeconsole.error(data, responseType); } } catch (err) {console.log(err); }}(async () => {try {constsubscription=/* language=graphql */`subscription($wc: Int!) { blocks(filter: { workchain_id: { eq: $wc } }) { seq_no id } }`awaitclient.net.subscribe({ subscription, variables: {wc:-1}, }, responseHandler)console.log('The last masterchain blocks')console.log('Press CTRL+C to interrupt it') } catch (error) {if (error.code ===504) {console.error('Network is inaccessible'); } else {console.error(error); }process.exit(1); } })();