Getting block by height

Get the block information given a height.

Prerequisites

Let’s get into some code

Are you curious to see what happened in the genesis block?

const blockchainHttp = new BlockchainHttp('http://localhost:3000');

const height = 1;

blockchainHttp
    .getBlockByHeight(height)
    .subscribe(block => console.log(block), err => console.error(err));
        final BlockchainHttp blockchainHttp = new BlockchainHttp("http://localhost:3000");

        // Replace with block height
        final BigInteger blockHeight = BigInteger.valueOf(1);

        final BlockInfo blockInfo = blockchainHttp.getBlockByHeight(blockHeight).toFuture().get();

        System.out.print(blockInfo);
const blockchainHttp = new BlockchainHttp('http://localhost:3000');

const height = 1;

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

The following snippet returns the height of the latest block.

const blockchainHttp = new BlockchainHttp('http://localhost:3000');

blockchainHttp
    .getBlockchainHeight()
    .subscribe(height => console.log(height.compact()), err => console.error(err));
        final BlockchainHttp blockchainHttp = new BlockchainHttp("http://localhost:3000");

        final BigInteger blockchainHeight = blockchainHttp.getBlockchainHeight().toFuture().get();

        System.out.print(blockchainHeight);
const blockchainHttp = new BlockchainHttp('http://localhost:3000');

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