isHash
Checks if a string is a valid 32-byte hash
Loading...
Checks if a string is a valid 32-byte hash
Checks if a string is a valid 32-byte hash (64 hex characters with 0x prefix).
import "github.com/ChefBingbong/viem-go/utils/hash"import "github.com/ChefBingbong/viem-go/utils/hash"
// Valid hashvalid := hash.IsHash("0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad")// true
// Invalid (too short)invalid := hash.IsHash("0x1234")// false
// Invalid (no prefix)invalid = hash.IsHash("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad")// falsebooltrue if the string is a valid 32-byte hash, false otherwise.
stringThe string to validate. Must be exactly 66 characters (0x + 64 hex characters).
valid := hash.IsHash("0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad")// true
invalid := hash.IsHash("0x1234")// false0x prefix0-9, a-f, A-F)