Skip to content

Instantly share code, notes, and snippets.

@majecty
Created July 31, 2019 15:41
Show Gist options
  • Save majecty/97ad1c6e87c928547a841c7fcf95055e to your computer and use it in GitHub Desktop.
Save majecty/97ad1c6e87c928547a841c7fcf95055e to your computer and use it in GitHub Desktop.
import { SDK } from "codechain-sdk";
import { Block } from "codechain-sdk/lib/core/Block";
async function main() {
const sdk = new SDK({
server: "https://corgi-rpc.codechain.io",
networkId: "wc"
});
let currentBestBlockNumber = /* Fill this line */ 1;
while (true) {
const block: Block | null = /* Get block whose number is currentBestBlockNumber */ null;
console.log(`New block ${currentBestBlockNumber} - ${block!.hash}`);
await delay(100);
let nextBlockNumber = /* Get current best block number */ 2;
while (nextBlockNumber === currentBestBlockNumber) {
await delay(1000);
nextBlockNumber = /* Get current best block number */ 2;
}
currentBestBlockNumber = nextBlockNumber;
}
}
main().catch(console.error);
async function delay(ms: number) {
return new Promise(resolve => {
setTimeout(() => {
resolve();
}, ms);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment