Validation functions

Taquito provides functions that allow us to see if an address, a chain, a key hash, a contract address, a public key or a signature is valid. Note that these validations do not rely on a node but are done based on checksums. Thus, they allow us to check if a value is valid and not if it exists on a chain. The ValidationResult returned by these functions is an enum which can take the following values:

0 = NO_PREFIX_MATCHED,
1 = INVALID_CHECKSUM,
2 = INVALID_LENGTH,
3 = VALID

Validate an address

The validateAddress function

This function can be used to validate implicit addresses (tz1, tz2, tz3) as well as originated addresses (KT1).

In the following example, the function is first called with a valid public key hash (pkh). Then, it is called with the same pkh where one character differs (e.g. 'p' instead of 'P'), which results in an invalid checksum.

Live Editor
Result

The validateKeyHash function

This function is used to validate implicit addresses (tz1, tz2, tz3).

Here is a valid example with a pkh and an invalid one where the prefix is missing :

Live Editor
Result

The validateContractAddress function

This function is used to validate originated addresses (KT1).

Here is a valid example with the address of an existing contract :

Live Editor
Result

Validate a chain

The validateChain function is used to validate a chain id.

The following example shows a valid result when using the mainnet chain id and an invalid result if the prefix is missing :

Live Editor
Result

Validate a public key

The validatePublicKey is used to check if a public key is valid.

Live Editor
Result

Validate a signature

The validateSignature function is used to check if a signature is valid.

Live Editor
Result