Skip to main content

Thread

A thread is the persistent on-chain record of a conversation between two wallets. It tracks both participants, message count, and escrow state.

How threads work

One wallet (from) opens the thread to another (to). Once open, either side can send messages. The thread ID is a random 32-bit number chosen at creation; the on-chain address is derived from it.

If the recipient has an inbox, it is updated to record the new thread. If their inbox has a payment rule, the first message must satisfy it — paying them directly or placing funds in escrow.

Loading a thread

By address:

const thread = await client.thread(threadAddress).load();

By numeric ID — returns a handle, load explicitly:

const handle = client.thread(42);
await handle.load();

Refreshing

Thread state changes when new messages arrive or escrow settles. Call refresh() to re-fetch:

await thread.refresh();
console.log(thread.Thread.totalMsgs);

The Thread type

interface Thread {
address: PublicKey;
id: number;
from: PublicKey; // who opened the thread
to: PublicKey; // who received it
inboxId?: BN; // recipient's inbox, if targeted
totalMsgs: number;
lastMsgSeq: number; // sequence number of the latest message
lastUpdated: number; // unix timestamp
lastSenderSide: number; // 0 = from sent last, 1 = to sent last
lastReadSeqFrom: number;
lastReadSeqTo: number;
escrowPayment: ThreadEscrowInfo | null;
}

Access it via thread.Thread after loading.

ThreadClient getters

GetterTypeDescription
LoadedbooleanWhether the thread has been fetched
ThreadThreadRaw on-chain data (throws if not loaded)
ThreadInfo{ id, from, to }Minimal identity snapshot used internally by message pipelines
InboxInboxClient | undefinedThe recipient's inbox, if the thread was opened against one
LastMessageMessageClient | undefinedCached last message after calling loadLastMessage()