Created
July 31, 2019 15:41
-
-
Save majecty/97ad1c6e87c928547a841c7fcf95055e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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