Client is the primary interface for interacting with the XMTP network. This guide shows you how to create and configure clients using the ClientBuilder pattern.
Overview
Each client instance is bound to:- A single Inbox ID (user identity)
- A single Installation ID (device/app instance)
- A local SQLite database for storage
Basic Client Creation
use xmtp_mls::Client;
use xmtp_mls::identity::IdentityStrategy;
let client_builder = Client::builder(IdentityStrategy::CreateIfNotFound(
account_address,
nonce,
legacy_signed_private_key, // Optional: for V2 migration
));
The
IdentityStrategy determines how the client handles identity:CreateIfNotFound- Creates a new inbox if one doesn’t existCachedOnly- Uses an existing cached identityExternalIdentity- Uses externally provided identity
let client = client_builder
.api_clients(api_client, sync_api_client)
.store(db)
.default_mls_store()? // Use default SQLite MLS storage
.with_remote_verifier()?
.build()
.await?;
// Create a signature request
let signature_request = client.identity().signature_request();
// Sign with your wallet
let signature = wallet.sign_message(signature_request.signature_text()).await?;
signature_request.add_signature(signature);
// Register on the network
client.register_identity(signature_request).await?;
ClientBuilder Configuration
TheClientBuilder supports extensive configuration:
Storage Configuration
Device Sync Configuration
Version Information
Offline Mode
Smart Contract Verifier
Client Properties
Identity States
A client’s identity can be in one of three states:- Not Registered - Installation keys generated but not associated with an inbox
- Registered but Not Ready - Identity update created but not published to network
- Ready - Fully registered and operational
Multi-Device Support
Multiple installations can share the same inbox:Best Practices
let db = EncryptedMessageStore::new(
StorageOption::Persistent("/path/to/db"),
Some(encryption_key),
)?;
let encryption_key = generate_secure_key(); // 32 bytes
let db = EncryptedMessageStore::new(
StorageOption::Persistent(path),
Some(encryption_key),
)?;
// Release when app goes to background
client.release_db_connection()?;
// Reconnect when app returns to foreground
client.reconnect_db()?;
Error Handling
Common errors when building clients:Next Steps
Managing Groups
Create and manage group conversations
Database Encryption
Secure your local database with SQLCipher
