Skip to content

Commit

Permalink
utils: Add a util to get the genesis hash for a network addrs
Browse files Browse the repository at this point in the history
Signed-off-by: Shreevatsa N <vatsa@dhiway.com>
  • Loading branch information
vatsa287 committed Jun 25, 2024
1 parent 0c6a18e commit 208ce34
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/utils/src/genesis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { connect, disconnect } from '@cord.network/config'
import { SDKErrors } from '.'

/**
* Connects to chain and returnns the genesis hash in hexadecimal format for a given networkAddress.
*
* @param networkAddress Network Address for which the genesis hash is required.
* @returns Returns the genesis hash in Hexadecimal format.
*/
export async function getGenesisHash(
networkAddress: string,
): Promise<string> {
try {
const connectData = await connect(networkAddress as string);
const genesisHash = connectData.genesisHash.toHex();

return genesisHash;
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : JSON.stringify(error)

throw new SDKErrors.CordQueryError(
`Error querying asset entry: ${errorMessage}`
)
} finally {
disconnect();
}
}

0 comments on commit 208ce34

Please sign in to comment.