Client struct is the primary entry point for interacting with the XMTP network. It manages access to the network, identity, and data storage.
Client Structure
The Client is generic over aContext parameter that encapsulates dependencies:
Shared context containing API client, storage, identity, and configuration
Unique identifier for this client installation (public key bytes)
Event broadcaster for local client events (new groups, messages, etc.)
Background worker manager for sync, key package rotation, etc.
Context Parameter
TheContext generic parameter must implement XmtpSharedContext, which provides:
- API Client: Network communication via
XmtpApitrait - Database: Local storage via
XmtpDbtrait - Identity: User’s inbox and installation keys
- Smart Contract Verifier: For validating blockchain signatures
- Version Info: Client version metadata
- Worker Metrics: Performance monitoring
XmtpMlsLocalContext<ApiClient, Db, Storage>- Standard context with configurable API and storageMlsContext- Default context alias used in bindings
Creating a Client
Clients are created using theClientBuilder fluent API. See ClientBuilder for details.
Key Capabilities
Identity Management
- Register new identities on the network
- Look up inbox IDs by blockchain address or other identifiers
- Retrieve association state showing wallet/installation links
- Check registration status
Conversation Operations
- Create groups with custom permissions
- Create or find direct messages
- List conversations with filtering
- Query groups by various criteria
Message Operations
- Look up messages by ID
- Delete messages locally
- Enrich messages with decoded content
Synchronization
- Sync welcome messages to discover new conversations
- Sync all groups to receive latest messages
- Sync device preferences across installations
Consent State
- Set and retrieve consent preferences
- Manage allow/deny lists for contacts
Network Queries
- Check if addresses can receive messages
- Fetch key packages for installations
- Get inbox update counts
Thread Safety
The Client isClone when the underlying Context is Clone (which it typically is via Arc). Cloning creates a new handle to the same underlying client, allowing safe concurrent use across threads.
Database Lifecycle
The client provides methods to manage database connections:release_db_connection()- Close the database connection poolreconnect_db()- Reopen database connections and restart workers
Related Types
- ClientBuilder - Fluent API for constructing clients
- Client Methods - Complete method reference
MlsGroup- Individual conversation objectsIdentity- User identity and credentials
