Follow this tutorial to build a quickstart chat app with XMTP.
When you build your quickstart app, you will use a key pair to create an identity and register it with XMTP. This gives you an inbox ID, which is a stable identifier that serves as the destination for your messages.
The signer provides identity(), kind(), and sign(request). Its sign
method returns a Signature with the raw signature bytes. The SDK’s
Client.generateKeys() (SDKClient.generateKeys() in Kotlin and Swift) returns
a local signing key that implements these methods. For a persistent account,
save and restore the private key
before opening the client. The examples below create temporary accounts.
The backend URL is required. Use the URL of your running backend. These examples
create temporary identities for testing. Do not use their key lifecycle in a
production app: store the signer key and database encryption key securely and
reuse them with the same database on later launches.
The Browser and Node blocks come from complete source files. They are checked
against the SDK types during the docs build. The mobile examples create a second
client so that the message recipient is registered on the same backend.
It is possible to modify this object, but such modifications will not be
reflected outside the Node.js process, or (unless explicitly requested)
to other Worker threads.
In other words, the following example would not work:
Assigning a property on process.env will implicitly convert the value
to a string. This behavior is deprecated. Future versions of Node.js may
throw an error when the value is not a string, number, or boolean.
import { env } from'node:process';
env.test =null;
console.log(env.test);
// => 'null'
env.test =undefined;
console.log(env.test);
// => 'undefined'
Use delete to delete a property from process.env.
import { env } from'node:process';
env.TEST=1;
delete env.TEST;
console.log(env.TEST);
// => undefined
On Windows operating systems, environment variables are case-insensitive.
import { env } from'node:process';
env.TEST=1;
console.log(env.test);
// => 1
Unless explicitly specified when creating a Worker instance,
each Worker thread has its own copy of process.env, based on its
parent thread's process.env, or whatever was specified as the env option
to the Worker constructor. Changes to process.env will not be visible
across Worker threads, and only the main thread can make changes that
are visible to the operating system or to native add-ons. On Windows, a copy of process.env on a Worker instance operates in a case-sensitive manner
unlike the main thread.
The Crypto.getRandomValues() method lets you get cryptographically strong random values. The array given as the parameter is filled with random numbers (random in its cryptographic meaning).
Load each client’s stored 32-byte database key before the calls below. Generate a
new key securely for a new database, store it securely, and reuse it on reopen.
Omitting the key selects unencrypted storage.
Create a conversation and send a text message. For Browser and Node, use the
inbox ID printed by a second running client on the same backend. Put the Kotlin
send and stream operations in the withDemoClients block. For Swift, use the
recipient client from the preceding step.
window.prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog.
It is possible to modify this object, but such modifications will not be
reflected outside the Node.js process, or (unless explicitly requested)
to other Worker threads.
In other words, the following example would not work:
Assigning a property on process.env will implicitly convert the value
to a string. This behavior is deprecated. Future versions of Node.js may
throw an error when the value is not a string, number, or boolean.
import { env } from'node:process';
env.test =null;
console.log(env.test);
// => 'null'
env.test =undefined;
console.log(env.test);
// => 'undefined'
Use delete to delete a property from process.env.
import { env } from'node:process';
env.TEST=1;
delete env.TEST;
console.log(env.TEST);
// => undefined
On Windows operating systems, environment variables are case-insensitive.
import { env } from'node:process';
env.TEST=1;
console.log(env.test);
// => 1
Unless explicitly specified when creating a Worker instance,
each Worker thread has its own copy of process.env, based on its
parent thread's process.env, or whatever was specified as the env option
to the Worker constructor. Changes to process.env will not be visible
across Worker threads, and only the main thread can make changes that
are visible to the operating system or to native add-ons. On Windows, a copy of process.env on a Worker instance operates in a case-sensitive manner
unlike the main thread.
@since ― v0.1.27
env.
string |undefined
XMTP_RECIPIENT_INBOX_ID;
if (!
constrecipientInboxId:string|undefined
recipientInboxId) thrownew
var Error:ErrorConstructor
new (message?:string, options?:ErrorOptions) =>Error (+1 overload)
Sending a message stores it locally and publishes it to the backend. Update
your UI from the message stream or query the conversation’s messages. See
optimistic sending to show a
message before publication completes.
Use client.conversations.streamAllMessages() in each SDK to receive messages. Use syncAll to fetch welcomes and messages in
the selected conversations. The JavaScript examples select allowed
conversations; allow an incoming conversation before you expect its messages
in that stream. See Consent.
When you stop the JavaScript example, call await stream.return(), await
receive, then call await client.end(). On mobile, stop the message stream
and end both clients. The Kotlin helper does this when its block exits; use
try await recipient.end() and try await client.end() in Swift.