Getting a block by height

Get the block information given a height.

Prerequisites

Let’s get into some code

What happened in the genesis block? Run the following code to get the first created block header.

const blockHttp = new BlockHttp('http://localhost:3000');

const height = 1;

blockHttp
    .getBlockByHeight(height)
    .subscribe(block => console.log(block), err => console.error(err));
const blockHttp = new BlockHttp('http://localhost:3000');

const height = 1;

blockHttp
    .getBlockByHeight(height)
    .subscribe(block => console.log(block), err => console.error(err));

The following snippet returns the height of the latest block.

const chainHttp = new ChainHttp('http://localhost:3000');

chainHttp
    .getBlockchainHeight()
    .subscribe(height => console.log(height.compact()), err => console.error(err));
const chainHttp = new ChainHttp('http://localhost:3000');

chainHttp
    .getBlockchainHeight()
    .subscribe(height => console.log(height.compact()), err => console.error(err));
nem2-cli blockchain height