isClarityType
Type guard function for narrowing a generic ClarityValue to a specific Clarity type. Useful for runtime type checking of Clarity values returned from contract calls.
Usage
import { isClarityType, ClarityType, Cl } from '@stacks/transactions';
const value: ClarityValue = Cl.uint(100);
if (isClarityType(value, ClarityType.UInt)) {
// TypeScript now knows `value` is UIntCV
console.log(value.value); // 100n
}
if (isClarityType(value, ClarityType.ResponseOk)) {
// TypeScript now knows `value` is ResponseOkCV
console.log(value.value); // inner ClarityValue
}Signature
Returns
boolean
true if the value's type matches the provided ClarityType, with TypeScript type narrowing.
Parameters
val (required)
Type:
ClarityValue
The Clarity value to check.
type (required)
Type:
ClarityType
The Clarity type to compare against.
Last updated
Was this helpful?