WASM bindings require browser support for OPFS or ephemeral storage.
2
Create a client
Initialize an XMTP client with your wallet credentials.
Node.js
Swift
Kotlin
import { Client } from '@xmtp/node-bindings'// Create a client with wallet authenticationconst client = await Client.create( accountAddress, { env: 'production', dbPath: './xmtp.db' })console.log('Client created with Inbox ID:', client.inboxId())
import XMTPiOS// Create client with walletlet client = try await Client.create( account: wallet, options: .init( api: .init(env: .production), dbEncryptionKey: encryptionKey ))print("Client created with Inbox ID: \(client.inboxId)")
import org.xmtp.android.library.Client// Create clientval client = Client().create( account = wallet, options = ClientOptions( api = ClientOptions.Api( env = XMTPEnvironment.PRODUCTION ) ))println("Client created with Inbox ID: ${client.inboxId}")
The client manages your local database, identity state, and network connections. Each client is bound to a single Inbox ID and Installation ID.
On first run, the client will register your installation with the XMTP network. This requires a wallet signature to prove ownership.
3
Create or join a group
Start a new conversation or sync existing groups from the network.
Node.js
Swift
Kotlin
// Sync existing groups from the networkawait client.conversations.sync()// Create a new groupconst group = await client.conversations.createGroup( [member1Address, member2Address], { groupName: "Team Discussion", groupImageUrl: "https://example.com/avatar.png", groupDescription: "Our project coordination channel" })console.log('Group created:', group.id())// List all conversationsconst groups = await client.conversations.list()console.log(`You have ${groups.length} conversations`)
// Sync existing groupstry await client.conversations.sync()// Create a new grouplet group = try await client.conversations.newGroup( with: [member1Address, member2Address], permissions: .allMembers, name: "Team Discussion", imageUrlSquare: "https://example.com/avatar.png")print("Group created: \(group.id)")
// Sync existing groupsclient.conversations.sync()// Create a new groupval group = client.conversations.newGroup( listOf(member1Address, member2Address), permissions = GroupPermissions.ALL_MEMBERS, name = "Team Discussion", imageUrlSquare = "https://example.com/avatar.png")println("Group created: ${group.id}")
4
Send and receive messages
Exchange end-to-end encrypted messages with group members.
Node.js
Swift
Kotlin
// Send a text messageawait group.send("Hello, team! π")// Send with optimistic sending (returns before confirmed)await group.send("Quick update", { sendOptimistically: true })// Query recent messagesconst messages = await group.findMessages({ limit: 10 })messages.forEach(msg => { console.log(`${msg.senderInboxId}: ${msg.content}`)})// Stream new messages in real-timeconst stream = await group.streamMessages()for await (const message of stream) { console.log('New message:', message.content)}
// Send a messagetry await group.send(content: "Hello, team! π")// Query messageslet messages = try await group.messages(limit: 10)for message in messages { print("\(message.senderInboxId): \(message.body)")}// Stream new messagesfor try await message in group.streamMessages() { print("New message: \(message.body)")}
Always wrap LibXMTP operations in try-catch blocks:
try { const group = await client.conversations.createGroup([address1, address2]) await group.send("Welcome!")} catch (error) { if (error.message.includes('not registered')) { console.error('One or more addresses are not XMTP users') } else { console.error('Failed to create group:', error) }}
The first time a client is created, you need to provide a wallet signature to register your installation. Make sure your wallet is properly initialized and can sign messages.See Creating Clients for detailed registration flows.
Messages not appearing immediately
Messages may take a few seconds to propagate through the network. Use group.sync() to manually fetch new messages, or set up a message stream for real-time updates.
Database permission errors
Make sure the dbPath directory exists and is writable by your application. On mobile platforms, use the appβs documents directory.
Member not found errors when creating groups
Users must have an active XMTP installation to be added to groups. They need to have created a client at least once. Check that addresses are valid XMTP users with client.canMessage([address]).