import { offchainMessageContentRestrictedAsciiOf1232BytesMax, OffchainMessageV0 } from '@solana/offchain-messages';function handleSubmit() { // We know only that what the user typed conforms to the `string` type. const text: string = textInput.value; try { const offchainMessage: OffchainMessageV0 = { content: offchainMessageContentRestrictedAsciiOf1232BytesMax(text), // ... }; } catch (e) { // `text` turned out not to conform to // `OffchainMessageContentRestrictedAsciiOf1232BytesMax` }}
[!TIP]
When starting from known-good ASCII content as a string, it's more efficient to typecast it
rather than to use the offchainMessageContentRestrictedAsciiOf1232BytesMax helper,
because the helper unconditionally performs validation on its input.