Development of a Decentralized Chat on Blockchain
We develop decentralized chats where blockchain is used for identity, key management, payment channels, and proof of existence, while messages are transmitted via cryptographically protected P2P transport. Storing each message on-chain on Ethereum mainnet costs $2 to $10 — it's an expensive public registry not suitable for everyday chat. Instead, we design a hybrid system that uses blockchain exactly where it provides advantages: authentication, token-gating, micro-payments. For example, checking NFT ownership when joining a chat is done in one RPC call (cost <$0.001), and registering a user via a wallet takes a second. This approach saves up to 90% of gas fees compared to full on-chain storage. A typical client problem: ensuring conversation confidentiality while maintaining history immutability for auditing. We solve it with a combination of E2E encryption (X3DH, as in Signal) and decentralized key storage on the blockchain. Evaluate your project — write to us.
How XMTP Provides E2E Encryption?
XMTP (Extensible Message Transport Protocol) uses the X3DH (Extended Triple Diffie-Hellman) protocol to establish a shared secret between sender and receiver. Each message is encrypted on the client and decrypted only by the recipient. Group chats use MLS (Messaging Layer Security, RFC 9420) with forward secrecy and post-compromise security. Signal Protocol uses a similar scheme, but XMTP adapts it for Ethereum addresses. As a result, even the XMTP node operator cannot read message content — only metadata (from whom, to whom, when).
Solution Space: From On-Chain to Hybrid
Fully On-Chain: Only for Specific Cases
Storing messages on-chain makes sense in very narrow scenarios:
- Governance proposals and discussions (Snapshot, Tally) — immutability is important
- Dispute resolution in arbitration protocols — evidence must be tamper-proof
- Critical announcements for DAOs — provable publicity
For these cases we use Ethereum events (event MessagePosted(address indexed sender, bytes32 indexed channelId, string content)). Calldata for storing text is cheaper than storage: on Ethereum mainnet 1KB calldata ≈ 16000 gas ≈ $0.5-2. On Arbitrum or Base — 10-50 times cheaper.
P2P with On-Chain Identity: XMTP
XMTP is a production-ready protocol for Web3 messages, the de facto standard for decentralized chat. It is used in Coinbase Wallet, Converse, and many dApps. XMTP architecture:
- Identity is based on Ethereum address. No separate account needed.
- Messages are encrypted end-to-end via X3DH.
- Transport is a decentralized P2P network of XMTP nodes.
- On-chain: only key information at first user registration.
import { Client } from '@xmtp/xmtp-js';
import { ethers } from 'ethers';
const signer = await provider.getSigner();
const xmtp = await Client.create(signer, { env: 'production' });
const conversation = await xmtp.conversations.newConversation(
'0xRecipientAddress'
);
await conversation.send('Hello from dApp!');
for await (const message of await conversation.streamMessages()) {
console.log(`${message.senderAddress}: ${message.content}`);
}
XMTP supports structured content types: transaction notifications, NFT attachments, read receipts. This is especially important in a DeFi context: "Sent you 100 USDC" with an embedded transaction preview.
Group Chats: XMTP MLS
XMTP v3 added groups based on MLS — a cryptographic protocol for group encryption with forward secrecy and post-compromise security. A group is a set of participants, each with their own keys; removal from a group prevents reading future messages.
import { Client } from '@xmtp/xmtp-js';
const group = await xmtp.conversations.newGroup([
'0xAddress1',
'0xAddress2',
'0xAddress3'
]);
await group.send('Hello everyone!');
await group.addMembers(['0xNewMember']);
await group.removeMembers(['0xOldMember']);
Why Blockchain Is Not Suitable for Storing Messages
Storing messages on-chain is economically unfeasible for mass use: a single transaction with text can cost $0.5-2 on Ethereum, and for frequent exchange it's millions of dollars per year. The main value of blockchain is in decentralized authentication and access control. User registration via a wallet signature (EIP-4361) provides cryptographic proof of address ownership without passwords. Token-gating allows restricting chat access based on on-chain conditions (e.g., NFT balance). Payment channels (Superfluid) automate micro-payments for messages or subscriptions. By using blockchain only for identity, we reduce costs by 80-95% and achieve scalability.
Comparison of XMTP and Waku
| Characteristic | XMTP | Waku |
|---|---|---|
| Identity | Ethereum address (mandatory) | Optional, any can be used |
| Transport | P2P network of XMTP nodes | P2P (libp2p, gossipsub) |
| Encryption | X3DH + MLS | Optional (at application layer) |
| History storage | External (Ceramic, Arweave) | Waku Store (limited TTL) |
| Token-gating | Through application | Through external layer |
| Micro-payments | Superfluid | External solutions |
How to Integrate XMTP in 4 Steps
- Wallet Setup: Connect any Ethereum wallet (MetaMask, WalletConnect). Obtain a signer via ethers.js or viem.
-
Create XMTP Client: Initialize
Client.create(signer, { env: 'production' }). At this stage, keys are generated and identity is registered in the XMTP network (requires one on-chain transaction). -
Create a Conversation: Call
client.conversations.newConversation(address)for 1-on-1 ornewGroup(addresses)for groups. The conversation is immediately ready for message exchange. -
Send and Subscribe: Use
conversation.send(text)to send andstreamMessages()to receive messages in real time. Everything is E2E encrypted.
Serverless Token-Gate via XMTP
In XMTP, token-gating can be implemented on the client side: when attempting to join a group, the user signs an attestation of their on-chain status. Existing participants verify the signature via an Ethereum provider. For more complex scenarios — Lit Protocol, where only a wallet with the required NFT can obtain the channel decryption key.
async function checkTokenGate(userAddress: string, channelId: string): Promise<boolean> {
const gateConfig = await getChannelGate(channelId);
const client = createPublicClient({ chain: mainnet, transport: http(RPC_URL) });
if (gateConfig.type === 'ERC20_MINIMUM') {
const balance = await client.readContract({
address: gateConfig.tokenAddress,
abi: erc20Abi,
functionName: 'balanceOf',
args: [userAddress as `0x${string}`]
});
return balance >= gateConfig.minimumAmount;
}
if (gateConfig.type === 'NFT_HOLDER') {
const balance = await client.readContract({
address: gateConfig.contractAddress,
abi: erc721Abi,
functionName: 'balanceOf',
args: [userAddress as `0x${string}`]
});
return balance > 0n;
}
return false;
}
Payment Channels in Chat
For micro-payments (pay-per-message, tips, spam prevention) we integrate a payment layer:
- Superfluid streams: the sender opens a money stream to the recipient; the stream is active while the conversation continues. Closing the conversation closes the stream.
- Inline ETH transfers: when sending a message — optional "Attach tip" button. Creates an XMTP message of type
transaction-reference+ a parallel on-chain transaction.
History Storage and Privacy
Decentralized transports do not guarantee permanent storage of old messages. For archiving we use:
- Ceramic Network: append-only streams with cryptographic guarantees of authorship
- Arweave: permanent storage, more expensive but permanent. Used for critical communications
- Self-hosted: users store messages locally (IndexedDB), synchronize via IPFS
Privacy mode: integration with Railgun for anonymous messages via zk-proofs.
Frontend Architecture
Chat is one of the most state-management-demanding UI components. For Web3 chat:
- Real-time messaging: XMTP SDK provides
streamMessages()async iterator - Message persistence: TanStack Query with infinite scroll for history and optimistic updates
- Content types: rendering markdown, embedded NFT previews, transaction previews
function ChatMessage({ message }: { message: DecodedMessage }) {
if (message.contentType?.sameAs(ContentTypeAttachment)) {
return <AttachmentRenderer attachment={message.content} />;
}
if (message.contentType?.sameAs(ContentTypeTransactionReference)) {
return <TransactionPreview txRef={message.content} />;
}
// Text message
return <ReactMarkdown>{message.content}</ReactMarkdown>;
}
Comparison of Approaches
| Approach | Identity | Transport | History Storage | Token-gating | Micro-payments |
|---|---|---|---|---|---|
| Fully on-chain | Ethereum | On-chain (tx) | On-chain | Native | Only ETH |
| XMTP | Ethereum (address) | P2P network XMTP | External (Ceramic) | Via application | Superfluid |
| Waku | Optional | P2P (libp2p) | Waku Store | Via application layer | External |
What Is Included in the Work
- Requirements analysis and architecture design
- Stack selection (XMTP/Waku, Ethereum/Polygon)
- Development of smart contracts for token-gating and payments
- Integration of XMTP/Waku and relay node configuration
- Frontend implementation (React/Next.js) with Web3 wallet support
- Deployment and testing (Tenderly, Slither)
- Documentation and source code handover
- Training of the client's team
- Post-release support
Timeline Estimates
- Basic 1-on-1 chat with XMTP and wallet-based identity — 1-2 weeks
- Group chats (XMTP MLS), multiple token-gate conditions, history persistence — 4-6 weeks
- Full platform with custom P2P transport, payment channels, and multi-chain support — 2-3 months
Cost is calculated individually. Ready to discuss your project? Contact us for a consultation.







