getOffchainMessageDecoder

function getOffchainMessageDecoder(): VariableSizeDecoder<OffchainMessage>;

Returns a decoder that you can use to convert a byte array (eg. one that conforms to the OffchainMessageBytes type) to an OffchainMessage object.

Returns

VariableSizeDecoder<OffchainMessage>

Example

import { getOffchainMessageDecoder } from '@solana/offchain-messages';
 
const offchainMessageDecoder = getOffchainMessageDecoder();
const offchainMessage = offchainMessageDecoder.decode(
    offchainMessageEnvelope.content,
);
console.log(`Decoded an offchain message (version: ${offchainMessage.version}`);

Remarks

If the offchain message version is known ahead of time, use one of the decoders specific to that version so as not to bundle more code than you need.

On this page