Algosdk-js: A few questions

  1. Does there exist an inbuilt toString() method or something similar for Algorand Secret Keys? generateAccount() returns an object with property sk which is a UInt8Array - do I need to write the conversion code as part of my project?
  2. Are typescript type definitions present for algosdk?
  3. I see there isn’t, but is there the possibility of adding a getBlock(...) function which accepts blockHash as the parameter and returns block info? Currently it only takes a round parameter

Will update if I have more questions. Thanks!

1 - to get the secret key you can use
var account = algosdk.generateAccount();
account.sk
2 - not yet
3 - currently we only support round number

I’m curious regarding your third question. Could you please tell us more why you’d like to retrieve a block by it’s hash ? In Algorand, we generally try to use the round number as the primary key for the block. I’m wondering where the need for a block hash came from.

My use case specifically is because I’m implementing the Sidetree protocol on Algorand, which requires a non-predictable unique which is tied to a single block. Canonically, this would be the block hash. There’s also other use cases like being able to search with block hash on AlgoExplorer for example.

For the meantime, I developed a service worker which maps algorand block hashes to block numbers (rounds). You can find it here - GitHub - FlexFinTx/algorand-roundhash-mapper: A worker which stores a mapping from blockHash to blockRound for Algorand in a Mongo database

What about a transaction instead of a block ? Can you create a transaction instead ( where you could also store some arbitrary data in the notes field ) ?

With the indexer enabled, transactions are searchable across the entire blockchain, and you could always find which block contains that particular transaction.

1 Like

I believe the solution you suggested would also probably work, but I am not running indexer nodes right now. Maybe I will come back to this later and switch it out.