Class Client<ContentTypes>

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

Type Parameters

  • ContentTypes = any

Constructors

Properties

address: string
apiClient: ApiClient
contacts: Contacts
publicKeyBundle: PublicKeyBundle

Accessors

Methods

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

    Parameters

    • contentType: ContentTypeId

    Returns undefined | ContentCodec<any>

  • Parameters

    • contentBytes: Uint8Array

    Returns Promise<{
        content: ContentTypes;
        contentFallback?: string;
        contentType: ContentTypeId;
        error?: Error;
    }>

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

    Parameters

    Returns Promise<{
        payload: Uint8Array;
        shouldPush: boolean;
    }>

  • Used to force getUserContact fetch contact from the network.

    Parameters

    • peerAddress: string

    Returns void

  • 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

    • Out

    Parameters

    Returns Promise<Out[]>

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

    Type Parameters

    • Out

    Parameters

    Returns AsyncGenerator<Out[], any, any>

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

    Primarily used internally

    Parameters

    Returns Promise<void>

  • Create and start a client associated with given wallet.

    Type Parameters

    • ContentCodecs extends ContentCodec<any>[] = []

    Parameters

    • wallet: null | Signer | {
          account: undefined | Account;
          addChain: ((args: AddChainParameters) => Promise<void>);
          batch?: {
              multicall?: boolean | {
                  batchSize?: number;
                  wait?: number;
              };
          };
          cacheTime: number;
          chain: undefined | Chain;
          deployContract: (<const abi, chainOverride>(args: DeployContractParameters<abi, undefined | Chain, undefined | Account, chainOverride>) => Promise<`0x${string}`>);
          extend: (<const client>(fn: ((client: Client<Transport, undefined | Chain, undefined | Account, WalletRpcSchema, WalletActions<undefined | Chain, undefined | Account>>) => client)) => Client<Transport, undefined | Chain, undefined | Account, WalletRpcSchema, {
              [K in string | number | symbol]: client[K]
          } & WalletActions<undefined | Chain, undefined | Account>>);
          getAddresses: (() => Promise<GetAddressesReturnType>);
          getChainId: (() => Promise<number>);
          getPermissions: (() => Promise<GetPermissionsReturnType>);
          key: string;
          name: string;
          pollingInterval: number;
          prepareTransactionRequest: (<TParameterType, TChainOverride, TAccountOverride>(args: PrepareTransactionRequestParameters<undefined | Chain, undefined | Account, TChainOverride, TAccountOverride, TParameterType>) => Promise<PrepareTransactionRequestReturnType<Chain, undefined | Account, TChainOverride, TAccountOverride, TParameterType>>);
          request: EIP1193RequestFn<WalletRpcSchema>;
          requestAddresses: (() => Promise<RequestAddressesReturnType>);
          requestPermissions: ((args: {
              eth_accounts: Record<string, any>;
          }) => Promise<RequestPermissionsReturnType>);
          sendRawTransaction: ((args: SendRawTransactionParameters) => Promise<`0x${string}`>);
          sendTransaction: (<TChainOverride>(args: SendTransactionParameters<undefined | Chain, undefined | Account, TChainOverride>) => Promise<`0x${string}`>);
          signMessage: ((args: SignMessageParameters<undefined | Account>) => Promise<`0x${string}`>);
          signTransaction: (<TChainOverride>(args: SignTransactionParameters<undefined | Chain, undefined | Account, TChainOverride>) => Promise<`0x${string}`>);
          signTypedData: (<const TTypedData, TPrimaryType>(args: SignTypedDataParameters<TTypedData, TPrimaryType, undefined | Account>) => Promise<`0x${string}`>);
          switchChain: ((args: SwitchChainParameters) => Promise<void>);
          transport: TransportConfig<string, EIP1193RequestFn> & Record<string, any>;
          type: string;
          uid: string;
          watchAsset: ((args: WatchAssetParams) => Promise<boolean>);
          writeContract: (<const abi, functionName, args, TChainOverride>(args: WriteContractParameters<abi, functionName, args, undefined | Chain, undefined | Account, TChainOverride>) => Promise<`0x${string}`>);
      }

      the wallet as a Signer instance

    • Optionalopts: Partial<Flatten<NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions>> & {
          codecs?: ContentCodecs;
      }

      specify how to to connect to the network

    Returns Promise<Client<undefined | ExtractDecodedType<[...ContentCodecs[], TextCodec][number]>>>

  • 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.

    Type Parameters

    • U

    Parameters

    • wallet: null | Signer | {
          account: undefined | Account;
          addChain: ((args: AddChainParameters) => Promise<void>);
          batch?: {
              multicall?: boolean | {
                  batchSize?: number;
                  wait?: number;
              };
          };
          cacheTime: number;
          chain: undefined | Chain;
          deployContract: (<const abi, chainOverride>(args: DeployContractParameters<abi, undefined | Chain, undefined | Account, chainOverride>) => Promise<`0x${string}`>);
          extend: (<const client>(fn: ((client: Client<Transport, undefined | Chain, undefined | Account, WalletRpcSchema, WalletActions<undefined | Chain, undefined | Account>>) => client)) => Client<Transport, undefined | Chain, undefined | Account, WalletRpcSchema, {
              [K in string | number | symbol]: client[K]
          } & WalletActions<undefined | Chain, undefined | Account>>);
          getAddresses: (() => Promise<GetAddressesReturnType>);
          getChainId: (() => Promise<number>);
          getPermissions: (() => Promise<GetPermissionsReturnType>);
          key: string;
          name: string;
          pollingInterval: number;
          prepareTransactionRequest: (<TParameterType, TChainOverride, TAccountOverride>(args: PrepareTransactionRequestParameters<undefined | Chain, undefined | Account, TChainOverride, TAccountOverride, TParameterType>) => Promise<PrepareTransactionRequestReturnType<Chain, undefined | Account, TChainOverride, TAccountOverride, TParameterType>>);
          request: EIP1193RequestFn<WalletRpcSchema>;
          requestAddresses: (() => Promise<RequestAddressesReturnType>);
          requestPermissions: ((args: {
              eth_accounts: Record<string, any>;
          }) => Promise<RequestPermissionsReturnType>);
          sendRawTransaction: ((args: SendRawTransactionParameters) => Promise<`0x${string}`>);
          sendTransaction: (<TChainOverride>(args: SendTransactionParameters<undefined | Chain, undefined | Account, TChainOverride>) => Promise<`0x${string}`>);
          signMessage: ((args: SignMessageParameters<undefined | Account>) => Promise<`0x${string}`>);
          signTransaction: (<TChainOverride>(args: SignTransactionParameters<undefined | Chain, undefined | Account, TChainOverride>) => Promise<`0x${string}`>);
          signTypedData: (<const TTypedData, TPrimaryType>(args: SignTypedDataParameters<TTypedData, TPrimaryType, undefined | Account>) => Promise<`0x${string}`>);
          switchChain: ((args: SwitchChainParameters) => Promise<void>);
          transport: TransportConfig<string, EIP1193RequestFn> & Record<string, any>;
          type: string;
          uid: string;
          watchAsset: ((args: WatchAssetParams) => Promise<boolean>);
          writeContract: (<const abi, functionName, args, TChainOverride>(args: WriteContractParameters<abi, functionName, args, undefined | Chain, undefined | Account, TChainOverride>) => Promise<`0x${string}`>);
      }
    • Optionalopts: Partial<Flatten<NetworkOptions & KeyStoreOptions & ContentOptions & LegacyOptions & PreEventCallbackOptions>> & {
          codecs?: U;
      }

    Returns Promise<Uint8Array>

  • Tells the caller whether the browser has a Snaps-compatible version of MetaMask installed

    Returns Promise<boolean>