Get the block information given a height.
What happened in the genesis block? Run the following code to get the first block header recorded on the blockchain.
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const blockHttp = repositoryFactory.createBlockRepository();
const height = 1;
blockHttp
.getBlockByHeight(UInt64.fromUint(height))
.subscribe((block) => console.log(block), (err) => console.error(err));
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const blockHttp = repositoryFactory.createBlockRepository();
const height = 1;
blockHttp
.getBlockByHeight(symbol_sdk_1.UInt64.fromUint(height))
.subscribe((block) => console.log(block), (err) => console.error(err));
// replace with node endpoint
try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
"http://api-01.us-east-1.096x.symboldev.network:3000")) {
final BlockRepository blockRepository = repositoryFactory.createBlockRepository();
// Replace with block height
final BigInteger blockHeight = BigInteger.valueOf(1);
final BlockInfo blockInfo = blockRepository.getBlockByHeight(blockHeight).toFuture()
.get();
final JsonHelper helper = new JsonHelperJackson2();
System.out.println(helper.prettyPrint(blockInfo));
}
The following snippet returns the height of the latest block.
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const chainHttp = repositoryFactory.createChainRepository();
chainHttp
.getBlockchainHeight()
.subscribe((height) => console.log(height.compact()), (err) => console.error(err));
// replace with node endpoint
const nodeUrl = 'http://api-01.us-east-1.096x.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const chainHttp = repositoryFactory.createChainRepository();
chainHttp
.getBlockchainHeight()
.subscribe((height) => console.log(height.compact()), (err) => console.error(err));
Get the block header:
symbol-cli block header --height 1
Get the height of the blockchain:
symbol-cli chain height
Did you find what you were looking for? Give us your feedback.