Skip to main content

index/functions/tryParseTokenClassKey.md

tryParseTokenClassKey(value): GalaChainTokenClassKey | undefined

The non-throwing parseTokenClassKey: the class key, or undefined when value is not one. A string is split exactly as parseTokenClassKey splits it (| form when it contains a |, else $, from the right, all four parts non-empty). Unlike parseTokenClassKey, an object is VALIDATED, not just copied: all four fields must be non-empty strings. Anything else (undefined, null, a number, an array) is undefined, so it is safe on untrusted input (a stored token, a URL parameter, a wallet row) without a try/catch.

Use tryParseCompositeKey instead when only the $ form is valid input.

Parameters​

ParameterType
valueunknown

Returns​

GalaChainTokenClassKey | undefined

Example​

const key = tryParseTokenClassKey(row.compositeKey);
if (key === undefined) return failClosed(); // no class is known: never invent one from a symbol