function offchainMessageContentUtf8Of65535BytesMax<TText>( text,): OffchainMessageContentUtf8Of65535BytesMax<TText>;
Combines asserting that the content of a v0 offchain message is UTF-8 of up to 65535 characters
with coercing it to the OffchainMessageContentUtf8Of65535BytesMax type. It's most useful
with untrusted input.
import { OffchainMessageContentUtf8Of65535BytesMax, 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: OffchainMessageContentUtf8Of65535BytesMax(text), // ... }; } catch (e) { // `text` turned out not to conform to // `OffchainMessageContentUtf8Of65535BytesMax` }}
[!TIP]
When starting from known-good UTF-8 content as a string up to 65535 bytes, it's more efficient
to typecast it rather than to use the OffchainMessageContentUtf8Of65535BytesMax helper,
because the helper unconditionally performs validation on its input.