Learn why decentralized messaging matters, see how the @mysten/messaging SDK works in code, and build your first message flow.
Traditional messaging platforms like WhatsApp and Discord rely on centralized servers. A single company controls your data and can censor or ban you. If they shut down, your message history vanishes. On-chain messaging eliminates this by storing messages as blockchain objects that you own. Let's see what this looks like architecturally.
Sui messaging uses three layers working together. The Sui blockchain stores channel metadata and message references as objects. The Seal protocol encrypts messages so only channel members can read them. Walrus (Sui's decentralized storage) holds the actual encrypted message blobs. Only a tiny blob ID is stored on-chain, keeping gas costs low. Here's how a message flows through all three layers:
Each layer has a specific role: Sui handles ownership and access control, Seal handles privacy, and Walrus handles storage. The @mysten/messaging SDK ties them all together through a single MessagingClient. When you call sendMessage(), the SDK automatically encrypts with Seal, stores on Walrus, and records the reference on Sui. Match each component to its role:
A channel is a Sui object that represents a conversation. It stores member addresses, an encryption policy, and metadata. Channels can be direct messages (2 members) or group chats (many members). The channel object controls who can send, read, and decrypt messages. Let's see how to create one:
Sending a message is a three-step process that the SDK handles for you: encrypt the content with Seal, store the encrypted blob on Walrus, and record the blob reference on-chain. The sendMessage method takes a channel ID and your plaintext content, then performs all three steps atomically. Here's the complete flow:
Reading messages reverses the flow: fetch blob references from Sui, retrieve encrypted blobs from Walrus, and decrypt with Seal. Again, the SDK handles this. getMessages returns decrypted plaintext for all messages you're authorized to read. If you're not a member of the channel, decryption will fail — this is the Seal guarantee.
The messaging SDK has four packages: @mysten/messaging (the main client), @mysten/sui (blockchain interactions), @mysten/seal (encryption), and @mysten/walrus (storage). You install all four, then create each client and combine them into a MessagingClient. Let's walk through the complete setup:
Each client has a specific responsibility. SuiClient reads blockchain state and submits transactions. SealClient manages threshold encryption keys — it splits the encryption key across multiple servers so no single server can decrypt alone. WalrusClient stores and retrieves encrypted data blobs using erasure coding for durability. MessagingClient ties them together. Match each client to what it does: