Hi, I’m trying to use the v2 API of the Algorand indexer. I found the response of the /blocks/{round}
API has a previous-block-hash
field, but doesn’t have something like current-block-hash
. So how to get the block hash of a specific round?
This is available in the certificate of the block that you can get by querying the block as msgpack (?format=msgpack
).
In JS:
const algosdk = require("algosdk");
const base32 = require("hi-base32");
const c = new algosdk.Algodv2("", "https://testnet.algoexplorerapi.io", "");
(async () => {
const blk = await c.block(13819291).do();
const blk_hash = base32.encode(blk["cert"]["prop"]["dig"]);
console.log(blk_hash);
})();
Other SDKs work similarly, the client methods are: GetBlock
for Java, block_raw
for Python, BlockRaw
for Go.
I use an Indexer client and there is no option of querying the block as msgpack, is there a way to compute the block hash instead of making a request to v2 client?
It may not be completely satisfying but you can ask the next block on the indexer /v2/blocks
endpoint and it contains the hash of the previous block.