Skip to main content

Client

Class: Client

Client class initiates connection to the XMTP network. Should be created with await Client.create(options)

Constructors

constructor

new Client(publicKeyBundle, apiClient, backupClient, keystore)

Parameters

NameType
publicKeyBundlePublicKeyBundle
apiClientdefault
backupClientdefault
keystoreKeystore

Defined in

Client.ts:220

Properties

_backupClient

Private _backupClient: default

Defined in

Client.ts:214


_codecs

Private _codecs: Map<string, ContentCodec<any>>

Defined in

Client.ts:217


_conversations

Private _conversations: Conversations

Defined in

Client.ts:215


_maxContentSize

Private _maxContentSize: number

Defined in

Client.ts:218


address

address: string

Defined in

Client.ts:204


apiClient

apiClient: default

Defined in

Client.ts:206


contacts

contacts: Set<string>

Defined in

Client.ts:207


keystore

keystore: Keystore

Defined in

Client.ts:205


knownPublicKeyBundles

Private knownPublicKeyBundles: Map<string, SignedPublicKeyBundle | PublicKeyBundle>

Defined in

Client.ts:209


publicKeyBundle

publicKeyBundle: PublicKeyBundle

Defined in

Client.ts:208

Accessors

backupType

get backupType(): BackupType

Returns

BackupType

Defined in

Client.ts:249


conversations

get conversations(): Conversations

Returns

Conversations

Defined in

Client.ts:245


signedPublicKeyBundle

get signedPublicKeyBundle(): SignedPublicKeyBundle

Returns

SignedPublicKeyBundle

Defined in

Client.ts:253

Methods

canMessage

canMessage(peerAddress): Promise<boolean>

Check if

Peer Address

can be messaged, specifically it checks that a PublicKeyBundle can be found for the given address

Parameters

NameType
peerAddressstring

Returns

Promise<boolean>

Defined in

Client.ts:448

canMessage(peerAddress): Promise<boolean[]>

Check if

Peer Address

can be messaged, specifically it checks that a PublicKeyBundle can be found for the given address

Parameters

NameType
peerAddressstring[]

Returns

Promise<boolean[]>

Defined in

Client.ts:449


close

close(): Promise<void>

Returns

Promise<void>

Defined in

Client.ts:329


codecFor

codecFor(contentType): undefined | ContentCodec<any>

Find a matching codec for a given ContentTypeId from the client's codec registry

Parameters

NameType
contentTypeContentTypeId

Returns

undefined | ContentCodec<any>

Defined in

Client.ts:557


encodeContent

encodeContent(content, options?): Promise<Uint8Array>

Convert arbitrary content into a serialized EncodedContent instance with the given options

Parameters

NameType
contentany
options?SendOptions

Returns

Promise<Uint8Array>

Defined in

Client.ts:573


ensureUserContactPublished

Private ensureUserContactPublished(legacy?): Promise<void>

Parameters

NameTypeDefault value
legacybooleanfalse

Returns

Promise<void>

Defined in

Client.ts:333


forgetContact

forgetContact(peerAddress): void

Used to force getUserContact fetch contact from the network.

Parameters

NameType
peerAddressstring

Returns

void

Defined in

Client.ts:443


getUserContact

getUserContact(peerAddress): Promise<undefined | SignedPublicKeyBundle | PublicKeyBundle>

Returns the cached PublicKeyBundle if one is known for the given address or fetches one from the network

This throws if either the address is invalid or the contact is not published. See also [#canMessage].

Parameters

NameType
peerAddressstring

Returns

Promise<undefined | SignedPublicKeyBundle | PublicKeyBundle>

Defined in

Client.ts:370


getUserContacts

getUserContacts(peerAddresses): Promise<(undefined | SignedPublicKeyBundle | PublicKeyBundle)[]>

Identical to getUserContact but for multiple peer addresses

Parameters

NameType
peerAddressesstring[]

Returns

Promise<(undefined | SignedPublicKeyBundle | PublicKeyBundle)[]>

Defined in

Client.ts:394


init

Private init(options): Promise<void>

Parameters

NameType
optionsFlatten<NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions>

Returns

Promise<void>

Defined in

Client.ts:318


listEnvelopes

listEnvelopes<Out>(topic, mapper, opts?): Promise<Out[]>

List stored messages from the specified topic.

A specified mapper function will be applied to each envelope. If the mapper function throws an error during processing, the envelope will be discarded.

Type parameters

Name
Out

Parameters

NameType
topicstring
mapperEnvelopeMapper<Out>
opts?ListMessagesOptions

Returns

Promise<Out[]>

Defined in

Client.ts:609


listEnvelopesPaginated

listEnvelopesPaginated<Out>(contentTopic, mapper, opts?): AsyncGenerator<Out[], any, unknown>

List messages on a given set of content topics, yielding one page at a time

Type parameters

Name
Out

Parameters

NameType
contentTopicstring
mapperEnvelopeMapper<Out>
opts?ListMessagesPaginatedOptions

Returns

AsyncGenerator<Out[], any, unknown>

Defined in

Client.ts:643


listInvitations

listInvitations(opts?): Promise<Envelope[]>

Parameters

NameType
opts?ListMessagesOptions

Returns

Promise<Envelope[]>

Defined in

Client.ts:594


publishEnvelopes

publishEnvelopes(envelopes): Promise<void>

Low level method for publishing envelopes to the XMTP network with no pre-processing or encryption applied.

Primarily used internally

Parameters

NameTypeDescription
envelopesPublishParams[]PublishParams[]

Returns

Promise<void>

Defined in

Client.ts:533


publishUserContact

publishUserContact(legacy?): Promise<void>

Parameters

NameTypeDefault value
legacybooleanfalse

Returns

Promise<void>

Defined in

Client.ts:353


registerCodec

registerCodec(codec): void

Register a codec to be automatically used for encoding/decoding messages of the given Content Type

Parameters

NameType
codecContentCodec<any>

Returns

void

Defined in

Client.ts:546


validateEnvelope

Private validateEnvelope(env): void

Parameters

NameType
envPublishParams

Returns

void

Defined in

Client.ts:514


canMessage

Static canMessage(peerAddress, opts?): Promise<boolean>

Parameters

NameType
peerAddressstring
opts?Partial<NetworkOptions>

Returns

Promise<boolean>

Defined in

Client.ts:472

Static canMessage(peerAddress, opts?): Promise<boolean[]>

Parameters

NameType
peerAddressstring[]
opts?Partial<NetworkOptions>

Returns

Promise<boolean[]>

Defined in

Client.ts:477


create

Static create(wallet, opts?): Promise<Client>

Create and start a client associated with given wallet.

Parameters

NameTypeDescription
walletnull | Signerthe wallet as a Signer instance
opts?Partial<Flatten<NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions>>specify how to to connect to the network

Returns

Promise<Client>

Defined in

Client.ts:263


getKeys

Static getKeys(wallet, opts?): Promise<Uint8Array>

Export the XMTP PrivateKeyBundle from the SDK as a Uint8Array.

This bundle can then be provided as privateKeyOverride in a subsequent call to Client.create(...)

Be very careful with these keys, as they can be used to impersonate a user on the XMTP network and read the user's messages.

Parameters

NameType
walletnull | Signer
opts?Partial<Flatten<NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions>>

Returns

Promise<Uint8Array>

Defined in

Client.ts:296


setupBackupClient

Static Private setupBackupClient(walletAddress, env): Promise<default>

Parameters

NameType
walletAddressstring
env"local" | "dev" | "production"

Returns

Promise<default>

Defined in

Client.ts:305

Was the information on this page helpful?