Skip to content

Instantly share code, notes, and snippets.

@daoka
Created July 15, 2020 15:23
Show Gist options
  • Save daoka/096fa3f6484eefb22a3de6ffc024fed6 to your computer and use it in GitHub Desktop.
Save daoka/096fa3f6484eefb22a3de6ffc024fed6 to your computer and use it in GitHub Desktop.
new block listener for 0.9.6
import { NetworkType, RepositoryFactoryHttp } from 'symbol-sdk';
const apiEndpoint = 'https://sym-test963.opening-line.jp:3001';
const wsEndpoint = `${apiEndpoint.replace('http', 'ws')}/ws`
const networkType = NetworkType.TEST_NET;
const generationHash = '1DFB2FAA9E7F054168B0C5FCB84F4DEB62CC2B4D317D861F3168D161F54EA78B';
const repositoryFactory = new RepositoryFactoryHttp(apiEndpoint, {
networkType: networkType,
generationHash: generationHash,
websocketUrl: wsEndpoint,
});
const listener = repositoryFactory.createListener();
listener.open().then(() => {
listener.newBlock().subscribe(
(x) => {
console.log(`---- new block: ${x.height} ----`)
console.log(x);
}, (err) => {
console.error(err);
}
)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment