diff --git a/packages/app-js/src/snippets/newHead.ts b/packages/app-js/src/snippets/newHead.ts index 76f608255f..01df5da501 100644 --- a/packages/app-js/src/snippets/newHead.ts +++ b/packages/app-js/src/snippets/newHead.ts @@ -2,7 +2,13 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -export default `// subscribe to new headers, printing the full result -api.rpc.chain.subscribeNewHead((header) => { +export default `// subscribe to new headers, printing the full info for 5 +let count = 0; +const unsub = await api.rpc.chain.subscribeNewHead((header) => { console.log(\`#\${header.blockNumber}:\`, header); + + if (++count === 5) { + console.log('5 headers retrieved, unsubscribing'); + unsub(); + } });`;