-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: Add a util to get the genesis hash for a network addrs
Signed-off-by: Shreevatsa N <vatsa@dhiway.com>
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |